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
766988e4
Commit
766988e4
authored
May 13, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplication surrounding error creation.
parent
c8f04698
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
28 deletions
+15
-28
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+2
-2
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+11
-25
BUYClient_Internal.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient_Internal.h
+2
-1
No files found.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
766988e4
...
...
@@ -120,7 +120,7 @@
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
if
(
!
error
)
{
error
=
[
self
e
xtractErrorFromResponse
:
response
json
:
json
];
error
=
[
self
e
rrorFromJSON
:
json
response
:
response
];
}
block
(
statusCode
,
error
);
...
...
@@ -141,7 +141,7 @@
}
if
(
!
error
)
{
error
=
[
self
e
xtractErrorFromResponse
:
response
json
:
json
];
error
=
[
self
e
rrorFromJSON
:
json
response
:
response
];
}
block
(
accessToken
,
error
);
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
766988e4
...
...
@@ -540,19 +540,13 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return
status
;
}
-
(
NSError
*
)
errorFromJSON
:
(
NSDictionary
*
)
errorDictionary
statusCode
:
(
NSInteger
)
statusCod
e
-
(
NSError
*
)
errorFromJSON
:
(
NSDictionary
*
)
json
response
:
(
NSURLResponse
*
)
respons
e
{
return
[[
NSError
alloc
]
initWithDomain
:
kShopifyError
code
:
statusCode
userInfo
:
errorDictionary
];
}
-
(
NSError
*
)
extractErrorFromResponse
:
(
NSURLResponse
*
)
response
json
:
(
NSDictionary
*
)
json
{
NSError
*
error
=
nil
;
NSInteger
statusCode
=
[((
NSHTTPURLResponse
*
)
response
)
statusCode
];
if
(
statusCode
<
kMinSuccessfulStatusCode
||
statusCode
>
kMaxSuccessfulStatusCode
)
{
error
=
[
NSError
errorWithDomain
:
NSURLErrorDomain
code
:
statusCode
userInfo
:
json
];
return
[[
NSError
alloc
]
initWithDomain
:
kShopifyError
code
:
statusCode
userInfo
:
json
];
}
return
error
;
return
nil
;
}
#pragma mark - Convenience Requests
...
...
@@ -620,29 +614,21 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
request
.
HTTPMethod
=
method
;
NSURLSessionDataTask
*
task
=
[
self
.
session
dataTaskWithRequest
:
request
completionHandler
:
^
(
NSData
*
data
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
NSDictionary
*
json
=
nil
;
BOOL
unauthorized
=
statusCode
==
401
;
BOOL
failedValidation
=
statusCode
==
422
;
if
(
unauthorized
)
{
error
=
[[
NSError
alloc
]
initWithDomain
:
kShopifyError
code
:
statusCode
userInfo
:
nil
];
NSDictionary
*
json
=
nil
;
if
(
data
.
length
>
2
)
{
// 2 is the minimum amount of data {} for a JSON Object. Just ignore anything less.
json
=
[
NSJSONSerialization
JSONObjectWithData
:
data
options
:
0
error
:
nil
];
}
else
{
//2 is the minimum amount of data {} for a JSON Object. Just ignore anything less.
if
((
!
error
||
failedValidation
)
&&
[
data
length
]
>
2
)
{
id
jsonData
=
[
NSJSONSerialization
JSONObjectWithData
:
data
options
:
0
error
:&
error
];
json
=
[
jsonData
isKindOfClass
:[
NSDictionary
class
]]
?
jsonData
:
nil
;
}
if
(
statusCode
<
kMinSuccessfulStatusCode
||
statusCode
>
kMaxSuccessfulStatusCode
)
{
error
=
[
self
errorFromJSON
:
json
statusCode
:
statusCode
];
}
if
(
!
error
)
{
error
=
[
self
errorFromJSON
:
json
response
:
response
];
}
dispatch_async
(
self
.
queue
,
^
{
completionHandler
(
json
,
response
,
error
);
});
}];
[
self
startTask
:
task
];
return
task
;
}
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient_Internal.h
View file @
766988e4
...
...
@@ -37,6 +37,7 @@ extern NSString *const kShopifyError;
-
(
NSURLSessionDataTask
*
)
requestForURL
:(
NSURL
*
)
url
method
:(
NSString
*
)
method
body
:(
NSData
*
)
body
additionalHeaders
:(
NSDictionary
*
)
headers
completionHandler
:(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
;
-
(
NSURLComponents
*
)
URLComponentsForAPIPath
:(
NSString
*
)
apiPath
appendingPath
:(
NSString
*
)
appendingPath
queryItems
:(
NSDictionary
*
)
queryItems
;
-
(
NSError
*
)
extractErrorFromResponse
:(
NSURLResponse
*
)
response
json
:(
NSDictionary
*
)
json
;
-
(
NSError
*
)
errorFromJSON
:(
NSDictionary
*
)
json
response
:(
NSURLResponse
*
)
response
;
@end
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