Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shopify_iossdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
shopify_iossdk
Commits
1c96e165
Commit
1c96e165
authored
May 30, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add separate network request queue to avoid deadlock. Minor refactor.
parent
a57f4973
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
20 deletions
+36
-20
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+36
-20
No files found.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
1c96e165
...
...
@@ -34,6 +34,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
@interface
BUYClient
()
<
NSURLSessionDelegate
>
@property
(
nonatomic
,
strong
)
NSURLSession
*
session
;
@property
(
nonatomic
,
strong
)
NSOperationQueue
*
networkQueue
;
@end
...
...
@@ -58,26 +59,44 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
_shopDomain
=
shopDomain
;
_apiKey
=
apiKey
;
_appId
=
appId
;
_applicationName
=
[[
NSBundle
mainBundle
]
infoDictionary
][
@"CFBundleName"
]
?:
@""
;
_callbackQueue
=
[
NSOperationQueue
mainQueue
];
_requestQueue
=
[
NSOperationQueue
new
];
_networkQueue
=
[
NSOperationQueue
new
];
_session
=
[
self
urlSession
];
_pageSize
=
25
;
}
return
self
;
}
#pragma mark - Headers -
-
(
NSString
*
)
applicationName
{
return
[[
NSBundle
mainBundle
]
infoDictionary
][
@"CFBundleName"
]
?:
@""
;
}
-
(
NSString
*
)
bundleIdentifier
{
return
[[
NSBundle
mainBundle
]
bundleIdentifier
];
}
-
(
NSDictionary
*
)
additionalHeaders
{
return
@{
@"User-Agent"
:
[
NSString
stringWithFormat
:
@"Mobile Buy SDK iOS/%@/%@"
,
BUYClientVersionString
,
[
self
bundleIdentifier
]]
};
}
#pragma mark - Accessors -
-
(
NSURLSession
*
)
urlSession
{
NSURLSessionConfiguration
*
config
=
[
NSURLSessionConfiguration
defaultSessionConfiguration
];
config
.
HTTPAdditionalHeaders
=
[
self
additionalHeaders
];
NSString
*
bundleIdentifier
=
[[
NSBundle
mainBundle
]
bundleIdentifier
];
config
.
HTTPAdditionalHeaders
=
@{
@"User-Agent"
:
[
NSString
stringWithFormat
:
@"Mobile Buy SDK iOS/%@/%@"
,
BUYClientVersionString
,
bundleIdentifier
]};
return
[
NSURLSession
sessionWithConfiguration
:
config
delegate
:
self
delegateQueue
:
self
.
requestQueue
];
return
[
NSURLSession
sessionWithConfiguration
:
config
delegate
:
self
delegateQueue
:
self
.
networkQueue
];
}
-
(
void
)
setPageSize
:
(
NSUInteger
)
pageSize
...
...
@@ -89,23 +108,20 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
-
(
BUYStatus
)
statusForStatusCode
:
(
NSUInteger
)
statusCode
error
:
(
NSError
*
)
error
{
BUYStatus
status
=
BUYStatusUnknown
;
if
(
statusCode
==
BUYStatusPreconditionFailed
)
{
status
=
BUYStatusPreconditionFailed
;
}
else
if
(
statusCode
==
BUYStatusNotFound
)
{
status
=
BUYStatusNotFound
;
}
else
if
(
error
||
statusCode
==
BUYStatusFailed
)
{
status
=
BUYStatusFailed
;
switch
((
BUYStatus
)
statusCode
)
{
case
BUYStatusPreconditionFailed
:
return
BUYStatusPreconditionFailed
;
case
BUYStatusNotFound
:
return
BUYStatusNotFound
;
case
BUYStatusFailed
:
return
BUYStatusFailed
;
case
BUYStatusProcessing
:
return
BUYStatusProcessing
;
case
BUYStatusComplete
:
return
BUYStatusComplete
;
default
:
{
if
(
error
)
{
return
BUYStatusFailed
;
}
else
{
return
BUYStatusUnknown
;
}
else
if
(
statusCode
==
BUYStatusProcessing
)
{
status
=
BUYStatusProcessing
;
}
else
if
(
statusCode
==
BUYStatusComplete
)
{
status
=
BUYStatusComplete
;
}
return
status
;
}
-
(
NSError
*
)
errorFromJSON
:
(
NSDictionary
*
)
json
response
:
(
NSURLResponse
*
)
response
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment