Skip to content

Commit

Permalink
Merge pull request #11 from RRStoyanov/master
Browse files Browse the repository at this point in the history
Collect response headers and method to check current limit
  • Loading branch information
BNMetrics authored Mar 19, 2018
2 parents 3654cb2 + 873e367 commit e3f2e08
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,19 @@ public function __call($name, $args = null)
else return $this->{$currAction}($endpoint, $params);
}

/**
* @return \BNMetrics\Shopify\ShopifyAuth
*/
public function getShopifyAuth(): \BNMetrics\Shopify\ShopifyAuth
{
return $this->shopifyAuth;
}

/**
* @param \BNMetrics\Shopify\ShopifyAuth $shopifyAuth
*/
public function setShopifyAuth(\BNMetrics\Shopify\ShopifyAuth $shopifyAuth): void
{
$this->shopifyAuth = $shopifyAuth;
}
}
17 changes: 17 additions & 0 deletions src/ShopifyAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ShopifyAuth extends AbstractProvider

protected $requestPath;

protected $responseHeaders;

/**
* Set the myshopify domain URL for the API request.
* eg. example.myshopify.com
Expand Down Expand Up @@ -86,6 +88,8 @@ protected function getUserByToken($token)

$user = json_decode($response->getBody(), true);

$this->responseHeaders = $response->getHeaders();

return $user['shop'];
}

Expand All @@ -106,6 +110,19 @@ protected function mapUserToObject(array $user)
]);
}

/**
* Return current shopify api limit - 1 is lower
*
* @return int
*/
public function checkCurrentApiLimit(): int
{
$limit = $this->responseHeaders['X-Shopify-Shop-Api-Call-Limit'] ??
$this->responseHeaders['HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT'] ?? ['1/40'];

return (int)explode('/', $limit[0])[0];
}


/**
* this method is for when you need to make an embedded shopify app
Expand Down

0 comments on commit e3f2e08

Please sign in to comment.