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
93c81413
Commit
93c81413
authored
May 13, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor route creation / management out of BUYClient.
parent
d956de37
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
366 additions
and
85 deletions
+366
-85
BUYClientTestBase.h
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTestBase.h
+1
-1
BUYIntegrationTest.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
+1
-1
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+16
-0
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+23
-81
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+0
-0
BUYClient_Internal.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient_Internal.h
+4
-2
BUYRouter.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.h
+68
-0
BUYRouter.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.m
+253
-0
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTestBase.h
View file @
93c81413
...
...
@@ -44,7 +44,7 @@ extern NSString * const BUYFakeCustomerToken;
@property
(
nonatomic
,
strong
)
NSString
*
giftCardCode2
;
@property
(
nonatomic
,
strong
)
NSString
*
giftCardCode3
;
@property
(
nonatomic
,
strong
)
NSString
*
giftCardCodeExpired
;
@property
(
nonatomic
,
strong
)
NS
String
*
giftCardIdExpired
;
@property
(
nonatomic
,
strong
)
NS
Number
*
giftCardIdExpired
;
@property
(
nonatomic
,
strong
)
NSString
*
giftCardCodeInvalid
;
@property
(
nonatomic
,
strong
)
NSString
*
discountCodeValid
;
@property
(
nonatomic
,
strong
)
NSString
*
discountCodeExpired
;
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
View file @
93c81413
...
...
@@ -517,7 +517,7 @@
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingInvalidGiftCardFromCheckout_2"
];
}];
BUYGiftCard
*
giftCard
=
[[
BUYGiftCard
alloc
]
initWithModelManager
:
_modelManager
JSONDictionary
:@{
@"id"
:
@
"000"
}];
BUYGiftCard
*
giftCard
=
[[
BUYGiftCard
alloc
]
initWithModelManager
:
_modelManager
JSONDictionary
:@{
@"id"
:
@
(
000
)
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
removeGiftCard
:
giftCard
fromCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
XCTAssertNotNil
(
error
);
...
...
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
View file @
93c81413
...
...
@@ -356,6 +356,10 @@
9A47CF201CE50EBB00A6D5BA
/* BUYApplePayTestToken.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A47CF1F1CE50EBB00A6D5BA
/* BUYApplePayTestToken.m */
;
};
9A47CF221CE5112A00A6D5BA
/* BUYAssert.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A47CF211CE5112A00A6D5BA
/* BUYAssert.h */
;
};
9A47CF231CE5112A00A6D5BA
/* BUYAssert.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A47CF211CE5112A00A6D5BA
/* BUYAssert.h */
;
};
9A53317E1CE5F92A0025964B
/* BUYRouter.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A53317C1CE5F9260025964B
/* BUYRouter.m */
;
};
9A53317F1CE5F92B0025964B
/* BUYRouter.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A53317C1CE5F9260025964B
/* BUYRouter.m */
;
};
9A5331801CE5F9310025964B
/* BUYRouter.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A53317B1CE5F9260025964B
/* BUYRouter.h */
;
};
9A5331811CE5F9310025964B
/* BUYRouter.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A53317B1CE5F9260025964B
/* BUYRouter.h */
;
};
9A6B03791CDA5D4F0054C26E
/* BUYAccountCredentialsTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A6B03781CDA5D4F0054C26E
/* BUYAccountCredentialsTests.m */
;
};
BE47340F1B66C4EF00AA721A
/* BUYError.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
BE47340D1B66C4EF00AA721A
/* BUYError.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
BE4734101B66C4EF00AA721A
/* BUYError.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
BE47340E1B66C4EF00AA721A
/* BUYError.m */
;
};
...
...
@@ -623,6 +627,8 @@
9A47CF1E1CE50EBB00A6D5BA
/* BUYApplePayTestToken.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYApplePayTestToken.h
;
sourceTree
=
"<group>"
;
};
9A47CF1F1CE50EBB00A6D5BA
/* BUYApplePayTestToken.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYApplePayTestToken.m
;
sourceTree
=
"<group>"
;
};
9A47CF211CE5112A00A6D5BA
/* BUYAssert.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
BUYAssert.h
;
path
=
../Additions/BUYAssert.h
;
sourceTree
=
"<group>"
;
};
9A53317B1CE5F9260025964B
/* BUYRouter.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYRouter.h
;
sourceTree
=
"<group>"
;
};
9A53317C1CE5F9260025964B
/* BUYRouter.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYRouter.m
;
sourceTree
=
"<group>"
;
};
9A6B03781CDA5D4F0054C26E
/* BUYAccountCredentialsTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYAccountCredentialsTests.m
;
sourceTree
=
"<group>"
;
};
BE33B4ED1B15FF4D0067982B
/* BUYApplePayHelpers.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYApplePayHelpers.h
;
sourceTree
=
"<group>"
;
};
BE33B4EE1B15FF4D0067982B
/* BUYApplePayHelpers.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYApplePayHelpers.m
;
sourceTree
=
"<group>"
;
};
...
...
@@ -1098,6 +1104,8 @@
isa
=
PBXGroup
;
children
=
(
8498DCB01CDD1B4A00BD12A8
/* BUYClient_Internal.h */
,
9A53317B1CE5F9260025964B
/* BUYRouter.h */
,
9A53317C1CE5F9260025964B
/* BUYRouter.m */
,
F7FDA17019C93F6F00AF4E93
/* BUYClient.h */
,
F7FDA17119C93F6F00AF4E93
/* BUYClient.m */
,
8498DCB11CDD1B4A00BD12A8
/* BUYClient+Customers.h */
,
...
...
@@ -1188,6 +1196,9 @@
9032F2DB1BE9457A00BB9EEF
/* BUYCheckoutAttribute.h in Headers */
,
9019315E1BC5B9BC00D1134E
/* BUYError.h in Headers */
,
84980F371CB75C2900CFAB58
/* NSPropertyDescription+BUYAdditions.h in Headers */
,
9019315F1BC5B9BC00D1134E
/* BUYProductHeaderCell.h in Headers */
,
9A5331801CE5F9310025964B
/* BUYRouter.h in Headers */
,
901931601BC5B9BC00D1134E
/* BUYProductViewErrorView.h in Headers */
,
901931611BC5B9BC00D1134E
/* BUYClient.h in Headers */
,
849810971CB7E07900CFAB58
/* BUYFlatCollectionTransformer.h in Headers */
,
901931641BC5B9BC00D1134E
/* BUYCartLineItem.h in Headers */
,
...
...
@@ -1281,6 +1292,9 @@
9032F2DA1BE9457A00BB9EEF
/* BUYCheckoutAttribute.h in Headers */
,
BE47340F1B66C4EF00AA721A
/* BUYError.h in Headers */
,
84980F361CB75C2900CFAB58
/* NSPropertyDescription+BUYAdditions.h in Headers */
,
BEB74A6D1B5564200005A300
/* BUYProductHeaderCell.h in Headers */
,
9A5331811CE5F9310025964B
/* BUYRouter.h in Headers */
,
903BCC7C1B7D1C2D00C21FEB
/* BUYProductViewErrorView.h in Headers */
,
BE9A64471B503C8B0033E558
/* BUYClient.h in Headers */
,
849810961CB7E07900CFAB58
/* BUYFlatCollectionTransformer.h in Headers */
,
9003969B1B601DF400226B73
/* BUYCartLineItem.h in Headers */
,
...
...
@@ -1508,6 +1522,7 @@
9A47CEFE1CE39F6100A6D5BA
/* BUYCreditCardToken.m in Sources */
,
901930F21BC5B9BC00D1134E
/* BUYOrder.m in Sources */
,
849810991CB7E07900CFAB58
/* BUYFlatCollectionTransformer.m in Sources */
,
9A53317F1CE5F92B0025964B
/* BUYRouter.m in Sources */
,
84DD12A41CC63FE600A2442D
/* _BUYLineItem.m in Sources */
,
84DD12CC1CC63FEE00A2442D
/* _BUYTaxLine.m in Sources */
,
84DD12CA1CC63FEE00A2442D
/* _BUYShippingRate.m in Sources */
,
...
...
@@ -1637,6 +1652,7 @@
9A47CEFD1CE39F6000A6D5BA
/* BUYCreditCardToken.m in Sources */
,
90E83BC51B9F550E00C95A1B
/* BUYOrder.m in Sources */
,
849810981CB7E07900CFAB58
/* BUYFlatCollectionTransformer.m in Sources */
,
9A53317E1CE5F92A0025964B
/* BUYRouter.m in Sources */
,
84DD128C1CC63FE600A2442D
/* _BUYLineItem.m in Sources */
,
84DD12BE1CC63FEE00A2442D
/* _BUYTaxLine.m in Sources */
,
84DD12BC1CC63FEE00A2442D
/* _BUYShippingRate.m in Sources */
,
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
93c81413
...
...
@@ -31,6 +31,7 @@
#import "BUYAccountCredentials.h"
#import "BUYOrder.h"
#import "BUYShopifyErrorCodes.h"
#import "BUYRouter.h"
@interface
BUYAuthenticatedResponse
:
NSObject
+
(
BUYAuthenticatedResponse
*
)
responseFromJSON
:(
NSDictionary
*
)
json
;
...
...
@@ -60,8 +61,8 @@
-
(
NSURLSessionDataTask
*
)
getCustomerWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponentsForCustomer
WithID
:
customerID
];
return
[
self
getRequestForURL
:
components
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomers
WithID
:
customerID
];
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
...
...
@@ -72,8 +73,8 @@
-
(
NSURLSessionDataTask
*
)
createCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponents
ForCustomers
];
return
[
self
postRequestForURL
:
components
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRoute
*
route
=
[
self
.
router
route
ForCustomers
];
return
[
self
postRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
json
callback
:
block
];
}
...
...
@@ -85,8 +86,8 @@
-
(
NSURLSessionDataTask
*
)
createTokenForCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerJSON
:(
NSDictionary
*
)
customerJSON
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponentsForCustomerLogi
n
];
return
[
self
postRequestForURL
:
components
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersToke
n
];
return
[
self
postRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseFromJSON
:
json
];
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
...
...
@@ -114,9 +115,8 @@
-
(
NSURLSessionDataTask
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataCheckoutStatusBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponentsForPasswordReset
];
return
[
self
postRequestForURL
:
components
.
URL
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersPasswordRecovery
];
return
[
self
postRequestForURL
:
route
.
URL
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
if
(
!
error
)
{
...
...
@@ -130,9 +130,9 @@
-
(
NSURLSessionDataTask
*
)
renewCustomerTokenWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataTokenBlock
)
block
{
if
(
self
.
customerToken
)
{
NSURLComponents
*
components
=
[
self
URLComponentsFor
TokenRenewalWithID
:
customerID
];
BUYRoute
*
route
=
[
self
.
router
routeForCustomers
TokenRenewalWithID
:
customerID
];
return
[
self
putRequestForURL
:
components
.
URL
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
.
URL
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
accessToken
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -155,9 +155,12 @@
-
(
NSURLSessionDataTask
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
customerToken
:(
NSString
*
)
customerToken
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponentsForCustomerActivationWithID
:
customerID
customerToken
:
customerToken
];
BUYRoute
*
route
=
[
self
.
router
routeForCustomersActivationWithID
:
customerID
];
route
.
queryItems
=
@{
@"token"
:
customerToken
,
};
return
[
self
putRequestForURL
:
components
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
...
...
@@ -171,9 +174,12 @@
-
(
NSURLSessionDataTask
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
customerToken
:(
NSString
*
)
customerToken
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponentsForCustomerPasswordResetWithCustomerID
:
customerID
customerToken
:
customerToken
];
BUYRoute
*
route
=
[
self
.
router
routeForCustomersPasswordResetWithID
:
customerID
];
route
.
queryItems
=
@{
@"token"
:
customerToken
,
};
return
[
self
putRequestForURL
:
components
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
...
...
@@ -187,8 +193,8 @@
-
(
NSURLSessionDataTask
*
)
getOrdersForCustomerWithCallback
:(
BUYDataOrdersBlock
)
block
{
NSURLComponents
*
components
=
[
self
URLComponentsForCustomer
Orders
];
return
[
self
getRequestForURL
:
components
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomers
Orders
];
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
NSArray
*
orders
=
[
self
.
modelManager
ordersWithJSONDictionary
:
json
];
block
(
orders
,
error
);
...
...
@@ -198,68 +204,4 @@
}];
}
#pragma mark - URL Formatting
-
(
NSURLComponents
*
)
URLComponentsForCustomers
{
return
[
self
customerURLComponentsAppendingPath
:
nil
];
}
-
(
NSURLComponents
*
)
URLComponentsForCustomerWithID
:
(
NSString
*
)
customerID
{
return
[
self
customerURLComponentsAppendingPath
:
customerID
];
}
-
(
NSURLComponents
*
)
URLComponentsForCustomerLogin
{
return
[
self
customerURLComponentsAppendingPath
:
@"customer_token"
];
}
-
(
NSURLComponents
*
)
URLComponentsForCustomerActivationWithID
:
(
NSString
*
)
customerID
customerToken
:
(
NSString
*
)
customerToken
{
NSDictionary
*
queryItems
=
@{
@"token"
:
customerToken
};
NSString
*
path
=
[
NSString
stringWithFormat
:
@"%@/activate"
,
customerID
];
return
[
self
customerURLComponentsAppendingPath
:
path
queryItems
:
queryItems
];
}
-
(
NSURLComponents
*
)
URLComponentsForCustomerPasswordResetWithCustomerID
:
(
NSString
*
)
customerID
customerToken
:
(
NSString
*
)
customerToken
{
NSDictionary
*
queryItems
=
@{
@"token"
:
customerToken
};
NSString
*
path
=
[
NSString
stringWithFormat
:
@"%@/reset"
,
customerID
];
return
[
self
customerURLComponentsAppendingPath
:
path
queryItems
:
queryItems
];
}
-
(
NSURLComponents
*
)
URLComponentsForPasswordReset
{
return
[
self
customerURLComponentsAppendingPath
:
@"recover"
queryItems
:
nil
];
}
-
(
NSURLComponents
*
)
URLComponentsForTokenRenewalWithID
:
(
NSString
*
)
customerID
{
NSString
*
path
=
[
NSString
stringWithFormat
:
@"%@/customer_token/renew"
,
customerID
];
return
[
self
customerURLComponentsAppendingPath
:
path
queryItems
:
nil
];
}
-
(
NSURLComponents
*
)
URLComponentsForCustomerOrders
{
return
[
self
customerURLComponentsAppendingPath
:
@"orders"
queryItems
:
nil
];
}
#pragma mark - Convenience methods
-
(
NSURLComponents
*
)
customerURLComponentsAppendingPath
:
(
NSString
*
)
path
{
return
[
self
customerURLComponentsAppendingPath
:
path
queryItems
:
nil
];
}
-
(
NSURLComponents
*
)
customerURLComponentsAppendingPath
:
(
NSString
*
)
path
queryItems
:
(
NSDictionary
*
)
queryItems
{
return
[
self
URLComponentsForAPIPath
:
@"customers"
appendingPath
:
path
queryItems
:
queryItems
];
}
-
(
NSString
*
)
accessTokenFromHeaders
:
(
NSDictionary
*
)
headers
{
return
[
headers
valueForKey
:
BUYClientCustomerAccessToken
];
}
@end
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
93c81413
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient_Internal.h
View file @
93c81413
...
...
@@ -29,14 +29,16 @@
extern
NSString
*
const
kShopifyError
;
@class
BUYRouter
;
@interface
BUYClient
(
Internal
)
@property
(
nonatomic
,
strong
)
BUYRouter
*
router
;
-
(
NSURLSessionDataTask
*
)
postRequestForURL
:(
NSURL
*
)
url
object
:(
id
<
BUYSerializable
>
)
object
completionHandler
:(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
;
-
(
NSURLSessionDataTask
*
)
putRequestForURL
:(
NSURL
*
)
url
object
:(
id
<
BUYSerializable
>
)
object
completionHandler
:(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
;
-
(
NSURLSessionDataTask
*
)
getRequestForURL
:(
NSURL
*
)
url
completionHandler
:(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
;
-
(
NSURLComponents
*
)
URLComponentsForAPIPath
:(
NSString
*
)
apiPath
appendingPath
:(
NSString
*
)
appendingPath
queryItems
:(
NSDictionary
*
)
queryItems
;
-
(
NSError
*
)
errorFromJSON
:(
NSDictionary
*
)
json
response
:(
NSURLResponse
*
)
response
;
@end
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.h
0 → 100644
View file @
93c81413
//
// BUYRouter.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>
@interface
BUYRoute
:
NSObject
@property
(
strong
,
nonatomic
,
readonly
)
NSURL
*
URL
;
@property
(
strong
,
nonatomic
,
readonly
)
NSDictionary
*
queryItems
;
-
(
void
)
setQueryItems
:(
NSDictionary
*
)
queryItems
;
@end
@interface
BUYRouter
:
NSObject
-
(
instancetype
)
initWithShopDomain
:(
NSString
*
)
shopDomain
appID
:(
NSString
*
)
appID
;
-
(
BUYRoute
*
)
routeForAPI
;
-
(
BUYRoute
*
)
routeForApps
;
-
(
BUYRoute
*
)
routeForShop
;
-
(
BUYRoute
*
)
routeForProductListings
;
-
(
BUYRoute
*
)
routeForCollectionListings
;
-
(
BUYRoute
*
)
routeForCheckouts
;
-
(
BUYRoute
*
)
routeForCheckoutsWithToken
:(
NSString
*
)
token
;
-
(
BUYRoute
*
)
routeForCheckoutsProcessingWithToken
:(
NSString
*
)
token
;
-
(
BUYRoute
*
)
routeForCheckoutsCompletionWithToken
:(
NSString
*
)
token
;
-
(
BUYRoute
*
)
routeForCheckoutsShippingRatesWithToken
:(
NSString
*
)
token
;
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCard
;
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCardWithToken
:(
NSString
*
)
token
;
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCard
:(
NSNumber
*
)
giftCardID
token
:(
NSString
*
)
token
;
-
(
BUYRoute
*
)
routeForCustomers
;
-
(
BUYRoute
*
)
routeForCustomersOrders
;
-
(
BUYRoute
*
)
routeForCustomersWithID
:(
NSString
*
)
identifier
;
-
(
BUYRoute
*
)
routeForCustomersActivationWithID
:(
NSString
*
)
identifier
;
-
(
BUYRoute
*
)
routeForCustomersToken
;
-
(
BUYRoute
*
)
routeForCustomersTokenRenewalWithID
:(
NSString
*
)
customerID
;
-
(
BUYRoute
*
)
routeForCustomersPasswordRecovery
;
-
(
BUYRoute
*
)
routeForCustomersPasswordResetWithID
:(
NSString
*
)
identifier
;
@end
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.m
0 → 100644
View file @
93c81413
//
// BUYRouter.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYRouter.h"
#pragma mark - Route -
@interface
BUYRoute
()
@property
(
strong
,
nonatomic
)
NSURLComponents
*
components
;
@end
@implementation
BUYRoute
+
(
instancetype
)
routeWithFormat
:(
NSString
*
)
format
,
...
{
va_list
list
;
va_start
(
list
,
format
);
NSString
*
URLString
=
[[
NSString
alloc
]
initWithFormat
:
format
arguments
:
list
];
va_end
(
list
);
return
[[[
self
class
]
alloc
]
initWithURLString
:
URLString
];
}
-
(
instancetype
)
initWithURLString
:(
NSString
*
)
URLString
{
self
=
[
super
init
];
if
(
self
)
{
NSURL
*
url
=
[
NSURL
URLWithString
:
URLString
];
_components
=
[
NSURLComponents
componentsWithURL
:
url
resolvingAgainstBaseURL
:
NO
];
}
return
self
;
}
-
(
void
)
setQueryItems
:(
NSDictionary
*
)
queryItems
{
_queryItems
=
queryItems
;
NSMutableArray
*
items
=
[
NSMutableArray
new
];
[
queryItems
enumerateKeysAndObjectsUsingBlock
:
^
(
NSString
*
key
,
id
value
,
BOOL
*
stop
)
{
[
items
addObject
:[
NSURLQueryItem
queryItemWithName
:
key
value
:[
NSString
stringWithFormat
:
@"%@"
,
value
]]];
}];
[
_components
setQueryItems
:
items
];
}
#pragma mark - Accessors -
-
(
NSURL
*
)
URL
{
/* ---------------------------------
* All API requests should end with
* a .json suffix.
*/
return
[
_components
.
URL
URLByAppendingPathExtension
:
@"json"
];
}
#pragma mark - Mutation -
-
(
BUYRoute
*
)
appendFormat
:
(
NSString
*
)
format
,
...
{
va_list
list
;
va_start
(
list
,
format
);
NSString
*
formattedString
=
[[
NSString
alloc
]
initWithFormat
:
format
arguments
:
list
];
va_end
(
list
);
if
(
formattedString
.
length
>
0
)
{
_components
.
path
=
[
_components
.
path
stringByAppendingPathComponent
:
formattedString
];
}
return
self
;
}
-
(
BUYRoute
*
)
appendPath
:
(
NSString
*
)
path
{
return
[
self
appendFormat
:
path
];
}
-
(
BUYRoute
*
)
appendIdentifier
:
(
NSNumber
*
)
identifier
{
return
[
self
appendFormat
:
@"%@"
,
identifier
];
}
@end
#pragma mark - Router -
@interface
BUYRouter
()
@property
(
strong
,
nonatomic
)
NSString
*
shopDomain
;
@property
(
strong
,
nonatomic
)
NSString
*
appID
;
@end
@implementation
BUYRouter
#pragma mark - Init -
-
(
instancetype
)
initWithShopDomain
:(
NSString
*
)
shopDomain
appID
:(
NSString
*
)
appID
{
self
=
[
super
init
];
if
(
self
)
{
_shopDomain
=
shopDomain
;
_appID
=
appID
;
}
return
self
;
}
#pragma mark - API -
-
(
BUYRoute
*
)
routeForAPI
{
return
[
BUYRoute
routeWithFormat
:
@"https://%@/api/"
,
self
.
shopDomain
];
}
-
(
BUYRoute
*
)
routeForApps
{
return
[[
self
routeForAPI
]
appendFormat
:
@"/apps/%@"
,
self
.
appID
];
}
#pragma mark - Storefront -
-
(
BUYRoute
*
)
routeForShop
{
return
[[
self
routeForAPI
]
appendPath
:
@"/meta"
];
}
-
(
BUYRoute
*
)
routeForProductListings
{
return
[[
self
routeForApps
]
appendPath
:
@"/product_listings"
];
}
-
(
BUYRoute
*
)
routeForCollectionListings
{
return
[[
self
routeForApps
]
appendPath
:
@"/collection_listings"
];
}
#pragma mark - Checkout -
-
(
BUYRoute
*
)
routeForCheckouts
{
return
[[
self
routeForAPI
]
appendPath
:
@"/checkouts"
];
}
-
(
BUYRoute
*
)
routeForCheckoutsWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@""
withToken
:
token
];
}
-
(
BUYRoute
*
)
routeForCheckoutsProcessingWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@"/processing"
withToken
:
token
];
}
-
(
BUYRoute
*
)
routeForCheckoutsCompletionWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@"/complete"
withToken
:
token
];
}
-
(
BUYRoute
*
)
routeForCheckoutsShippingRatesWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@"/shipping_rates"
withToken
:
token
];
}
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCard
{
return
[[
self
routeForCheckouts
]
appendPath
:
@"/gift_cards"
];
}
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCardWithToken
:
(
NSString
*
)
token
{
return
[[[
self
routeForCheckouts
]
appendPath
:
@"/gift_cards"
]
appendPath
:
token
];
}
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCard
:
(
NSNumber
*
)
giftCardID
token
:
(
NSString
*
)
token
{
return
[[[
self
routeForCheckoutsUsingGiftCard
]
appendIdentifier
:
giftCardID
]
appendPath
:
token
];
}
#pragma mark - Customers -
-
(
BUYRoute
*
)
routeForCustomers
{
return
[[
self
routeForAPI
]
appendPath
:
@"/customers"
];
}
-
(
BUYRoute
*
)
routeForCustomersOrders
{
return
[[
self
routeForCustomers
]
appendPath
:
@"/orders"
];
}
-
(
BUYRoute
*
)
routeForCustomersWithID
:
(
NSString
*
)
identifier
{
return
[[
self
routeForCustomers
]
appendPath
:
identifier
];
}
-
(
BUYRoute
*
)
routeForCustomersActivationWithID
:
(
NSString
*
)
identifier
{
return
[[
self
routeForCustomersWithID
:
identifier
]
appendPath
:
@"/activate"
];
}
-
(
BUYRoute
*
)
routeForCustomersToken
{
return
[[
self
routeForCustomers
]
appendPath
:
@"/customer_token"
];
}
-
(
BUYRoute
*
)
routeForCustomersTokenRenewalWithID
:
(
NSString
*
)
customerID
{
return
[[
self
routeForCustomersWithID
:
customerID
]
appendPath
:
@"/customer_token/renew"
];
}
-
(
BUYRoute
*
)
routeForCustomersPasswordRecovery
{
return
[[
self
routeForCustomers
]
appendPath
:
@"/recover"
];
}
-
(
BUYRoute
*
)
routeForCustomersPasswordResetWithID
:
(
NSString
*
)
identifier
{
return
[[
self
routeForCustomersWithID
:
identifier
]
appendPath
:
@"/reset"
];
}
#pragma mark - Utilities -
-
(
BUYRoute
*
)
routeForCheckoutsAction
:
(
NSString
*
)
action
withToken
:
(
NSString
*
)
token
{
return
[[[
self
routeForCheckouts
]
appendPath
:
action
]
appendPath
:
token
];
}
@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