You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGELOG.md
+1-9
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,7 @@
2
2
3
3
## v1.0
4
4
### 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.
Copy file name to clipboardexpand all lines: README.md
+110-21
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,29 @@
1
1
# Etsy PHP SDK
2
2
A PHP SDK for the Etsy API v3.
3
3
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.
5
7
6
8
## Requirements
7
-
PHP 7.1 or greater.
9
+
PHP 8 or greater.
8
10
9
11
## Install
10
12
Install the package using composer.
11
13
```php
12
14
composer require rhysnhall/etsy-php-sdk
13
15
```
14
16
15
-
Include the OAuth client and Etsy class.
17
+
Include the Etsy class.
16
18
```php
17
19
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.
19
27
```
20
28
21
29
## Usage
@@ -25,7 +33,7 @@ The Etsy API uses OAuth 2.0 authentication. You can read more about authenticati
25
33
26
34
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).
27
35
```php
28
-
$client = new Etsy\OAuth\Client($api_key);
36
+
$client = new Etsy\OAuth\Client($client_id);
29
37
```
30
38
31
39
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
89
97
90
98
#### Refreshing your token
91
99
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.
@@ -107,37 +115,118 @@ This will provide you with a brand new set of OAuth2 access and refresh tokens.
107
115
108
116
### Basic use
109
117
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
+
```
111
139
140
+
Resources contain the API response from Etsy as properties.
112
141
```php
113
-
$etsy = new Etsy\Etsy($api_key, $access_token);
142
+
$listingTitle = $listing->title;
143
+
```
114
144
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
+
```
117
150
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
+
```
120
156
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();
125
161
```
126
162
127
-
######Collections
163
+
#### Collections
128
164
When there is more than one result a collection will be returned.
129
165
```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
+
```
131
173
132
-
// Get first review.
133
-
$first = $reviews->first();
174
+
Collections contain a handful of useful methods.
134
175
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
135
197
// Get 100 results using pagination.
136
-
foreach($reviews->paginate(100) as $review) {
198
+
foreach($reviews->paginate(200) as $review) {
137
199
...
138
200
}
139
201
```
140
202
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
+
141
230
---
142
231
143
232
Full documentation will be available soon. Email [hello@rhyshall.com](mailto:hello@rhyshall.com) for any assistance.
0 commit comments