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";
...
@@ -34,6 +34,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
@interface
BUYClient
()
<
NSURLSessionDelegate
>
@interface
BUYClient
()
<
NSURLSessionDelegate
>
@property
(
nonatomic
,
strong
)
NSURLSession
*
session
;
@property
(
nonatomic
,
strong
)
NSURLSession
*
session
;
@property
(
nonatomic
,
strong
)
NSOperationQueue
*
networkQueue
;
@end
@end
...
@@ -58,26 +59,44 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
...
@@ -58,26 +59,44 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
_shopDomain
=
shopDomain
;
_shopDomain
=
shopDomain
;
_apiKey
=
apiKey
;
_apiKey
=
apiKey
;
_appId
=
appId
;
_appId
=
appId
;
_applicationName
=
[[
NSBundle
mainBundle
]
infoDictionary
][
@"CFBundleName"
]
?:
@""
;
_callbackQueue
=
[
NSOperationQueue
mainQueue
];
_callbackQueue
=
[
NSOperationQueue
mainQueue
];
_requestQueue
=
[
NSOperationQueue
new
];
_requestQueue
=
[
NSOperationQueue
new
];
_networkQueue
=
[
NSOperationQueue
new
];
_session
=
[
self
urlSession
];
_session
=
[
self
urlSession
];
_pageSize
=
25
;
_pageSize
=
25
;
}
}
return
self
;
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 -
#pragma mark - Accessors -
-
(
NSURLSession
*
)
urlSession
-
(
NSURLSession
*
)
urlSession
{
{
NSURLSessionConfiguration
*
config
=
[
NSURLSessionConfiguration
defaultSessionConfiguration
];
NSURLSessionConfiguration
*
config
=
[
NSURLSessionConfiguration
defaultSessionConfiguration
];
config
.
HTTPAdditionalHeaders
=
[
self
additionalHeaders
];
NSString
*
bundleIdentifier
=
[[
NSBundle
mainBundle
]
bundleIdentifier
];
return
[
NSURLSession
sessionWithConfiguration
:
config
delegate
:
self
delegateQueue
:
self
.
networkQueue
];
config
.
HTTPAdditionalHeaders
=
@{
@"User-Agent"
:
[
NSString
stringWithFormat
:
@"Mobile Buy SDK iOS/%@/%@"
,
BUYClientVersionString
,
bundleIdentifier
]};
return
[
NSURLSession
sessionWithConfiguration
:
config
delegate
:
self
delegateQueue
:
self
.
requestQueue
];
}
}
-
(
void
)
setPageSize
:
(
NSUInteger
)
pageSize
-
(
void
)
setPageSize
:
(
NSUInteger
)
pageSize
...
@@ -89,23 +108,20 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
...
@@ -89,23 +108,20 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
-
(
BUYStatus
)
statusForStatusCode
:
(
NSUInteger
)
statusCode
error
:
(
NSError
*
)
error
-
(
BUYStatus
)
statusForStatusCode
:
(
NSUInteger
)
statusCode
error
:
(
NSError
*
)
error
{
{
BUYStatus
status
=
BUYStatusUnknown
;
switch
((
BUYStatus
)
statusCode
)
{
if
(
statusCode
==
BUYStatusPreconditionFailed
)
{
case
BUYStatusPreconditionFailed
:
return
BUYStatusPreconditionFailed
;
status
=
BUYStatusPreconditionFailed
;
case
BUYStatusNotFound
:
return
BUYStatusNotFound
;
}
case
BUYStatusFailed
:
return
BUYStatusFailed
;
else
if
(
statusCode
==
BUYStatusNotFound
)
{
case
BUYStatusProcessing
:
return
BUYStatusProcessing
;
status
=
BUYStatusNotFound
;
case
BUYStatusComplete
:
return
BUYStatusComplete
;
}
default
:
{
else
if
(
error
||
statusCode
==
BUYStatusFailed
)
{
if
(
error
)
{
status
=
BUYStatusFailed
;
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
-
(
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