Skip to content

Commit 0f7ddaf

Browse files
authored
Merge pull request #9 from ohmybrew/v3-dev
V3
2 parents 99b3c2c + a0c6df5 commit 0f7ddaf

File tree

11 files changed

+865
-855
lines changed

11 files changed

+865
-855
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# CHANGELOG
22

3+
# Version 3.0.0
4+
5+
*Contains breaking changes*
6+
7+
To better the library, it has been reverted back to its original single-class form and backwards compatibile with 1.x.x
8+
9+
+ GraphQL and REST are all under one class
10+
+ `getApiCalls()` now takes two arguments, first being rest|graph, second being the key
11+
+ `rest()` is now for REST calls
12+
+ `graph()` is now for GraphQL calls
13+
+ `request()` is aliased to `rest()` for backward compatibility
14+
315
# Version 2.0.0
416

517
*Contains breaking changes*

README.md

Lines changed: 46 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -17,78 +17,44 @@ The recommended way to install is [through composer](http://packagist.org).
1717

1818
## Usage
1919

20+
Add `use OhMyBrew\BasicShopifyAPI;` to your imports.
21+
2022
### Public API
2123

22-
For OAuth applications. The shop domain, API key, API secret, and an access token are required. This assumes you properly have your app setup in the partner's dashboard with the correct keys and redirect URIs.
24+
This assumes you properly have your app setup in the partner's dashboard with the correct keys and redirect URIs.
2325

24-
#### Quick run-down
26+
#### REST
2527

26-
##### REST Method
28+
For REST calls, the shop domain and access token are required.
2729

2830
```php
29-
use OhMyBrew\ShopifyAPI;
30-
31-
$api = new RestAPI;
32-
$api->setApiKey('your key here');
33-
$api->setApiSecret('your secret here');
31+
$api = new BasicShopifyAPI();
32+
$api->setShop('your shop here');
33+
$api->setAccessToken('your token here');
3434

35-
$api->setShop('example.myshopify.com');
36-
$api->setAccessToken('a token here');
37-
// or
38-
$api->setSession('example.myshopify.com', 'a token here');
39-
40-
/**
41-
* $request will return an object with keys of `response` for full Guzzle response
42-
* `body` with JSON-decoded result
43-
*/
44-
$request = $api->request('GET', '/admin/shop.json');
45-
echo $request->response->getStatusCode();
46-
echo $request->body->shop->name;
35+
// Now run your requests...
36+
$api->rest(...);
4737
```
4838

49-
##### GraphQL Method
39+
#### GraphQL
5040

51-
```php
52-
use OhMyBrew\ShopifyAPI;
41+
For GraphQL calls, the shop domain and access token are required.
5342

54-
$api = new GraphAPI;
55-
$api->setApiKey('your key here');
56-
$api->setApiSecret('your secret here');
43+
```php
44+
$api = new BasicShopifyAPI();
45+
$api->setShop('your shop here');
46+
$api->setAccessToken('your token here');
5747

58-
$api->setShop('example.myshopify.com');
59-
$api->setAccessToken('a token here');
60-
// or
61-
$api->setSession('example.myshopify.com', 'a token here');
62-
63-
/**
64-
* $request will return an object with keys of `response` for full Guzzle response
65-
* `body` with JSON-decoded result
66-
*/
67-
$query =<<<QL
68-
{
69-
shop {
70-
products(first: 2) {
71-
edges {
72-
node {
73-
id
74-
handle
75-
}
76-
}
77-
}
78-
}
79-
}
80-
QL;
81-
$request = $api->request($query);
82-
echo $request->response->getStatusCode();
83-
echo $request->body->shop->products->edges[0]->node->handle;
48+
// Now run your requests...
49+
$api->graph(...);
8450
```
8551

8652
#### Getting access token
8753

8854
After obtaining the user's shop domain, to then direct them to the auth screen use `getAuthUrl`, as example (basic PHP):
8955

9056
```php
91-
$api = new RestAPI; // or GraphAPI
57+
$api = new BasicShopifyAPI();
9258
$api->setShop($_SESSION['shop']);
9359
$api->setApiKey(env('SHOPIFY_API_KEY'));
9460

@@ -110,7 +76,7 @@ if (!$code) {
11076
$api->setAccessToken($token);
11177

11278
// You can now make API calls as well once you've set the token to `setAccessToken`
113-
$request = $api->request('GET', '/admin/shop.json');
79+
$request = $api->rest('GET', '/admin/shop.json'); // or GraphQL
11480
}
11581
```
11682

@@ -125,65 +91,43 @@ $valid = $api->verifyRequest($_GET);
12591

12692
### Private API
12793

128-
For private application calls. The shop domain, API key, and API password are required.
94+
This assumes you properly have your app setup in the partner's dashboard with the correct keys and redirect URIs.
12995

130-
#### Quick run-down
96+
#### REST
13197

132-
##### REST Method
98+
For REST calls, shop domain, API key, and API password are request
13399

134100
```php
135-
$api = new RestAPI(true); // true sets it to private
101+
$api = new BasicShopifyAPI(true); // true sets it to private
136102
$api->setShop('example.myshopify.com');
137103
$api->setApiKey('your key here');
138104
$api->setApiPassword('your password here');
139105

140-
/**
141-
* $request will return an object with keys of `response` for full Guzzle response
142-
* `body` with JSON-decoded result
143-
*/
144-
$request = $api->request('GET', '/admin/shop.json');
145-
echo $request->response->getStatusCode();
146-
echo $request->body->shop->name;
106+
// Now run your requests...
107+
$api->rest(...);
147108
```
148109

149-
##### GraphQL Method
110+
#### GraphQL
111+
112+
For GraphQL calls, shop domain and API password are required.
150113

151114
```php
152-
$api = new GraphAPI(true); // true sets it to private
115+
$api = new BasicShopifyAPI(true); // true sets it to private
153116
$api->setShop('example.myshopify.com');
154-
$api->setApiPassword('your password here'); // This is used as the access token for GraphQL
155-
156-
/**
157-
* $request will return an object with keys of `response` for full Guzzle response
158-
* `body` with JSON-decoded result
159-
*/
160-
$query =<<<QL
161-
{
162-
shop {
163-
products(first: 2) {
164-
edges {
165-
node {
166-
id
167-
handle
168-
}
169-
}
170-
}
171-
}
172-
}
173-
QL;
174-
$request = $api->request($query);
175-
echo $request->response->getStatusCode();
176-
echo $request->body->shop->products->edges[0]->node->handle;
117+
$api->setApiPassword('your password here');
118+
119+
// Now run your requests...
120+
$api->graph(...);
177121
```
178122

179123
### Making requests
180124

181-
#### REST Method
125+
#### REST
182126

183127
Requests are made using Guzzle.
184128

185129
```php
186-
$api->request(string $type, string $path, array $params = null);
130+
$api->rest(string $type, string $path, array $params = null);
187131
```
188132

189133
+ `type` refers to GET, POST, PUT, DELETE, etc
@@ -195,12 +139,14 @@ The return value for the request will be an object containing:
195139
+ `response` the full Guzzle response object
196140
+ `body` the JSON decoded response body
197141

198-
#### GraphQL Method
142+
*Note*: `request()` will alias to `rest()` as well.
143+
144+
#### GraphQL
199145

200146
Requests are made using Guzzle.
201147

202148
```php
203-
$api->request(string $query);
149+
$api->graph(string $query);
204150
```
205151

206152
+ `query` refers to the full GraphQL query
@@ -217,7 +163,7 @@ After each request is made, the API call limits are updated. To access them, sim
217163
```php
218164
// Returns an array of left, made, and limit.
219165
// Example: ['left' => 79, 'made' => 1, 'limit' => 80]
220-
$limits = $api->getApiCalls();
166+
$limits = $api->getApiCalls('rest'); // or 'graph'
221167
```
222168

223169
For GraphQL, additionally there will be the following values: `restoreRate`, `requestedCost`, `actualCost`.
@@ -227,9 +173,9 @@ To quickly get a value, you may pass an optional parameter to the `getApiCalls`
227173
```php
228174
// As example, this will return 79
229175
// You may pass 'left', 'made', or 'limit'
230-
$left = $api->getApiCalls('left'); // returns 79
176+
$left = $api->getApiCalls('graph', 'left'); // returns 79
231177
// or
232-
$left = $api->getApiCalls()['left']; // returns 79
178+
$left = $api->getApiCalls('graph')['left']; // returns 79
233179
```
234180

235181
### Isolated API calls
@@ -247,17 +193,17 @@ $api->withSession(string $shop, string $accessToken, Closure $closure);
247193
`$this` will be binded to the current API. Example:
248194

249195
```php
250-
$api = new RestAPI(true);
196+
$api = new BasicShopifyAPI(true);
251197
$api->setApiKey('your key here');
252198
$api->setApiPassword('your password here');
253199

254200
$api->withSession('some-shop.myshopify.com', 'token from database?', function() {
255-
$request = $this->request('GET', '/admin/shop.json');
201+
$request = $this->rest('GET', '/admin/shop.json');
256202
echo $request->body->shop->name; // Some Shop
257203
});
258204

259205
$api->withSession('some-shop-two.myshopify.com', 'token from database?', function() {
260-
$request = $this->request('GET', '/admin/shop.json');
206+
$request = $this->rest('GET', '/admin/shop.json');
261207
echo $request->body->shop->name; // Some Shop Two
262208
});
263209
```

UPGRADING.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
# Upgrading
22

3-
# v1.x.x -> v2.0.0
3+
# v1.x.x -> v3.0.0
44

5-
Library is no longer a single class. It now has a namespace with several classes.
5+
+ `getApiCalls()` now takes two arguments, first being rest|graph, second being the key
66

77
Old:
88

99
```php
10-
use OhMyBrew\BasicShopifyAPI;
11-
12-
$api = new BasicShopifyAPI(...);
10+
getApiCalls('left');
1311
```
1412

1513
New:
1614

1715
```php
18-
19-
use OhMyBrew\ShopifyAPI;
20-
21-
$api = new RestAPI(...);
16+
getApiCalls('rest', 'left');
2217
```
2318

24-
A GraphQL API class is now also included, use `GraphAPI`.
19+
+ `request()` still exists, and is aliased to `rest()` but encourage you to move all REST calls to the new `rest()` method name

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"squizlabs/php_codesniffer": "^3.0"
2222
},
2323
"autoload": {
24-
"psr-4": { "OhMyBrew\\ShopifyAPI\\": "src/OhMyBrew/ShopifyAPI/" }
24+
"files": ["src/OhMyBrew/BasicShopifyAPI.php"]
2525
},
2626
"config": { "bin-dir": "bin" }
2727
}

0 commit comments

Comments
 (0)