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
cf1c4b2c
Commit
cf1c4b2c
authored
May 26, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Organize BUYClient+Customer.m (reorder methods, add pragma marks).
parent
3bc35a19
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
98 deletions
+118
-98
BUYClient+Customers.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
+47
-37
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+71
-61
No files found.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
View file @
cf1c4b2c
...
...
@@ -67,6 +67,8 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
@interface
BUYClient
(
Customers
)
#pragma mark - Getting -
/**
* GET /api/customers/:customer_id
* Gets an existing customer
...
...
@@ -78,6 +80,8 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
*/
-
(
BUYRequestOperation
*
)
getCustomerWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
;
#pragma mark - Customer -
/**
* POST /api/customers
* Creates a new customer
...
...
@@ -93,39 +97,44 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
-
(
BUYRequestOperation
*
)
createCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
;
/**
* POST /api/customers/customer_token
* Logs in an existing customer
* Expects email and password
* PUT /api/customers/:customer_id/activate
* Activates an unactivated customer
*
* @param credentials Credentials object containing items for required fields
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer being activated
* @param token Token contained in activation URL
* @param block (BUYCustomer *customer, NSString *token, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
BUYRequestOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
/**
* DELETE /api/customers/:customer_id/customer_token
* Logs out an existing customer
* Expects a customerID string
* PUT /api/customers/:customer_id
* Update customer credentials represented by BUYAccountCredentials object
*
* @param customer A customerID represented by a string
* @param block (BUYStatus status, NSError *error)
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer being activated
* @param block (BUYCustomer *customer, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
logoutCustomerID
:(
NSString
*
)
customerID
callback
:(
BUYDataStatus
Block
)
block
;
-
(
BUYRequestOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomer
Block
)
block
;
/**
* P
OST /api/customers/recover
*
Sends email for password recovery to an existing customer
* P
UT /api/customers/:customer_id/reset
*
Resets an existing customer's password
*
* @param email Email to send the password reset to
* @param block (BUYStatus status, NSError *error)
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer resetting password
* @param token Token contained in reset URL
* @param block (BUYCustomer *customer, NSString *token, NSError *error)
*
* @return
t
he associated BUYRequestOperation
* @return
T
he associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataStatusBlock
)
block
;
-
(
BUYRequestOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
#pragma mark - Token -
/**
* PUT /api/customers/:customer_id/customer_token/renew
...
...
@@ -138,43 +147,44 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
*/
-
(
BUYRequestOperation
*
)
renewCustomerTokenWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataTokenBlock
)
block
;
#pragma mark - Login -
/**
* PUT /api/customers/:customer_id/activate
* Activates an unactivated customer
* POST /api/customers/customer_token
* Logs in an existing customer
* Expects email and password
*
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer being activated
* @param token Token contained in activation URL
* @param credentials Credentials object containing items for required fields
* @param block (BUYCustomer *customer, NSString *token, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
;
/**
* PUT /api/customers/:customer_id
* Update customer credentials represented by BUYAccountCredentials object
* DELETE /api/customers/:customer_id/customer_token
* Logs out an existing customer
* Expects a customerID string
*
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer being activated
* @param block (BUYCustomer *customer, NSError *error)
* @param customer A customerID represented by a string
* @param block (BUYStatus status, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomer
Block
)
block
;
-
(
BUYRequestOperation
*
)
logoutCustomerID
:(
NSString
*
)
customerID
callback
:(
BUYDataStatus
Block
)
block
;
/**
* P
UT /api/customers/:customer_id/reset
*
Resets an existing customer's password
* P
OST /api/customers/recover
*
Sends email for password recovery to an existing customer
*
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer resetting password
* @param token Token contained in reset URL
* @param block (BUYCustomer *customer, NSString *token, NSError *error)
* @param email Email to send the password reset to
* @param block (BUYStatus status, NSError *error)
*
* @return
T
he associated BUYRequestOperation
* @return
t
he associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
BUYRequestOperation
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataStatusBlock
)
block
;
#pragma mark - Orders -
/**
* GET /api/customers/:customer_id/orders
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
cf1c4b2c
...
...
@@ -36,7 +36,7 @@
@implementation
BUYClient
(
Customers
)
#pragma mark -
Customer
#pragma mark -
Getting -
-
(
BUYRequestOperation
*
)
getCustomerWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
{
...
...
@@ -50,6 +50,8 @@
}];
}
#pragma mark - Customer -
-
(
BUYRequestOperation
*
)
createCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomers
];
...
...
@@ -63,23 +65,15 @@
}];
}
-
(
BUYRequestOperation
*
)
createTokenForCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerJSON
:(
NSDictionary
*
)
customerJSON
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
BUYRequestOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersToken
];
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
NSURL
*
route
=
[
self
urlForCustomersActivationWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
if
(
!
customerJSON
)
{
[
self
getCustomerWithID
:
authenticatedResponse
.
customerID
callback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
block
(
customer
,
self
.
customerToken
,
error
);
}];
}
else
{
BUYCustomer
*
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
[
@"customer"
]];
block
(
customer
,
self
.
customerToken
,
error
);
}
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
[
self
loginCustomerWithCredentials
:[
credentials
credentialsByAddingItems
:@[
emailItem
]]
callback
:
block
];
}
else
{
block
(
nil
,
nil
,
error
);
...
...
@@ -87,27 +81,36 @@
}];
}
-
(
BUYRequestOperation
*
)
logoutCustomerID
:(
NSString
*
)
customerID
callback
:(
BUYDataStatus
Block
)
block
-
(
BUYRequestOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomer
Block
)
block
{
NSURL
*
route
=
[
self
urlForCustomersTokenWithID
:
customerID
];
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
block
(
response
.
statusCode
,
error
);
NSURL
*
route
=
[
self
urlForCustomersWithID
:
customerID
];
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
}
block
(
customer
,
error
);
}];
}
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
BUYRequestOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
{
return
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
nil
callback
:
block
];
}
NSURL
*
route
=
[
self
urlForCustomersPasswordResetWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
-
(
BUYRequestOperation
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataStatusBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersPasswordRecovery
];
return
[
self
postRequestForURL
:
route
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
block
(
response
.
statusCode
,
error
);
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
[
self
loginCustomerWithCredentials
:[
credentials
credentialsByAddingItems
:@[
emailItem
]]
callback
:
block
];
}
else
{
block
(
nil
,
nil
,
error
);
}
}];
}
#pragma mark - Token -
-
(
BUYRequestOperation
*
)
renewCustomerTokenWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataTokenBlock
)
block
{
if
(
self
.
customerToken
)
{
...
...
@@ -129,50 +132,31 @@
}
}
-
(
BUYRequestOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersActivationWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
#pragma mark - Login -
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
[
self
loginCustomerWithCredentials
:[
credentials
credentialsByAddingItems
:@[
emailItem
]]
callback
:
block
];
}
else
{
block
(
nil
,
nil
,
error
);
}
-
(
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
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomer
Block
)
block
-
(
BUYRequestOperation
*
)
loginCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerToken
Block
)
block
{
NSURL
*
route
=
[
self
urlForCustomersWithID
:
customerID
];
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
}
block
(
customer
,
error
);
}];
return
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
nil
callback
:
block
];
}
-
(
BUYRequestOperation
*
)
re
setPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerToken
Block
)
block
-
(
BUYRequestOperation
*
)
re
coverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataStatus
Block
)
block
{
NSURL
*
route
=
[
self
urlForCustomersPasswordResetWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
[
self
loginCustomerWithCredentials
:[
credentials
credentialsByAddingItems
:@[
emailItem
]]
callback
:
block
];
}
else
{
block
(
nil
,
nil
,
error
);
}
NSURL
*
route
=
[
self
urlForCustomersPasswordRecovery
];
return
[
self
postRequestForURL
:
route
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
block
(
response
.
statusCode
,
error
);
}];
}
#pragma mark - Orders -
-
(
BUYRequestOperation
*
)
getOrdersForCustomerWithCallback
:(
BUYDataOrdersBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersOrders
];
...
...
@@ -186,4 +170,30 @@
}];
}
#pragma mark - Helpers -
-
(
BUYRequestOperation
*
)
createTokenForCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerJSON
:(
NSDictionary
*
)
customerJSON
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersToken
];
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
if
(
!
customerJSON
)
{
[
self
getCustomerWithID
:
authenticatedResponse
.
customerID
callback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
block
(
customer
,
self
.
customerToken
,
error
);
}];
}
else
{
BUYCustomer
*
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
[
@"customer"
]];
block
(
customer
,
self
.
customerToken
,
error
);
}
}
else
{
block
(
nil
,
nil
,
error
);
}
}];
}
@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