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
5488ed77
Commit
5488ed77
authored
May 24, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add customer logout API.
parent
a57f4973
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
46 deletions
+64
-46
BUYRequestOperationTests.m
...e Buy SDK/Mobile Buy SDK Tests/BUYRequestOperationTests.m
+3
-3
BUYClient+Checkout.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
+11
-13
BUYClient+Customers.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
+12
-0
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+17
-18
BUYClient+Internal.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Internal.h
+1
-2
BUYClient+Routing.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.h
+1
-0
BUYClient+Routing.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.m
+5
-0
BUYClient+Storefront.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Storefront.m
+5
-5
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+9
-5
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYRequestOperationTests.m
View file @
5488ed77
...
@@ -54,7 +54,7 @@
...
@@ -54,7 +54,7 @@
-
(
void
)
testInit
-
(
void
)
testInit
{
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
// We don't start the session
// We don't start the session
}];
}];
...
@@ -357,7 +357,7 @@
...
@@ -357,7 +357,7 @@
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
completion
:
(
dispatch_block_t
)
completion
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
completion
:
(
dispatch_block_t
)
completion
{
{
return
[
self
operationFulfillingExpectation
:
expectation
responseCompletion
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
operationFulfillingExpectation
:
expectation
responseCompletion
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
if
(
completion
)
{
if
(
completion
)
{
completion
();
completion
();
}
}
...
@@ -366,7 +366,7 @@
...
@@ -366,7 +366,7 @@
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
responseCompletion
:
(
void
(
^
)(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
))
completion
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
responseCompletion
:
(
void
(
^
)(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
))
completion
{
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
[
self
asyncMain
:
^
{
[
self
asyncMain
:
^
{
if
(
completion
)
{
if
(
completion
)
{
completion
(
json
,
(
id
)
response
,
error
);
completion
(
json
,
(
id
)
response
,
error
);
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
View file @
5488ed77
...
@@ -87,7 +87,7 @@
...
@@ -87,7 +87,7 @@
-
(
BUYRequestOperation
*
)
postCheckout
:(
NSDictionary
*
)
checkoutJSON
completion
:(
BUYDataCheckoutBlock
)
block
-
(
BUYRequestOperation
*
)
postCheckout
:(
NSDictionary
*
)
checkoutJSON
completion
:(
BUYDataCheckoutBlock
)
block
{
{
return
[
self
postRequestForURL
:[
self
urlForCheckouts
]
object
:
checkoutJSON
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:[
self
urlForCheckouts
]
object
:
checkoutJSON
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}];
}
}
...
@@ -100,7 +100,7 @@
...
@@ -100,7 +100,7 @@
BUYGiftCard
*
giftCard
=
[
self
.
modelManager
giftCardWithCode
:
giftCardCode
];
BUYGiftCard
*
giftCard
=
[
self
.
modelManager
giftCardWithCode
:
giftCardCode
];
NSURL
*
route
=
[
self
urlForCheckoutsUsingGiftCardWithToken
:
checkout
.
token
];
NSURL
*
route
=
[
self
urlForCheckoutsUsingGiftCardWithToken
:
checkout
.
token
];
return
[
self
postRequestForURL
:
route
object
:
giftCard
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
route
object
:
giftCard
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
YES
];
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
YES
];
}
}
...
@@ -114,7 +114,7 @@
...
@@ -114,7 +114,7 @@
BUYAssert
(
giftCard
.
identifier
,
@"Failed to remove gift card. Gift card must have a valid identifier."
);
BUYAssert
(
giftCard
.
identifier
,
@"Failed to remove gift card. Gift card must have a valid identifier."
);
NSURL
*
route
=
[
self
urlForCheckoutsUsingGiftCard
:
giftCard
.
identifier
token
:
checkout
.
token
];
NSURL
*
route
=
[
self
urlForCheckoutsUsingGiftCard
:
giftCard
.
identifier
token
:
checkout
.
token
];
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
if
(
!
error
)
{
if
(
!
error
)
{
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
NO
];
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
NO
];
}
}
...
@@ -149,7 +149,7 @@
...
@@ -149,7 +149,7 @@
BUYAssertCheckout
(
checkout
);
BUYAssertCheckout
(
checkout
);
NSURL
*
route
=
[
self
urlForCheckoutsWithToken
:
checkout
.
token
];
NSURL
*
route
=
[
self
urlForCheckoutsWithToken
:
checkout
.
token
];
return
[
self
getRequestForURL
:
route
start
:
start
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
start
:
start
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}];
}
}
...
@@ -159,7 +159,7 @@
...
@@ -159,7 +159,7 @@
BUYAssertCheckout
(
checkout
);
BUYAssertCheckout
(
checkout
);
NSURL
*
route
=
[
self
urlForCheckoutsWithToken
:
checkout
.
token
];
NSURL
*
route
=
[
self
urlForCheckoutsWithToken
:
checkout
.
token
];
return
[
self
patchRequestForURL
:
route
object
:
checkout
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
patchRequestForURL
:
route
object
:
checkout
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}];
}
}
...
@@ -179,7 +179,7 @@
...
@@ -179,7 +179,7 @@
BUYAssert
(
paymentToken
||
isFree
,
@"Failed to complete checkout. Checkout must have a payment token or have a payment value equal to $0.00"
);
BUYAssert
(
paymentToken
||
isFree
,
@"Failed to complete checkout. Checkout must have a payment token or have a payment value equal to $0.00"
);
NSURL
*
route
=
[
self
urlForCheckoutsCompletionWithToken
:
checkout
.
token
];
NSURL
*
route
=
[
self
urlForCheckoutsCompletionWithToken
:
checkout
.
token
];
return
[
self
postRequestForURL
:
route
object
:[
paymentToken
JSONDictionary
]
start
:
NO
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
route
object
:[
paymentToken
JSONDictionary
]
start
:
NO
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}];
}
}
...
@@ -211,9 +211,8 @@
...
@@ -211,9 +211,8 @@
-
(
BUYRequestOperation
*
)
getCompletionStatusOfCheckoutToken
:(
NSString
*
)
token
start
:(
BOOL
)
start
completion
:(
BUYDataStatusBlock
)
block
-
(
BUYRequestOperation
*
)
getCompletionStatusOfCheckoutToken
:(
NSString
*
)
token
start
:(
BOOL
)
start
completion
:(
BUYDataStatusBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCheckoutsProcessingWithToken
:
token
];
NSURL
*
route
=
[
self
urlForCheckoutsProcessingWithToken
:
token
];
return
[
self
getRequestForURL
:
route
start
:
start
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
start
:
start
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
block
([
self
statusForStatusCode
:
response
.
statusCode
error
:
error
],
error
);
block
([
self
statusForStatusCode
:
statusCode
error
:
error
],
error
);
}];
}];
}
}
...
@@ -227,14 +226,13 @@
...
@@ -227,14 +226,13 @@
@"checkout"
:
@""
,
@"checkout"
:
@""
,
}];
}];
BUYRequestOperation
*
operation
=
[
self
getRequestForURL
:
route
start
:
NO
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRequestOperation
*
operation
=
[
self
getRequestForURL
:
route
start
:
NO
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
shippingRates
=
nil
;
NSArray
*
shippingRates
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
shippingRates
=
[
self
.
modelManager
insertShippingRatesWithJSONArray
:
json
[
@"shipping_rates"
]];
shippingRates
=
[
self
.
modelManager
insertShippingRatesWithJSONArray
:
json
[
@"shipping_rates"
]];
}
}
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
block
(
shippingRates
,
[
self
statusForStatusCode
:
response
.
statusCode
error
:
error
],
error
);
block
(
shippingRates
,
[
self
statusForStatusCode
:
statusCode
error
:
error
],
error
);
}];
}];
operation
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
operation
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
...
@@ -259,7 +257,7 @@
...
@@ -259,7 +257,7 @@
json
[
@"billing_address"
]
=
[
checkout
.
billingAddress
jsonDictionaryForCheckout
];
json
[
@"billing_address"
]
=
[
checkout
.
billingAddress
jsonDictionaryForCheckout
];
}
}
return
[
self
postRequestForURL
:
checkout
.
paymentURL
object
:@{
@"checkout"
:
json
}
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
checkout
.
paymentURL
object
:@{
@"checkout"
:
json
}
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
id
<
BUYPaymentToken
>
token
=
nil
;
id
<
BUYPaymentToken
>
token
=
nil
;
if
(
!
error
)
{
if
(
!
error
)
{
token
=
[[
BUYCreditCardToken
alloc
]
initWithPaymentSessionID
:
json
[
@"id"
]];
token
=
[[
BUYCreditCardToken
alloc
]
initWithPaymentSessionID
:
json
[
@"id"
]];
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
View file @
5488ed77
...
@@ -105,6 +105,18 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
...
@@ -105,6 +105,18 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
;
/**
/**
* DELETE /api/customers/:customer_id/customer_token
* Logs out an existing customer
* Expects a customerID string
*
* @param customer A customerID represented by a string
* @param block (BUYStatus status, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
logoutCustomerID
:(
NSString
*
)
customerID
callback
:(
BUYDataStatusBlock
)
block
;
/**
* POST /api/customers/recover
* POST /api/customers/recover
* Sends email for password recovery to an existing customer
* Sends email for password recovery to an existing customer
*
*
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
5488ed77
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
-
(
BUYRequestOperation
*
)
getCustomerWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
-
(
BUYRequestOperation
*
)
getCustomerWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCustomersWithID
:
customerID
];
NSURL
*
route
=
[
self
urlForCustomersWithID
:
customerID
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
-
(
BUYRequestOperation
*
)
createCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
BUYRequestOperation
*
)
createCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCustomers
];
NSURL
*
route
=
[
self
urlForCustomers
];
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
json
callback
:
block
];
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
json
callback
:
block
];
}
}
...
@@ -66,7 +66,7 @@
...
@@ -66,7 +66,7 @@
-
(
BUYRequestOperation
*
)
createTokenForCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerJSON
:(
NSDictionary
*
)
customerJSON
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
BUYRequestOperation
*
)
createTokenForCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerJSON
:(
NSDictionary
*
)
customerJSON
callback
:(
BUYDataCustomerTokenBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCustomersToken
];
NSURL
*
route
=
[
self
urlForCustomersToken
];
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
...
@@ -87,6 +87,14 @@
...
@@ -87,6 +87,14 @@
}];
}];
}
}
-
(
BUYRequestOperation
*
)
logoutCustomerID
:(
NSString
*
)
customerID
callback
:(
BUYDataStatusBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersTokenWithID
:
customerID
];
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
block
(
response
.
statusCode
,
error
);
}];
}
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
{
{
return
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
nil
callback
:
block
];
return
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
nil
callback
:
block
];
...
@@ -95,13 +103,8 @@
...
@@ -95,13 +103,8 @@
-
(
BUYRequestOperation
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataStatusBlock
)
block
-
(
BUYRequestOperation
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataStatusBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCustomersPasswordRecovery
];
NSURL
*
route
=
[
self
urlForCustomersPasswordRecovery
];
return
[
self
postRequestForURL
:
route
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
route
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
block
(
response
.
statusCode
,
error
);
if
(
!
error
)
{
error
=
[
self
errorFromJSON
:
json
response
:
response
];
}
block
(
statusCode
,
error
);
}];
}];
}
}
...
@@ -110,17 +113,13 @@
...
@@ -110,17 +113,13 @@
if
(
self
.
customerToken
)
{
if
(
self
.
customerToken
)
{
NSURL
*
route
=
[
self
urlForCustomersTokenRenewalWithID
:
customerID
];
NSURL
*
route
=
[
self
urlForCustomersTokenRenewalWithID
:
customerID
];
return
[
self
putRequestForURL
:
route
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSString
*
accessToken
=
nil
;
NSString
*
accessToken
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
accessToken
=
authenticatedResponse
.
accessToken
;
accessToken
=
authenticatedResponse
.
accessToken
;
}
}
if
(
!
error
)
{
error
=
[
self
errorFromJSON
:
json
response
:
response
];
}
block
(
accessToken
,
error
);
block
(
accessToken
,
error
);
}];
}];
}
}
...
@@ -136,7 +135,7 @@
...
@@ -136,7 +135,7 @@
@"token"
:
customerToken
,
@"token"
:
customerToken
,
}];
}];
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
...
@@ -154,7 +153,7 @@
...
@@ -154,7 +153,7 @@
@"token"
:
customerToken
,
@"token"
:
customerToken
,
}];
}];
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
...
@@ -169,7 +168,7 @@
...
@@ -169,7 +168,7 @@
-
(
BUYRequestOperation
*
)
getOrdersForCustomerWithCallback
:(
BUYDataOrdersBlock
)
block
-
(
BUYRequestOperation
*
)
getOrdersForCustomerWithCallback
:(
BUYDataOrdersBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCustomersOrders
];
NSURL
*
route
=
[
self
urlForCustomersOrders
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
NSArray
*
orders
=
[
self
.
modelManager
ordersWithJSONDictionary
:
json
];
NSArray
*
orders
=
[
self
.
modelManager
ordersWithJSONDictionary
:
json
];
block
(
orders
,
error
);
block
(
orders
,
error
);
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Internal.h
View file @
5488ed77
...
@@ -32,7 +32,7 @@ static NSString * const BUYShopifyErrorDomain = @"shopify";
...
@@ -32,7 +32,7 @@ static NSString * const BUYShopifyErrorDomain = @"shopify";
static
NSString
*
const
BUYClientVersionString
=
@"1.3"
;
static
NSString
*
const
BUYClientVersionString
=
@"1.3"
;
static
NSString
*
const
BUYClientCustomerAccessToken
=
@"X-Shopify-Customer-Access-Token"
;
static
NSString
*
const
BUYClientCustomerAccessToken
=
@"X-Shopify-Customer-Access-Token"
;
typedef
void
(
^
BUYClientRequestJSONCompletion
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
);
typedef
void
(
^
BUYClientRequestJSONCompletion
)(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
);
@interface
BUYClient
(
Internal
)
@interface
BUYClient
(
Internal
)
...
@@ -51,7 +51,6 @@ typedef void (^BUYClientRequestJSONCompletion)(NSDictionary *json, NSURLResponse
...
@@ -51,7 +51,6 @@ typedef void (^BUYClientRequestJSONCompletion)(NSDictionary *json, NSURLResponse
-
(
BUYRequestOperation
*
)
patchRequestForURL
:(
NSURL
*
)
url
object
:(
id
<
BUYSerializable
>
)
object
start
:(
BOOL
)
start
completionHandler
:(
BUYClientRequestJSONCompletion
)
completionHandler
;
-
(
BUYRequestOperation
*
)
patchRequestForURL
:(
NSURL
*
)
url
object
:(
id
<
BUYSerializable
>
)
object
start
:(
BOOL
)
start
completionHandler
:(
BUYClientRequestJSONCompletion
)
completionHandler
;
-
(
BUYStatus
)
statusForStatusCode
:(
NSUInteger
)
statusCode
error
:(
NSError
*
)
error
;
-
(
BUYStatus
)
statusForStatusCode
:(
NSUInteger
)
statusCode
error
:(
NSError
*
)
error
;
-
(
NSError
*
)
errorFromJSON
:(
NSDictionary
*
)
json
response
:(
NSURLResponse
*
)
response
;
-
(
void
)
startOperation
:(
BUYOperation
*
)
operation
;
-
(
void
)
startOperation
:(
BUYOperation
*
)
operation
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.h
View file @
5488ed77
...
@@ -50,6 +50,7 @@
...
@@ -50,6 +50,7 @@
-
(
NSURL
*
)
urlForCustomersWithID
:(
NSString
*
)
identifier
;
-
(
NSURL
*
)
urlForCustomersWithID
:(
NSString
*
)
identifier
;
-
(
NSURL
*
)
urlForCustomersActivationWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
urlForCustomersActivationWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
urlForCustomersToken
;
-
(
NSURL
*
)
urlForCustomersToken
;
-
(
NSURL
*
)
urlForCustomersTokenWithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
urlForCustomersTokenRenewalWithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
urlForCustomersTokenRenewalWithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
urlForCustomersPasswordRecovery
;
-
(
NSURL
*
)
urlForCustomersPasswordRecovery
;
-
(
NSURL
*
)
urlForCustomersPasswordResetWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
urlForCustomersPasswordResetWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.m
View file @
5488ed77
...
@@ -193,6 +193,11 @@
...
@@ -193,6 +193,11 @@
return
[[[
self
urlForCustomers
]
appendPath
:
@"/customer_token"
]
appendExtension
];
return
[[[
self
urlForCustomers
]
appendPath
:
@"/customer_token"
]
appendExtension
];
}
}
-
(
NSURL
*
)
urlForCustomersTokenWithID
:
(
NSString
*
)
customerID
{
return
[[[
self
urlForCustomersWithID
:
customerID
]
appendPath
:
@"/customer_token"
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersTokenRenewalWithID
:
(
NSString
*
)
customerID
-
(
NSURL
*
)
urlForCustomersTokenRenewalWithID
:
(
NSString
*
)
customerID
{
{
return
[[[
self
urlForCustomersWithID
:
customerID
]
appendPath
:
@"/customer_token/renew"
]
appendExtension
];
return
[[[
self
urlForCustomersWithID
:
customerID
]
appendPath
:
@"/customer_token/renew"
]
appendExtension
];
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Storefront.m
View file @
5488ed77
...
@@ -49,7 +49,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
...
@@ -49,7 +49,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
-
(
BUYRequestOperation
*
)
getShop
:(
BUYDataShopBlock
)
block
-
(
BUYRequestOperation
*
)
getShop
:(
BUYDataShopBlock
)
block
{
{
return
[
self
getRequestForURL
:[
self
urlForShop
]
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:[
self
urlForShop
]
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
BUYShop
*
shop
=
nil
;
BUYShop
*
shop
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
shop
=
[
self
.
modelManager
insertShopWithJSONDictionary
:
json
];
shop
=
[
self
.
modelManager
insertShopWithJSONDictionary
:
json
];
...
@@ -65,7 +65,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
...
@@ -65,7 +65,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
@"page"
:
@
(
page
),
@"page"
:
@
(
page
),
}];
}];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
products
=
nil
;
NSArray
*
products
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
...
@@ -99,7 +99,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
...
@@ -99,7 +99,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
@"product_ids"
:
[
productIds
componentsJoinedByString
:
@","
],
@"product_ids"
:
[
productIds
componentsJoinedByString
:
@","
],
}];
}];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
products
=
nil
;
NSArray
*
products
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
...
@@ -126,7 +126,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
...
@@ -126,7 +126,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
@"page"
:
@
(
page
),
@"page"
:
@
(
page
),
}];
}];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
collections
=
nil
;
NSArray
*
collections
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
...
@@ -152,7 +152,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
...
@@ -152,7 +152,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
@"sort_by"
:
[
BUYCollection
sortOrderParameterForCollectionSort
:
sortOrder
]
@"sort_by"
:
[
BUYCollection
sortOrderParameterForCollectionSort
:
sortOrder
]
}];
}];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NS
HTTP
URLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
products
=
nil
;
NSArray
*
products
=
nil
;
if
(
json
&&
!
error
)
{
if
(
json
&&
!
error
)
{
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
5488ed77
...
@@ -108,11 +108,10 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
...
@@ -108,11 +108,10 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
return
status
;
return
status
;
}
}
-
(
NSError
*
)
errorFromJSON
:
(
NSDictionary
*
)
json
response
:
(
NSURLResponse
*
)
response
-
(
NSError
*
)
errorFromJSON
:
(
NSDictionary
*
)
json
response
:
(
NS
HTTP
URLResponse
*
)
response
{
{
NSInteger
statusCode
=
[((
NSHTTPURLResponse
*
)
response
)
statusCode
];
if
((
int
)(
response
.
statusCode
/
100
.
0
)
!=
2
)
{
// If not a 2xx response code
if
((
int
)(
statusCode
/
100
.
0
)
!=
2
)
{
// If not a 2xx response code
return
[[
NSError
alloc
]
initWithDomain
:
BUYShopifyErrorDomain
code
:
response
.
statusCode
userInfo
:
json
];
return
[[
NSError
alloc
]
initWithDomain
:
BUYShopifyErrorDomain
code
:
statusCode
userInfo
:
json
];
}
}
return
nil
;
return
nil
;
}
}
...
@@ -206,7 +205,12 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
...
@@ -206,7 +205,12 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
request
.
HTTPMethod
=
method
;
request
.
HTTPMethod
=
method
;
BUYRequestOperation
*
operation
=
[[
BUYRequestOperation
alloc
]
initWithSession
:
self
.
session
request
:
request
payload
:
object
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRequestOperation
*
operation
=
[[
BUYRequestOperation
alloc
]
initWithSession
:
self
.
session
request
:
request
payload
:
object
completion
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
!
error
)
{
error
=
[
self
errorFromJSON
:
json
response
:
response
];
}
[
self
.
callbackQueue
addOperationWithBlock
:
^
{
[
self
.
callbackQueue
addOperationWithBlock
:
^
{
completionHandler
(
json
,
response
,
error
);
completionHandler
(
json
,
response
,
error
);
}];
}];
...
...
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