forked from aditisinghcedcoss/etsy-php
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add variation images call in etsy sdk
- Loading branch information
Mohd Shahbaz
committed
Feb 10, 2020
0 parents
commit 7aa926d
Showing
16 changed files
with
11,970 additions
and
0 deletions.
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,4 @@ | ||
vendor/ | ||
scripts/autoload.php | ||
test.php | ||
auth.php |
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,27 @@ | ||
# Required to run your project under the correct environment. | ||
language: php | ||
|
||
# Versions of PHP you want your project run with. | ||
php: | ||
- 7.1 | ||
- hhvm | ||
|
||
# Commands to be run before your environment runs. | ||
before_script: | ||
- pecl install oauth | ||
- composer self-update | ||
- composer install --prefer-source --no-interaction --dev | ||
# Commands you want to run that will verify your build. | ||
script: phpunit | ||
|
||
# allow_failures: Allow this build to fail under the specified environments. | ||
# fast_finish: If your build fails do not continue trying to build, just stop. | ||
matrix: | ||
allow_failures: | ||
- php: hhvm | ||
fast_finish: true | ||
|
||
# Customize when the notification emails are sent. | ||
notifications: | ||
on_success: never | ||
on_failure: always |
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,218 @@ | ||
# Etsy PHP SDK [![Build Status](https://travis-ci.org/inakiabt/etsy-php.svg?branch=master)](https://travis-ci.org/inakiabt/etsy-php) | ||
|
||
Based on [Etsy Rest API description](http://www.etsy.com/developers/documentation/reference/apimethod) output, this wrapper provides a simple client with all available methods on Etsy API (thanks to the `__call` magic PHP method!), validating its arguments on each request (Take a look to https://github.com/inakiabt/etsy-php/blob/master/src/Etsy/methods.json for full list of methods and its arguments). | ||
|
||
## I'm looking for help | ||
Lately, I couldn't dedicate the time I think this repo deserved, so I'm looking for help! | ||
|
||
## Requirements | ||
|
||
Note: I will be working on remove this dependencies | ||
* cURL devel: | ||
* Ubuntu: `sudo apt-get install libcurl4-dev` | ||
* Fedora/CentOS: `sudo yum install curl-devel` | ||
* OAuth pecl package: | ||
* `sudo pecl install oauth` | ||
* And then add the line `extension=oauth.so` to your `php.ini` | ||
|
||
## Installation | ||
|
||
The following recommended installation requires [composer](http://getcomposer.org/). If you are unfamiliar with composer see the [composer installation instructions](http://getcomposer.org/doc/01-basic-usage.md#installation). | ||
|
||
Add the following to your `composer.json` file: | ||
|
||
```json | ||
{ | ||
"require": { | ||
"inakiabt/etsy-php": ">=0.10" | ||
} | ||
} | ||
``` | ||
|
||
## Usage ## | ||
|
||
All methods has only one argument, an array with two items (both are optional, depends on the method): | ||
|
||
- *params*: an array with all required params to build the endpoint url. | ||
> Example: | ||
> [getSubSubCategory](http://www.etsy.com/developers/documentation/reference/category#method_getsubsubcategory): GET /categories/:tag/:subtag/:subsubtag | ||
```php | ||
# it will request /categories/tag1/subtag1/subsubtag1 | ||
$api->getSubSubCategory(array( | ||
'params' => array( | ||
'tag' => 'tag1', | ||
'subtag' => 'subtag1', | ||
'subsubtag' => 'subsubtag1' | ||
))); | ||
``` | ||
|
||
- *data*: an array with post data required by the method | ||
> Example: | ||
> [createShippingTemplate](http://www.etsy.com/developers/documentation/reference/shippingtemplate#method_createshippingtemplate): POST /shipping/templates | ||
```php | ||
# it will request /shipping/templates sending the "data" array as the post data | ||
$api->createShippingTemplate(array( | ||
'data' => array( | ||
"title" => "First API Template", | ||
"origin_country_id" => 209, | ||
"destination_country_id" => 209, | ||
"primary_cost" => 10.0, | ||
"secondary_cost" => 10.0 | ||
))); | ||
``` | ||
|
||
## OAuth configuration script ## | ||
Etsy API uses OAuth 1.0 authentication, so lets setup our credentials. | ||
|
||
The script `scripts/auth-setup.php` will generate an OAuth config file required by the Etsy client to make signed requests. | ||
Example: | ||
```bash | ||
export ETSY_CONSUMER_KEY=qwertyuiop123456dfghj | ||
export ETSY_CONSUMER_SECRET=qwertyuiop12 | ||
|
||
php scripts/auth-setup.php /path/to/my-oauth-config-destination.php | ||
``` | ||
It will show an URL you must open, sign in on Etsy and allow the application. Then copy paste the verification code on the terminal. | ||
(On Mac OSX, it will open your default browser automatically) | ||
|
||
### Generated OAuth config file ### | ||
After all, it should looks like this: | ||
```php | ||
<?php | ||
return array ( | ||
'consumer_key' => 'df7df6s5fdsf9sdh8gf9jhg98', | ||
'consumer_secret' => 'sdgd6sd4d', | ||
'token_secret' => 'a1234567890qwertyu', | ||
'token' => '3j3j3h33h3g5', | ||
'access_token' => '8asd8as8gag5sdg4fhg4fjfgj', | ||
'access_token_secret' => 'f8dgdf6gd5f4s', | ||
); | ||
``` | ||
|
||
## Initialization ## | ||
|
||
```php | ||
<?php | ||
require('vendor/autoload.php'); | ||
$auth = require('/path/to/my-oauth-config-destination.php'); | ||
|
||
$client = new Etsy\EtsyClient($auth['consumer_key'], $auth['consumer_secret']); | ||
$client->authorize($auth['access_token'], $auth['access_token_secret']); | ||
|
||
$api = new Etsy\EtsyApi($client); | ||
|
||
print_r($api->getUser(array('params' => array('user_id' => '__SELF__')))); | ||
``` | ||
|
||
## Examples ## | ||
|
||
```php | ||
print_r($api->createShippingTemplate(array( | ||
'data' => array( | ||
"title" => "First API Template", | ||
"origin_country_id" => 209, | ||
"destination_country_id" => 209, | ||
"primary_cost" => 10.0, | ||
"secondary_cost" => 10.0 | ||
)))); | ||
|
||
# Upload local files: the item value must be an array with the first value as a string starting with "@": | ||
$listing_image = array( | ||
'params' => array( | ||
'listing_id' => '152326352' | ||
), | ||
'data' => array( | ||
'image' => array('@/path/to/file.jpg;type=image/jpeg') | ||
)); | ||
print_r($api->uploadListingImage($listing_image)); | ||
|
||
``` | ||
|
||
## Asociations ## | ||
You would be able to fetch associations of given your resources using a simple interface: | ||
```php | ||
$args = array( | ||
'params' => array( | ||
'listing_id' => 654321 | ||
), | ||
// A list of associations | ||
'associations' => array( | ||
// Could be a simple association, sending something like: ?includes=Images | ||
'Images', | ||
// Or a composed one with (all are optional as Etsy API says) "scope", "limit", "offset", "select" and sub-associations ("associations") | ||
// ?includes=ShippingInfo(currency_code, primary_cost):active:1:0/DestinationCountry(name,slug) | ||
'ShippingInfo' => array( | ||
'scope' => 'active', | ||
'limit' => 1, | ||
'offset' => 0, | ||
'select' => array('currency_code', 'primary_cost'), | ||
// The only issue here is that sub-associations couldn't be more than one, I guess. | ||
'associations' => array( | ||
'DestinationCountry' => array( | ||
'select' => array('name', 'slug') | ||
) | ||
) | ||
) | ||
) | ||
); | ||
$result = $this->api->getListing($args); | ||
``` | ||
To read more about associations: https://www.etsy.com/developers/documentation/getting_started/resources#section_associations | ||
|
||
## JSON params ## | ||
There are some methods that Etsy requires to be a JSON string encoded param (ie: param "variations" for "createListingVariations"). For these cases, those params should be defined like this: | ||
```php | ||
$args = array( | ||
'params' => array( | ||
'listing_id' => 654321 | ||
), | ||
'data' => array( | ||
'variations' => array( | ||
'json' => json_encode( | ||
array( | ||
array( | ||
'property_id' => 200, | ||
'value' => "Black" | ||
), | ||
array( | ||
'property_id' => 200, | ||
'value' => "White" | ||
) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
|
||
$result = $this->api->createListingVariations($args); | ||
``` | ||
|
||
## Testing ## | ||
```bash | ||
$ vendor/bin/phpunit | ||
``` | ||
|
||
## Changelog | ||
|
||
* 1.0 | ||
* Init commit, working module. | ||
|
||
## Author | ||
|
||
**Iñaki Abete** | ||
web: http://github.com/inakiabt | ||
email: [email protected] | ||
twitter: @inakiabt | ||
|
||
|
||
## Contribute | ||
|
||
Found a bug? Want to contribute and add a new feature? | ||
|
||
Please fork this project and send me a pull request! | ||
|
||
## License | ||
|
||
mobiledevice is licensed under the MIT license: | ||
|
||
www.opensource.org/licenses/MIT |
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,25 @@ | ||
{ | ||
"name": "cedcommerce/etsy-php", | ||
"version": "1.12.1", | ||
"description": "Simple PHP wrapper for Etsy API", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Iñaki Abete" | ||
} | ||
], | ||
|
||
"require": { | ||
"php": ">=5.3.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "7.3.5", | ||
"phpunit/php-invoker": ">=2.0.0", | ||
"phpunit/php-code-coverage": "6.0.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Etsy\\": "src/Etsy/" | ||
} | ||
} | ||
} |
Oops, something went wrong.