1
1
<?php
2
+
2
3
namespace LaravelShipStation ;
3
4
4
5
use GuzzleHttp \Client ;
@@ -31,7 +32,7 @@ class ShipStation
31
32
'/stores/ ' ,
32
33
'/users/ ' ,
33
34
'/warehouses/ ' ,
34
- '/webhooks/ '
35
+ '/webhooks/ ' ,
35
36
];
36
37
37
38
/**
@@ -59,14 +60,14 @@ class ShipStation
59
60
*/
60
61
public function __construct ($ apiKey , $ apiSecret , $ apiURL , $ partnerApiKey = null )
61
62
{
62
- if (!isset ($ apiKey , $ apiSecret )) {
63
+ if (! isset ($ apiKey , $ apiSecret )) {
63
64
throw new \Exception ('Your API key and/or private key are not set. Did you run artisan vendor:publish? ' );
64
65
}
65
66
66
67
$ this ->base_uri = $ apiURL ;
67
68
68
69
$ headers = [
69
- 'Authorization ' => 'Basic ' . base64_encode ("{$ apiKey }: {$ apiSecret }" ),
70
+ 'Authorization ' => 'Basic ' . base64_encode ("{$ apiKey }: {$ apiSecret }" ),
70
71
];
71
72
72
73
if (! empty ($ partnerApiKey )) {
@@ -143,7 +144,7 @@ public function update($options = [], $endpoint = '')
143
144
}
144
145
145
146
/**
146
- * Get the maximum number of requests that can be sent per window
147
+ * Get the maximum number of requests that can be sent per window.
147
148
*
148
149
* @return int
149
150
*/
@@ -153,7 +154,7 @@ public function getMaxAllowedRequests()
153
154
}
154
155
155
156
/**
156
- * Get the remaining number of requests that can be sent in the current window
157
+ * Get the remaining number of requests that can be sent in the current window.
157
158
*
158
159
* @return int
159
160
*/
@@ -163,7 +164,7 @@ public function getRemainingRequests()
163
164
}
164
165
165
166
/**
166
- * Get the number of seconds remaining until the next window begins
167
+ * Get the number of seconds remaining until the next window begins.
167
168
*
168
169
* @return int
169
170
*/
@@ -174,7 +175,7 @@ public function getSecondsUntilReset()
174
175
175
176
/**
176
177
* Are we currently rate limited?
177
- * We are if there are no more requests allowed in the current window
178
+ * We are if there are no more requests allowed in the current window.
178
179
*
179
180
* @return bool
180
181
*/
@@ -195,7 +196,7 @@ public function sleepIfRateLimited(Response $response)
195
196
$ this ->secondsUntilReset = (int ) $ response ->getHeader ('X-Rate-Limit-Reset ' )[0 ];
196
197
197
198
if ($ this ->isRateLimited () || ($ this ->secondsUntilReset / $ this ->remainingRequests ) > 1.5 ) {
198
- sleep ( 1.5 );
199
+ usleep ( 1500000 );
199
200
}
200
201
}
201
202
@@ -207,11 +208,11 @@ public function sleepIfRateLimited(Response $response)
207
208
*/
208
209
public function __get ($ property )
209
210
{
210
- if (in_array ('/ ' . $ property . '/ ' , $ this ->endpoints )) {
211
- $ this ->endpoint = '/ ' . $ property . '/ ' ;
211
+ if (in_array ('/ ' . $ property. '/ ' , $ this ->endpoints )) {
212
+ $ this ->endpoint = '/ ' . $ property. '/ ' ;
212
213
}
213
214
214
- $ className = " LaravelShipStation \\Helpers \\" . ucfirst ($ property );
215
+ $ className = ' LaravelShipStation \\Helpers \\' . ucfirst ($ property );
215
216
216
217
if (class_exists ($ className )) {
217
218
return new $ className ($ this );
0 commit comments