Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Update to allow for basic rate limiting through BasicShopifyAPI's new…
Browse files Browse the repository at this point in the history
… built-in feature
  • Loading branch information
gnikyt committed Nov 2, 2018
1 parent 98d5c6f commit 04403bb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"require": {
"php": ">=7.1.0",
"laravel/framework": "~5.5",
"ohmybrew/basic-shopify-api": "~3.0",
"ohmybrew/basic-shopify-api": "~4.0",
"doctrine/dbal": "~2.5"
},
"require-dev":{
Expand Down
7 changes: 7 additions & 0 deletions src/ShopifyApp/ShopifyApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public function api()
$api->setApiKey(config('shopify-app.api_key'));
$api->setApiSecret(config('shopify-app.api_secret'));

if (config('shopify-app.api_rate_limiting_enabled') === true) {
$api->enableRateLimiting(
config('shopify-app.api_rate_limit_cycle'),
config('shopify-app.api_rate_limit_cycle_buffer')
);
}

return $api;
}

Expand Down
42 changes: 42 additions & 0 deletions src/ShopifyApp/resources/config/shopify-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,48 @@

'api_class' => env('SHOPIFY_API_CLASS', \OhMyBrew\BasicShopifyAPI::class),

/*
|--------------------------------------------------------------------------
| Shopify API Rate Limiting
|--------------------------------------------------------------------------
|
| This option option allows you to enable basic rate limiting
| for API calls using the default BasicShopifyAPI library.
| Default is off.
|
*/

'api_rate_limiting_enabled' => env('SHOPIFY_API_RATE_LIMITING_ENABLED', false),

/*
|--------------------------------------------------------------------------
| Shopify API Rate Limit Cycle
|--------------------------------------------------------------------------
|
| This option option allows you to set the millisecond cycle for
| API calls using the default BasicShopifyAPI library.
| Default is 500ms per API call.
| Example: 0.5 * 1000
|
*/

'api_rate_limit_cycle' => env('SHOPIFY_API_RATE_LIMIT_CYCLE', null),

/*
|--------------------------------------------------------------------------
| Shopify API Rate Limit Cycle Buffer
|--------------------------------------------------------------------------
|
| This option option allows you to set the millisecond buffer for
| API calls using the default BasicShopifyAPI library which gets
| appended to the `api_rate_limit_cycle` value for a safety net.
| Default is 100ms per API call.
| Example: 0.1 * 1000
|
*/

'api_rate_limit_cycle_buffer' => env('SHOPIFY_API_RATE_LIMIT_CYCLE_BUFFER', null),

/*
|--------------------------------------------------------------------------
| Shopify "MyShopify" domain
Expand Down
7 changes: 7 additions & 0 deletions tests/ShopifyAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public function testReturnsApiInstance()
$this->assertEquals(\OhMyBrew\BasicShopifyAPI::class, get_class($this->shopifyApp->api()));
}

public function testReturnsApiInstanceWithRateLimiting()
{
config(['shopify-app.api_rate_limiting_enabled' => true]);

$this->assertTrue($this->shopifyApp->api()->isRateLimitingEnabled());
}

public function testShopSanitize()
{
$domains = ['my-shop', 'my-shop.myshopify.com', 'https://my-shop.myshopify.com', 'http://my-shop.myshopify.com'];
Expand Down

0 comments on commit 04403bb

Please sign in to comment.