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
b5170416
Commit
b5170416
authored
8 years ago
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move URL composition into BUYClient category. Remove BUYRouter.
parent
f76276d2
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
342 additions
and
396 deletions
+342
-396
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+14
-12
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+19
-21
BUYClient+Routing.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.h
+57
-0
BUYClient+Routing.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.m
+222
-0
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+30
-37
BUYRouter.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.h
+0
-68
BUYRouter.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.m
+0
-258
No files found.
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
View file @
b5170416
...
...
@@ -339,6 +339,10 @@
90F593091B0D5F4C0026B382
/* BUYClientTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
90F592FD1B0D5F4C0026B382
/* BUYClientTest.m */
;
};
90F5930A1B0D5F4C0026B382
/* BUYLineItemTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
90F592FE1B0D5F4C0026B382
/* BUYLineItemTest.m */
;
};
90F5930B1B0D5F4C0026B382
/* BUYObjectTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
90F592FF1B0D5F4C0026B382
/* BUYObjectTests.m */
;
};
9A0B0C661CEA703E0037D68F
/* BUYClient+Routing.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C641CEA703E0037D68F
/* BUYClient+Routing.h */
;
};
9A0B0C671CEA703E0037D68F
/* BUYClient+Routing.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C641CEA703E0037D68F
/* BUYClient+Routing.h */
;
};
9A0B0C681CEA703E0037D68F
/* BUYClient+Routing.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C651CEA703E0037D68F
/* BUYClient+Routing.m */
;
};
9A0B0C691CEA703E0037D68F
/* BUYClient+Routing.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C651CEA703E0037D68F
/* BUYClient+Routing.m */
;
};
9A102D1B1CDD1F960026CC43
/* BUYErrorTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A102D1A1CDD1F960026CC43
/* BUYErrorTests.m */
;
};
9A102D1E1CDD25980026CC43
/* BUYOptionValueTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A102D1D1CDD25980026CC43
/* BUYOptionValueTests.m */
;
};
9A47CEFD1CE39F6000A6D5BA
/* BUYCreditCardToken.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A47CEFB1CE39F5B00A6D5BA
/* BUYCreditCardToken.m */
;
};
...
...
@@ -356,10 +360,6 @@
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 */
;
};
...
...
@@ -615,6 +615,10 @@
90F592FE1B0D5F4C0026B382
/* BUYLineItemTest.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYLineItemTest.m
;
sourceTree
=
"<group>"
;
};
90F592FF1B0D5F4C0026B382
/* BUYObjectTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYObjectTests.m
;
sourceTree
=
"<group>"
;
};
90F593001B0D5F4C0026B382
/* BUYTestConstants.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYTestConstants.h
;
sourceTree
=
"<group>"
;
};
90FC31A61B50371600AFAB51
/* BUYProductViewHeaderBackgroundImageView.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
lineEnding
=
0
;
name
=
BUYProductViewHeaderBackgroundImageView.h
;
path
=
"Product View/BUYProductViewHeaderBackgroundImageView.h"
;
sourceTree
=
"<group>"
;
xcLanguageSpecificationIdentifier
=
xcode.lang.objcpp
;
};
90FC31A71B50371600AFAB51
/* BUYProductViewHeaderBackgroundImageView.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
BUYProductViewHeaderBackgroundImageView.m
;
path
=
"Product View/BUYProductViewHeaderBackgroundImageView.m"
;
sourceTree
=
"<group>"
;
};
9A0B0C641CEA703E0037D68F
/* BUYClient+Routing.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"BUYClient+Routing.h"
;
sourceTree
=
"<group>"
;
};
9A0B0C651CEA703E0037D68F
/* BUYClient+Routing.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+Routing.m"
;
sourceTree
=
"<group>"
;
};
9A102D1A1CDD1F960026CC43
/* BUYErrorTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYErrorTests.m
;
sourceTree
=
"<group>"
;
};
9A102D1D1CDD25980026CC43
/* BUYOptionValueTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYOptionValueTests.m
;
sourceTree
=
"<group>"
;
};
9A47CEF81CE39EC200A6D5BA
/* BUYPaymentToken.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYPaymentToken.h
;
sourceTree
=
"<group>"
;
};
...
...
@@ -627,8 +631,6 @@
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>"
;
};
...
...
@@ -1104,10 +1106,10 @@
isa
=
PBXGroup
;
children
=
(
8498DCB01CDD1B4A00BD12A8
/* BUYClient_Internal.h */
,
9A53317B1CE5F9260025964B
/* BUYRouter.h */
,
9A53317C1CE5F9260025964B
/* BUYRouter.m */
,
F7FDA17019C93F6F00AF4E93
/* BUYClient.h */
,
F7FDA17119C93F6F00AF4E93
/* BUYClient.m */
,
9A0B0C641CEA703E0037D68F
/* BUYClient+Routing.h */
,
9A0B0C651CEA703E0037D68F
/* BUYClient+Routing.m */
,
8498DCB11CDD1B4A00BD12A8
/* BUYClient+Customers.h */
,
8498DCB21CDD1B4A00BD12A8
/* BUYClient+Customers.m */
,
);
...
...
@@ -1130,6 +1132,7 @@
84DD12C51CC63FEE00A2442D
/* _BUYGiftCard.h in Headers */
,
84DD12A91CC63FE600A2442D
/* _BUYOrder.h in Headers */
,
84DD129F1CC63FE600A2442D
/* _BUYCustomer.h in Headers */
,
9A0B0C671CEA703E0037D68F
/* BUYClient+Routing.h in Headers */
,
84DD12991CC63FE600A2442D
/* _BUYCart.h in Headers */
,
84DD129D1CC63FE600A2442D
/* _BUYCollection.h in Headers */
,
84DD12A11CC63FE600A2442D
/* _BUYImageLink.h in Headers */
,
...
...
@@ -1197,7 +1200,6 @@
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 */
,
...
...
@@ -1226,6 +1228,7 @@
84DD12B91CC63FEE00A2442D
/* _BUYMaskedCreditCard.h in Headers */
,
84DD12B31CC63FEE00A2442D
/* _BUYCheckout.h in Headers */
,
84DD12BD1CC63FEE00A2442D
/* _BUYTaxLine.h in Headers */
,
9A0B0C661CEA703E0037D68F
/* BUYClient+Routing.h in Headers */
,
84DD12B71CC63FEE00A2442D
/* _BUYGiftCard.h in Headers */
,
84DD12911CC63FE600A2442D
/* _BUYOrder.h in Headers */
,
84DD12811CC63FE600A2442D
/* _BUYCart.h in Headers */
,
...
...
@@ -1293,7 +1296,6 @@
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 */
,
...
...
@@ -1511,6 +1513,7 @@
84980F611CB7617E00CFAB58
/* BUYDateTransformer.m in Sources */
,
901930E81BC5B9BC00D1134E
/* BUYImageLink.m in Sources */
,
84DD129E1CC63FE600A2442D
/* _BUYCollection.m in Sources */
,
9A0B0C691CEA703E0037D68F
/* BUYClient+Routing.m in Sources */
,
901930E91BC5B9BC00D1134E
/* BUYProductVariant.m in Sources */
,
84D9154E1CC03F1600D334FB
/* BUYManagedObject.m in Sources */
,
84B0A7331CE10ED900253EB0
/* BUYApplePayPaymentProvider.m in Sources */
,
...
...
@@ -1522,7 +1525,6 @@
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 */
,
...
...
@@ -1641,6 +1643,7 @@
84980F601CB7617E00CFAB58
/* BUYDateTransformer.m in Sources */
,
BE9A645A1B503CD90033E558
/* BUYImageLink.m in Sources */
,
84DD12861CC63FE600A2442D
/* _BUYCollection.m in Sources */
,
9A0B0C681CEA703E0037D68F
/* BUYClient+Routing.m in Sources */
,
BE9A64641B503CFB0033E558
/* BUYProductVariant.m in Sources */
,
84D9154D1CC03F1600D334FB
/* BUYManagedObject.m in Sources */
,
84B0A7321CE10ED900253EB0
/* BUYApplePayPaymentProvider.m in Sources */
,
...
...
@@ -1652,7 +1655,6 @@
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 */
,
...
...
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
b5170416
...
...
@@ -26,12 +26,12 @@
#import "BUYClient+Customers.h"
#import "BUYClient_Internal.h"
#import "BUYClient+Routing.h"
#import "NSDateFormatter+BUYAdditions.h"
#import "BUYCustomer.h"
#import "BUYAccountCredentials.h"
#import "BUYOrder.h"
#import "BUYShopifyErrorCodes.h"
#import "BUYRouter.h"
@interface
BUYAuthenticatedResponse
:
NSObject
+
(
BUYAuthenticatedResponse
*
)
responseFromJSON
:(
NSDictionary
*
)
json
;
...
...
@@ -61,8 +61,8 @@
-
(
NSURLSessionDataTask
*
)
getCustomerWithID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersWithID
:
customerID
];
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCustomersWithID
:
customerID
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
...
...
@@ -73,8 +73,8 @@
-
(
NSURLSessionDataTask
*
)
createCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerTokenBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomers
];
return
[
self
postRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCustomers
];
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
[
self
createTokenForCustomerWithCredentials
:
credentials
customerJSON
:
json
callback
:
block
];
}
...
...
@@ -86,8 +86,8 @@
-
(
NSURLSessionDataTask
*
)
createTokenForCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerJSON
:(
NSDictionary
*
)
customerJSON
callback
:(
BUYDataCustomerTokenBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersToken
];
return
[
self
postRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCustomersToken
];
return
[
self
postRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseFromJSON
:
json
];
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
...
...
@@ -115,8 +115,8 @@
-
(
NSURLSessionDataTask
*
)
recoverPasswordForCustomer
:(
NSString
*
)
email
callback
:(
BUYDataCheckoutStatusBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersPasswordRecovery
];
return
[
self
postRequestForURL
:
route
.
URL
object
:@{
@"email"
:
email
}
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCustomersPasswordRecovery
];
return
[
self
postRequestForURL
:
route
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
)
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersTokenRenewalWithID
:
customerID
];
NSURL
*
route
=
[
self
routeForCustomersTokenRenewalWithID
:
customerID
];
return
[
self
putRequestForURL
:
route
.
URL
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
accessToken
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -155,12 +155,11 @@
-
(
NSURLSessionDataTask
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
customerToken
:(
NSString
*
)
customerToken
callback
:(
BUYDataCustomerTokenBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersActivationWithID
:
customerID
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForCustomersActivationWithID
:
customerID
parameters
:@{
@"token"
:
customerToken
,
}
;
}]
;
return
[
self
putRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
...
...
@@ -174,12 +173,11 @@
-
(
NSURLSessionDataTask
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
customerToken
:(
NSString
*
)
customerToken
callback
:(
BUYDataCustomerTokenBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersPasswordResetWithID
:
customerID
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForCustomersPasswordResetWithID
:
customerID
parameters
:@{
@"token"
:
customerToken
,
}
;
}]
;
return
[
self
putRequestForURL
:
route
.
URL
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
if
(
email
&&
!
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
email
];
...
...
@@ -193,8 +191,8 @@
-
(
NSURLSessionDataTask
*
)
getOrdersForCustomerWithCallback
:(
BUYDataOrdersBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCustomersOrders
];
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCustomersOrders
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
NSArray
*
orders
=
[
self
.
modelManager
ordersWithJSONDictionary
:
json
];
block
(
orders
,
error
);
...
...
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.h
0 → 100644
View file @
b5170416
//
// BUYClient+Routing.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 "BUYClient.h"
@interface
BUYClient
(
Routing
)
-
(
NSURL
*
)
routeForAPI
;
-
(
NSURL
*
)
routeForApps
;
-
(
NSURL
*
)
routeForShop
;
-
(
NSURL
*
)
routeForProductListingsWithParameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
routeForCollectionListingsWithParameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
routeForCheckouts
;
-
(
NSURL
*
)
routeForCheckoutsWithToken
:(
NSString
*
)
token
;
-
(
NSURL
*
)
routeForCheckoutsProcessingWithToken
:(
NSString
*
)
token
;
-
(
NSURL
*
)
routeForCheckoutsCompletionWithToken
:(
NSString
*
)
token
;
-
(
NSURL
*
)
routeForCheckoutsShippingRatesWithToken
:(
NSString
*
)
token
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
routeForCheckoutsUsingGiftCard
;
-
(
NSURL
*
)
routeForCheckoutsUsingGiftCardWithToken
:(
NSString
*
)
token
;
-
(
NSURL
*
)
routeForCheckoutsUsingGiftCard
:(
NSNumber
*
)
giftCardID
token
:(
NSString
*
)
token
;
-
(
NSURL
*
)
routeForCustomers
;
-
(
NSURL
*
)
routeForCustomersOrders
;
-
(
NSURL
*
)
routeForCustomersWithID
:(
NSString
*
)
identifier
;
-
(
NSURL
*
)
routeForCustomersActivationWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
routeForCustomersToken
;
-
(
NSURL
*
)
routeForCustomersTokenRenewalWithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
routeForCustomersPasswordRecovery
;
-
(
NSURL
*
)
routeForCustomersPasswordResetWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
@end
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.m
0 → 100644
View file @
b5170416
//
// BUYClient+Routing.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 "BUYClient+Routing.h"
#pragma mark - NSURL (Private Routing) -
@interface
NSURL
(
PrivateRouting
)
@end
@implementation
NSURL
(
PrivateRouting
)
+
(
instancetype
)
URLWithFormat
:(
NSString
*
)
format
,
...
{
va_list
list
;
va_start
(
list
,
format
);
NSString
*
URLString
=
[[
NSString
alloc
]
initWithFormat
:
format
arguments
:
list
];
va_end
(
list
);
return
[[
NSURL
alloc
]
initWithString
:
URLString
];
}
-
(
NSURL
*
)
appendFormat
:(
NSString
*
)
format
,
...
{
va_list
list
;
va_start
(
list
,
format
);
NSString
*
formattedString
=
[[
NSString
alloc
]
initWithFormat
:
format
arguments
:
list
];
va_end
(
list
);
NSURL
*
trimmedURL
=
[
self
removeExtension
];
if
(
formattedString
.
length
>
0
)
{
return
[
trimmedURL
URLByAppendingPathComponent
:
formattedString
];
}
return
trimmedURL
;
}
-
(
NSURL
*
)
appendPath
:(
NSString
*
)
path
{
return
[
self
appendFormat
:
path
];
}
-
(
NSURL
*
)
appendIdentifier
:(
NSNumber
*
)
identifier
{
return
[
self
appendFormat
:
@"%@"
,
identifier
];
}
-
(
NSURL
*
)
appendParameters
:(
NSDictionary
*
)
parameters
{
NSURLComponents
*
components
=
[
NSURLComponents
componentsWithURL
:
self
resolvingAgainstBaseURL
:
NO
];
NSMutableArray
*
queryItems
=
[
NSMutableArray
new
];
[
parameters
enumerateKeysAndObjectsUsingBlock
:
^
(
NSString
*
key
,
id
value
,
BOOL
*
stop
)
{
[
queryItems
addObject
:[
NSURLQueryItem
queryItemWithName
:
key
value
:[
NSString
stringWithFormat
:
@"%@"
,
value
]]];
}];
[
components
setQueryItems
:
queryItems
];
return
components
.
URL
;
}
-
(
NSURL
*
)
appendExtension
{
return
[
self
URLByAppendingPathExtension
:
@"json"
];
}
-
(
NSURL
*
)
removeExtension
{
return
[
self
URLByDeletingPathExtension
];
}
@end
#pragma mark - BUYClient (Routing) -
@implementation
BUYClient
(
Routing
)
#pragma mark - API -
-
(
NSURL
*
)
routeForShopDomain
{
return
[
NSURL
URLWithFormat
:
@"https://%@"
,
self
.
shopDomain
];
}
-
(
NSURL
*
)
routeForAPI
{
return
[[
self
routeForShopDomain
]
appendPath
:
@"/api"
];
}
-
(
NSURL
*
)
routeForApps
{
return
[[
self
routeForAPI
]
appendFormat
:
@"/apps/%@"
,
self
.
appId
];
}
#pragma mark - Storefront -
-
(
NSURL
*
)
routeForShop
{
return
[[[
self
routeForShopDomain
]
appendPath
:
@"/meta"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForProductListingsWithParameters
:
(
NSDictionary
*
)
parameters
{
return
[[[[
self
routeForApps
]
appendPath
:
@"/product_listings"
]
appendExtension
]
appendParameters
:
parameters
];
}
-
(
NSURL
*
)
routeForCollectionListingsWithParameters
:
(
NSDictionary
*
)
parameters
{
return
[[[[
self
routeForApps
]
appendPath
:
@"/collection_listings"
]
appendExtension
]
appendParameters
:
parameters
];
}
#pragma mark - Checkout -
-
(
NSURL
*
)
routeForCheckouts
{
return
[[[
self
routeForAPI
]
appendPath
:
@"/checkouts"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCheckoutsWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@""
withToken
:
token
];
}
-
(
NSURL
*
)
routeForCheckoutsProcessingWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@"/processing"
withToken
:
token
];
}
-
(
NSURL
*
)
routeForCheckoutsCompletionWithToken
:
(
NSString
*
)
token
{
return
[
self
routeForCheckoutsAction
:
@"/complete"
withToken
:
token
];
}
-
(
NSURL
*
)
routeForCheckoutsShippingRatesWithToken
:
(
NSString
*
)
token
parameters
:
(
NSDictionary
*
)
parameters
{
return
[[[
self
routeForCheckoutsAction
:
@"/shipping_rates"
withToken
:
token
]
appendExtension
]
appendParameters
:
parameters
];
}
-
(
NSURL
*
)
routeForCheckoutsUsingGiftCard
{
return
[[[
self
routeForCheckouts
]
appendPath
:
@"/gift_cards"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCheckoutsUsingGiftCardWithToken
:
(
NSString
*
)
token
{
return
[[[[
self
routeForCheckouts
]
appendPath
:
token
]
appendPath
:
@"/gift_cards"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCheckoutsUsingGiftCard
:
(
NSNumber
*
)
giftCardID
token
:
(
NSString
*
)
token
{
return
[[[
self
routeForCheckoutsUsingGiftCardWithToken
:
token
]
appendIdentifier
:
giftCardID
]
appendExtension
];
}
#pragma mark - Customers -
-
(
NSURL
*
)
routeForCustomers
{
return
[[[
self
routeForAPI
]
appendPath
:
@"/customers"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersOrders
{
return
[[[
self
routeForCustomers
]
appendPath
:
@"/orders"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersWithID
:
(
NSString
*
)
identifier
{
return
[[[
self
routeForCustomers
]
appendPath
:
identifier
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersActivationWithID
:
(
NSString
*
)
identifier
parameters
:
(
NSDictionary
*
)
parameters
{
return
[[[[
self
routeForCustomersWithID
:
identifier
]
appendPath
:
@"/activate"
]
appendParameters
:
parameters
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersToken
{
return
[[[
self
routeForCustomers
]
appendPath
:
@"/customer_token"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersTokenRenewalWithID
:
(
NSString
*
)
customerID
{
return
[[[
self
routeForCustomersWithID
:
customerID
]
appendPath
:
@"/customer_token/renew"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersPasswordRecovery
{
return
[[[
self
routeForCustomers
]
appendPath
:
@"/recover"
]
appendExtension
];
}
-
(
NSURL
*
)
routeForCustomersPasswordResetWithID
:
(
NSString
*
)
identifier
parameters
:
(
NSDictionary
*
)
parameters
{
return
[[[[
self
routeForCustomersWithID
:
identifier
]
appendPath
:
@"/reset"
]
appendExtension
]
appendParameters
:
parameters
];
}
#pragma mark - Utilities -
-
(
NSURL
*
)
routeForCheckoutsAction
:
(
NSString
*
)
action
withToken
:
(
NSString
*
)
token
{
return
[[[[
self
routeForCheckouts
]
appendPath
:
token
]
appendPath
:
action
]
appendExtension
];
}
@end
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
b5170416
...
...
@@ -25,6 +25,7 @@
//
#import "BUYClient_Internal.h"
#import "BUYClient+Routing.h"
#import "BUYAssert.h"
#import "BUYAddress.h"
...
...
@@ -45,7 +46,6 @@
#import "NSDecimalNumber+BUYAdditions.h"
#import "NSDictionary+BUYAdditions.h"
#import "NSURLComponents+BUYAdditions.h"
#import "BUYRouter.h"
#define kGET @"GET"
#define kPOST @"POST"
...
...
@@ -76,7 +76,6 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
@property
(
nonatomic
,
strong
)
NSURLSession
*
session
;
@property
(
nonatomic
,
strong
)
NSString
*
merchantId
;
@property
(
nonatomic
,
strong
)
BUYRouter
*
router
;
@end
...
...
@@ -97,7 +96,6 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
self
=
[
super
init
];
if
(
self
)
{
self
.
router
=
[[
BUYRouter
alloc
]
initWithShopDomain
:
shopDomain
appID
:
appId
];
self
.
modelManager
=
[
BUYModelManager
modelManager
];
self
.
shopDomain
=
shopDomain
;
self
.
apiKey
=
apiKey
;
...
...
@@ -135,7 +133,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
-
(
NSURLSessionDataTask
*
)
getShop
:
(
BUYDataShopBlock
)
block
{
return
[
self
getRequestForURL
:[
self
.
router
routeForShop
].
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:[
self
routeForShop
]
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYShop
*
shop
=
nil
;
if
(
json
&&
!
error
)
{
shop
=
[
self
.
modelManager
insertShopWithJSONDictionary
:
json
];
...
...
@@ -146,13 +144,12 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
-
(
NSURLSessionDataTask
*
)
getProductsPage
:
(
NSUInteger
)
page
completion
:
(
BUYDataProductListBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForProductListings
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForProductListingsWithParameters
:@{
@"limit"
:
@
(
self
.
pageSize
),
@"page"
:
@
(
page
),
}
;
}]
;
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
products
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -182,12 +179,11 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
{
BUYAssert
(
productIds
,
@"Failed to get product by IDs. Product IDs array must not be nil."
);
BUYRoute
*
route
=
[
self
.
router
routeForProductListings
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForProductListingsWithParameters
:@{
@"product_ids"
:
[
productIds
componentsJoinedByString
:
@","
],
}
;
}]
;
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
products
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -209,13 +205,12 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
-
(
NSURLSessionDataTask
*
)
getCollectionsPage
:
(
NSUInteger
)
page
completion
:
(
BUYDataCollectionsListBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCollectionListings
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForCollectionListingsWithParameters
:@{
@"limit"
:
@
(
self
.
pageSize
),
@"page"
:
@
(
page
),
}
;
}]
;
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
collections
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -234,15 +229,14 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
{
BUYAssert
(
collectionId
,
@"Failed to get products page. Invalid collectionID."
);
BUYRoute
*
route
=
[
self
.
router
routeForProductListings
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForProductListingsWithParameters
:@{
@"collection_id"
:
collectionId
,
@"limit"
:
@
(
self
.
pageSize
),
@"page"
:
@
(
page
),
@"sort_by"
:
[
BUYCollection
sortOrderParameterForCollectionSort
:
sortOrder
]
}
;
}]
;
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
products
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -296,7 +290,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
-
(
NSURLSessionDataTask
*
)
postCheckout
:
(
NSDictionary
*
)
checkoutJSON
completion
:
(
BUYDataCheckoutBlock
)
block
{
return
[
self
postRequestForURL
:[
self
.
router
routeForCheckouts
].
URL
object
:
checkoutJSON
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:[
self
routeForCheckouts
]
object
:
checkoutJSON
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}
...
...
@@ -307,9 +301,9 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
BUYAssert
(
giftCardCode
.
length
>
0
,
@"Failed to apply gift card code. Invalid gift card code."
);
BUYGiftCard
*
giftCard
=
[
self
.
modelManager
giftCardWithCode
:
giftCardCode
];
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsUsingGiftCardWithToken
:
checkout
.
token
];
NSURL
*
route
=
[
self
routeForCheckoutsUsingGiftCardWithToken
:
checkout
.
token
];
return
[
self
postRequestForURL
:
route
.
URL
object
:
giftCard
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
postRequestForURL
:
route
object
:
giftCard
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
YES
];
}
...
...
@@ -322,8 +316,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
BUYAssertCheckout
(
checkout
);
BUYAssert
(
giftCard
.
identifier
,
@"Failed to remove gift card. Gift card must have a valid identifier."
);
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsUsingGiftCard
:
giftCard
.
identifier
token
:
checkout
.
token
];
return
[
self
deleteRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCheckoutsUsingGiftCard
:
giftCard
.
identifier
token
:
checkout
.
token
];
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
!
error
)
{
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
NO
];
}
...
...
@@ -352,8 +346,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
{
BUYAssertCheckout
(
checkout
);
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsWithToken
:
checkout
.
token
];
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCheckoutsWithToken
:
checkout
.
token
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}
...
...
@@ -362,8 +356,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
{
BUYAssertCheckout
(
checkout
);
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsWithToken
:
checkout
.
token
];
return
[
self
patchRequestForURL
:
route
.
URL
object
:
checkout
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCheckoutsWithToken
:
checkout
.
token
];
return
[
self
patchRequestForURL
:
route
object
:
checkout
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}
...
...
@@ -376,8 +370,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
BUYAssert
(
paymentToken
||
isFree
,
@"Failed to complete checkout. Checkout must have a payment token or have a payment value equal to $0.00"
);
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsCompletionWithToken
:
checkout
.
token
];
return
[
self
postRequestForURL
:
route
.
URL
object
:[
paymentToken
JSONDictionary
]
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCheckoutsCompletionWithToken
:
checkout
.
token
];
return
[
self
postRequestForURL
:
route
object
:[
paymentToken
JSONDictionary
]
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
[
self
handleCheckoutResponse
:
json
error
:
error
block
:
block
];
}];
}
...
...
@@ -408,8 +402,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
-
(
NSURLSessionDataTask
*
)
getCompletionStatusOfCheckoutToken
:
(
NSString
*
)
token
completion
:
(
BUYDataCheckoutStatusBlock
)
block
{
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsProcessingWithToken
:
token
];
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSURL
*
route
=
[
self
routeForCheckoutsProcessingWithToken
:
token
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSInteger
statusCode
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
block
([
BUYClient
statusForStatusCode
:
statusCode
error
:
error
],
error
);
}];
...
...
@@ -421,12 +415,11 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
{
BUYAssertCheckout
(
checkout
);
BUYRoute
*
route
=
[
self
.
router
routeForCheckoutsShippingRatesWithToken
:
checkout
.
token
];
route
.
queryItems
=
@{
NSURL
*
route
=
[
self
routeForCheckoutsShippingRatesWithToken
:
checkout
.
token
parameters
:@{
@"checkout"
:
@""
,
}
;
}]
;
return
[
self
getRequestForURL
:
route
.
URL
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
NSArray
*
shippingRates
=
nil
;
if
(
json
&&
!
error
)
{
shippingRates
=
[
self
.
modelManager
insertShippingRatesWithJSONArray
:
json
[
@"shipping_rates"
]];
...
...
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.h
deleted
100644 → 0
View file @
f76276d2
//
// 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
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYRouter.m
deleted
100644 → 0
View file @
f76276d2
//
// 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
*
)
routeForShopDomain
{
return
[
BUYRoute
routeWithFormat
:
@"https://%@"
,
self
.
shopDomain
];
}
-
(
BUYRoute
*
)
routeForAPI
{
return
[[
self
routeForShopDomain
]
appendPath
:
@"/api"
];
}
-
(
BUYRoute
*
)
routeForApps
{
return
[[
self
routeForAPI
]
appendFormat
:
@"/apps/%@"
,
self
.
appID
];
}
#pragma mark - Storefront -
-
(
BUYRoute
*
)
routeForShop
{
return
[[
self
routeForShopDomain
]
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
:
token
]
appendPath
:
@"/gift_cards"
];
}
-
(
BUYRoute
*
)
routeForCheckoutsUsingGiftCard
:
(
NSNumber
*
)
giftCardID
token
:
(
NSString
*
)
token
{
return
[[
self
routeForCheckoutsUsingGiftCardWithToken
:
token
]
appendIdentifier
:
giftCardID
];
}
#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
:
token
]
appendPath
:
action
];
}
@end
This diff is collapsed.
Click to expand it.
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