Skip to content

Commit d1aa0d6

Browse files
committed
v1.0
1 parent f667bfc commit d1aa0d6

40 files changed

+2854
-967
lines changed

CHANGELOG.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22

33
## v1.0
44
### Changes
5-
* Added `$date_from` and `$date_to` params to the `Shop::getLedgerEntries` method. These params expect either a unix timestamp or an instance of DateTime. If left empty or set to false they will default to the past 7 days.
6-
* Added `linkFile` method to the Listing resource. Removed support for linking a file from the `uploadFile` method.
7-
* Added `linkImage` method to the Listing resource. Removed support for linking an image from the `uploadImage` method.
8-
* Added `$file`, `$name` and `$rank` params to the `Listing::uploadFile` method. Removed the `$data` param.
9-
* Added `$file`, `$name`, `$rank` and `$options` params to the `Listing::uploadImage` method. Removed the `$data` param.
10-
* Removed the `Listing::updateInventory` method. This has been replaced with `ListingInventory::update`.
11-
12-
### Fixed issues
13-
* UploadFile request was throwing an exception if 'image' parameter was missing. This check has been removed.
5+
* Everything. Unfortunately, this is a breaking update.
146

157
## v0.3.2
168
### Fixed issues

README.md

+110-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# Etsy PHP SDK
22
A PHP SDK for the Etsy API v3.
33

4-
This package is still in development.
4+
**Major update on the 13th July 2024. This fixed all major issues and adds resources for recent additions to the API. If you are upgrading from a version prior to this - consider the whole thing to be breaking. There is no upgrade path and you will need to review all your code.**
5+
6+
Proper documentation still to come. Want to write it for me? I'll buy you an iced latte.
57

68
## Requirements
7-
PHP 7.1 or greater.
9+
PHP 8 or greater.
810

911
## Install
1012
Install the package using composer.
1113
```php
1214
composer require rhysnhall/etsy-php-sdk
1315
```
1416

15-
Include the OAuth client and Etsy class.
17+
Include the Etsy class.
1618
```php
1719
use Etsy\Etsy;
18-
use Etsy\OAuth\Client;
20+
21+
$etsy = new Etsy(
22+
$client_id,
23+
$access_token
24+
);
25+
26+
// Do the Etsy things.
1927
```
2028

2129
## Usage
@@ -25,7 +33,7 @@ The Etsy API uses OAuth 2.0 authentication. You can read more about authenticati
2533

2634
The first step in OAuth2 is to request an OAuth token. You will need an existing App API key which you can obtained by registering an app [here](https://www.etsy.com/developers/register).
2735
```php
28-
$client = new Etsy\OAuth\Client($api_key);
36+
$client = new Etsy\OAuth\Client($client_id);
2937
```
3038

3139
Generate a URL to redirect the user to authorize access to your app.
@@ -89,7 +97,7 @@ You'll be provided with both an access token and a refresh token. The access tok
8997

9098
#### Refreshing your token
9199

92-
You can refresh your authorization token using the refresh token that was previously provided. This will provide you with a new valid access token and another refresh token.
100+
You can refresh your authorization token (even after it has expired) using the refresh token that was previously provided. This will provide you with a new valid access token and another refresh token.
93101

94102
```php
95103
[$access_token, $refresh_token] = $client->refreshAccessToken($refresh_token);
@@ -107,37 +115,118 @@ This will provide you with a brand new set of OAuth2 access and refresh tokens.
107115

108116
### Basic use
109117

110-
Create a new instance of the Etsy class using your App API key and a user's access token.
118+
Create a new instance of the Etsy class using your App API key and a user's access token. **You must always initialize the Etsy resource before calling any resources**.
119+
120+
```php
121+
use Etsy\Etsy;
122+
use Etsy\Resources\User;
123+
124+
$etsy = new Etsy($apiKey, $accessToken);
125+
126+
// Get the authenticated user.
127+
$user = User::me();
128+
129+
// Get the users shop.
130+
$shop = $user->shop();
131+
```
132+
133+
#### Resources
134+
Most calls will return a `Resource`. Resources contain a number of methods that streamline your interaction with the Etsy API.
135+
```php
136+
// Get a Listing Resource
137+
$listing = \Etsy\Resources\Listing::get($shopId);
138+
```
111139

140+
Resources contain the API response from Etsy as properties.
112141
```php
113-
$etsy = new Etsy\Etsy($api_key, $access_token);
142+
$listingTitle = $listing->title;
143+
```
114144

115-
// Get user.
116-
$user = $etsy->getUser();
145+
##### Associations
146+
Resources will return associations as their respective Resource when appropriate. For example the bellow call will return the `shop` property as an instance of `Etsy\Resources\Shop`.
147+
```php
148+
$shop = $listing->shop;
149+
```
117150

118-
// Get shop.
119-
$shop = $user->getShop();
151+
##### `toJson`
152+
The `toJson` method will return the Resource as a JSON encoded object.
153+
```php
154+
$json = $listing->toJson();
155+
```
120156

121-
// Update shop.
122-
$shop->update([
123-
'title' => 'My exciting shop!'
124-
]);
157+
##### `toArray`
158+
The `toArray` method will return the Resource as an array.
159+
```php
160+
$array = $listing->toArray();
125161
```
126162

127-
###### Collections
163+
#### Collections
128164
When there is more than one result a collection will be returned.
129165
```php
130-
$reviews = $shop->getReviews();
166+
$reviews = Review::all();
167+
```
168+
169+
Results are stored as an array of `Resource` the `data` property of the collection.
170+
```php
171+
$firstReview = $reviews->data[0];
172+
```
131173

132-
// Get first review.
133-
$first = $reviews->first();
174+
Collections contain a handful of useful methods.
134175

176+
##### `first`
177+
Get the first item in the collection.
178+
```php
179+
$firstReview = $reviews->first();
180+
```
181+
182+
##### `count`
183+
Get the number of results in the collection. Not be confused with the `count` property which displays the number of results in a full Etsy resource.
184+
```php
185+
$count = $reviews->count();
186+
```
187+
188+
##### `append`
189+
Append a property to each item in the collection.
190+
```php
191+
$reviews->append(['shop_id' => $shopId]);
192+
```
193+
194+
##### `paginate`
195+
Most Etsy methods are capped at 100 results per call. You can use the `paginate` method to get more results than this (up to 500 results).
196+
```php
135197
// Get 100 results using pagination.
136-
foreach($reviews->paginate(100) as $review) {
198+
foreach($reviews->paginate(200) as $review) {
137199
...
138200
}
139201
```
140202

203+
##### `toJson`
204+
Returns the items in the collection as an array of JSON strings.
205+
```php
206+
$jsonArray = $reviews->toJson();
207+
```
208+
209+
#### Direct Requests
210+
You can make direct requests to the Etsy API using the static `$client` property of the Etsy class.
211+
212+
```php
213+
$response = Etsy::$client->get(
214+
"/application/listings/active",
215+
[
216+
"limit" => 25
217+
]
218+
);
219+
```
220+
221+
If you still want to use the Resources classes you can convert the response into a Resource.
222+
223+
```php
224+
$listings = Etsy::getResource(
225+
$response,
226+
'Listing'
227+
);
228+
```
229+
141230
---
142231

143232
Full documentation will be available soon. Email [hello@rhyshall.com](mailto:hello@rhyshall.com) for any assistance.

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rhysnhall/etsy-php-sdk",
3-
"version": "0.3.2",
3+
"version": "1.0",
44
"description": "PHP SDK for Etsy API v3.",
55
"type": "library",
66
"keywords": [
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=7.1",
21+
"php": "^8.0",
2222
"guzzlehttp/guzzle": "^7.3"
2323
},
2424
"autoload": {

src/Collection.php

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Collection {
3737
*/
3838
protected $_append = [];
3939

40+
/**
41+
* @var int
42+
*/
43+
public $count = 0;
44+
4045
/**
4146
* @var array
4247
*/

0 commit comments

Comments
 (0)