-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Methods for User Followers, Profile and Addresses
- Loading branch information
Showing
5 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Etsy\Exception; | ||
|
||
class SdkException extends \Exception { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Etsy\Resources; | ||
|
||
use Etsy\Resource; | ||
|
||
/** | ||
* UserAddress resource class. Represents a User's profile Address in Etsy. | ||
* | ||
* @link https://www.etsy.com/developers/documentation/reference/useraddress | ||
* @author Rhys Hall hello@rhyshall.com | ||
*/ | ||
class UserAddress extends Resource { | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $_associations = [ | ||
'Country' => 'Country', | ||
'User' => 'User' | ||
]; | ||
|
||
/** | ||
* Deletes the cart. | ||
* | ||
* @return boolean | ||
*/ | ||
public function delete() { | ||
return $this->deleteRequest( | ||
"/users/{$this->user_id}/addresses/{$this->user_address_id}" | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Etsy\Utils; | ||
|
||
use Etsy\Exception\SdkException; | ||
|
||
/** | ||
* Methods for handling and validating addresses. | ||
* | ||
* @author Rhys Hall hello@rhyshall.com | ||
*/ | ||
class Address { | ||
|
||
/** | ||
* 61 = Australia | ||
* 79 = Canada | ||
* 209 = United States | ||
*/ | ||
const VALID_STATES = [ | ||
61 => ['ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA'], | ||
79 => ['AB', 'BC', 'MB', 'NB', 'NL', 'NT', 'NS', 'NU', 'ON', 'PE', 'QC', 'SK', 'YT'], | ||
209 => ['AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FM', 'FL', 'GA', 'GU', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MH', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR', 'PW', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VI', 'VA', 'WA', 'WV', 'WI', 'WY', 'AA', 'AE', 'AP'] | ||
]; | ||
|
||
/** | ||
* Validates the state value for required countries. Does not return boolean | ||
* but throws an error if state is invalid. | ||
* | ||
* @param integer/string $country_id | ||
* @param string $state | ||
* @return void | ||
*/ | ||
public static function validateState($country_id, string $state) { | ||
if(in_array($country_id, array_keys(self::VALID_STATES))) { | ||
if(!in_array($state, self::VALID_STATES[$country_id])) { | ||
throw new SdkException("{$state} is not a valid state for country ID {$country_id}. Valid values are ".implode(', ', self::VALID_STATES[$country_id])); | ||
} | ||
} | ||
} | ||
|
||
} |