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
May 16, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move URL composition into BUYClient category. Remove BUYRouter.
parent
f76276d2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
340 additions
and
396 deletions
+340
-396
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+0
-0
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+21
-23
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
+40
-47
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
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
=
@{
@"token"
:
customerToken
,
};
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
=
@{
@"token"
:
customerToken
,
};
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
);
...
...
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
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
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
b5170416
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
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
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