Commit da1318c5 by Brent Gulanowski

Remove customerID parameter from address API.

Use the customerID from the customerToken instead.
parent b8be173a
...@@ -51,60 +51,55 @@ typedef void (^BUYDataAddressBlock)(BUYAddress * _Nullable address, NSError * _N ...@@ -51,60 +51,55 @@ typedef void (^BUYDataAddressBlock)(BUYAddress * _Nullable address, NSError * _N
* GET /api/customers/:customer_id/addresses * GET /api/customers/:customer_id/addresses
* Fetch all customer addresses * Fetch all customer addresses
* *
* @param customerID Customer ID for which to fetch all address
* @param block (NSArray<BUYAddress *> *addresses, NSError *error) * @param block (NSArray<BUYAddress *> *addresses, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (NSOperation *)getAddressesForCustomerID:(NSString *)customerID callback:(BUYDataAddressesBlock)block; - (NSOperation *)getAddressesCallback:(BUYDataAddressesBlock)block;
/** /**
* GET /api/customers/:customer_id/addresses/:id * GET /api/customers/:customer_id/addresses/:id
* Fetch a customer address by ID * Fetch a customer address by ID
* *
* @param addressID Identifier of the address to fetch * @param addressID Identifier of the address to fetch
* @param customerID Customer ID for which to fetch the address
* @param block (BUYAddress *address, NSError *error) * @param block (BUYAddress *address, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (NSOperation *)getAddressWithID:(NSNumber *)addressID customerID:(NSString *)customerID callback:(BUYDataAddressBlock)block; - (NSOperation *)getAddressWithID:(NSNumber *)addressID callback:(BUYDataAddressBlock)block;
/** /**
* POST /api/customers/:customer_id/addresses * POST /api/customers/:customer_id/addresses
* Creates a new customer address * Creates a new customer address
* *
* @param address Address to create * @param address Address to create
* @param customer Customer ID for which to create the address
* @param block (BUYAddress *address, NSError *error) * @param block (BUYAddress *address, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (NSOperation *)createAddress:(BUYAddress *)address customerID:(NSString *)customerID callback:(BUYDataAddressBlock)block; - (NSOperation *)createAddress:(BUYAddress *)address callback:(BUYDataAddressBlock)block;
/** /**
* PUT /api/customers/:customer_id/addresses/:id * PUT /api/customers/:customer_id/addresses/:id
* Updates the customer address * Updates the customer address
* *
* @param address Address to update, containing updated values * @param address Address to update, containing updated values
* @param customerID Customer ID for which to update the address
* @param block (BUYAddress *address, NSError *error) * @param block (BUYAddress *address, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (NSOperation *)updateAddress:(BUYAddress *)address customerID:(NSString *)customerID callback:(BUYDataAddressBlock)block; - (NSOperation *)updateAddress:(BUYAddress *)address callback:(BUYDataAddressBlock)block;
/** /**
* DELETE /api/customers/:customer_id/addresses/:id * DELETE /api/customers/:customer_id/addresses/:id
* Delete the customer address * Delete the customer address
* *
* @param addressID Address ID to delete * @param addressID Address ID to delete
* @param customerID Customer ID for which to delete the address
* @param block (BUYStatus status, NSError *error) * @param block (BUYStatus status, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (NSOperation *)deleteAddressWithID:(NSNumber *)addressID customerID:(NSString *)customerID callback:(BUYDataStatusBlock)block; - (NSOperation *)deleteAddressWithID:(NSNumber *)addressID callback:(BUYDataStatusBlock)block;
@end @end
......
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
@implementation BUYClient (Address) @implementation BUYClient (Address)
- (NSOperation *)getAddressesForCustomerID:(NSString *)customerID callback:(BUYDataAddressesBlock)block - (NSOperation *)getAddressesCallback:(BUYDataAddressesBlock)block
{ {
NSURL *route = [self urlForCustomersAddressesWithID:customerID]; NSURL *route = [self urlForCustomersAddresses];
return [self getRequestForURL:route completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self getRequestForURL:route completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
NSArray<BUYAddress *> *addresses = nil; NSArray<BUYAddress *> *addresses = nil;
if (json && !error) { if (json && !error) {
...@@ -45,9 +45,9 @@ ...@@ -45,9 +45,9 @@
}]; }];
} }
- (NSOperation *)getAddressWithID:(NSNumber *)addressID customerID:(NSString *)customerID callback:(BUYDataAddressBlock)block - (NSOperation *)getAddressWithID:(NSNumber *)addressID callback:(BUYDataAddressBlock)block
{ {
NSURL *route = [self urlForCustomersAddressWithID:customerID addressID:addressID]; NSURL *route = [self urlForCustomersAddressWithAddressID:addressID];
return [self getRequestForURL:route completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self getRequestForURL:route completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
BUYAddress *address = nil; BUYAddress *address = nil;
if (json && !error) { if (json && !error) {
...@@ -57,9 +57,9 @@ ...@@ -57,9 +57,9 @@
}]; }];
} }
- (NSOperation *)createAddress:(BUYAddress *)address customerID:(NSString *)customerID callback:(BUYDataAddressBlock)block - (NSOperation *)createAddress:(BUYAddress *)address callback:(BUYDataAddressBlock)block
{ {
NSURL *route = [self urlForCustomersAddressesWithID:customerID]; NSURL *route = [self urlForCustomersAddresses];
return [self postRequestForURL:route object:@{ @"address" : address.JSONDictionary } completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self postRequestForURL:route object:@{ @"address" : address.JSONDictionary } completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
BUYAddress *address = nil; BUYAddress *address = nil;
if (json && !error) { if (json && !error) {
...@@ -69,11 +69,11 @@ ...@@ -69,11 +69,11 @@
}]; }];
} }
- (NSOperation *)updateAddress:(BUYAddress *)address customerID:(NSString *)customerID callback:(BUYDataAddressBlock)block - (NSOperation *)updateAddress:(BUYAddress *)address callback:(BUYDataAddressBlock)block
{ {
BUYAssert(address.identifier, @"Failed to update address. Address must have a valid identifier."); BUYAssert(address.identifier, @"Failed to update address. Address must have a valid identifier.");
NSURL *route = [self urlForCustomersAddressWithID:customerID addressID:address.identifier]; NSURL *route = [self urlForCustomersAddressWithAddressID:address.identifier];
return [self putRequestForURL:route object:@{ @"address" : address.JSONDictionary } completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self putRequestForURL:route object:@{ @"address" : address.JSONDictionary } completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
BUYAddress *address = nil; BUYAddress *address = nil;
if (json && !error) { if (json && !error) {
...@@ -83,11 +83,11 @@ ...@@ -83,11 +83,11 @@
}]; }];
} }
- (NSOperation *)deleteAddressWithID:(NSNumber *)addressID customerID:(NSString *)customerID callback:(BUYDataStatusBlock)block - (NSOperation *)deleteAddressWithID:(NSNumber *)addressID callback:(BUYDataStatusBlock)block
{ {
BUYAssert(addressID, @"Failed to update address. Address must have a valid identifier."); BUYAssert(addressID, @"Failed to update address. Address must have a valid identifier.");
NSURL *route = [self urlForCustomersAddressWithID:customerID addressID:addressID]; NSURL *route = [self urlForCustomersAddressWithAddressID:addressID];
return [self deleteRequestForURL:route completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self deleteRequestForURL:route completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
block(response.statusCode, error); block(response.statusCode, error);
}]; }];
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
- (NSURL *)urlForCustomersActivationWithID:(NSString *)identifier parameters:(NSDictionary *)parameters; - (NSURL *)urlForCustomersActivationWithID:(NSString *)identifier parameters:(NSDictionary *)parameters;
- (NSURL *)urlForCustomersPasswordResetWithID:(NSString *)identifier parameters:(NSDictionary *)parameters; - (NSURL *)urlForCustomersPasswordResetWithID:(NSString *)identifier parameters:(NSDictionary *)parameters;
- (NSURL *)urlForCustomersAddressesWithID:(NSString *)customerID; - (NSURL *)urlForCustomersAddresses;
- (NSURL *)urlForCustomersAddressWithID:(NSString *)customerID addressID:(NSNumber *)addressID; - (NSURL *)urlForCustomersAddressWithAddressID:(NSNumber *)addressID;
@end @end
...@@ -233,14 +233,14 @@ ...@@ -233,14 +233,14 @@
#pragma mark - Customer Addresses - #pragma mark - Customer Addresses -
- (NSURL *)urlForCustomersAddressesWithID:(NSString *)customerID - (NSURL *)urlForCustomersAddresses
{ {
return [[[self urlForCustomersWithID:customerID] appendPath:@"/addresses"] appendExtension]; return [[[self urlForLoggedInCustomer] appendPath:@"/addresses"] appendExtension];
} }
- (NSURL *)urlForCustomersAddressWithID:(NSString *)customerID addressID:(NSNumber *)addressID - (NSURL *)urlForCustomersAddressWithAddressID:(NSNumber *)addressID
{ {
return [[[[self urlForCustomersWithID:customerID] appendPath:@"/addresses"] appendIdentifier:addressID] appendExtension]; return [[[[self urlForLoggedInCustomer] appendPath:@"/addresses"] appendIdentifier:addressID] appendExtension];
} }
#pragma mark - Utilities - #pragma mark - Utilities -
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment