diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index ebab69d..639d0d0 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor test.php -test/coveraget \ No newline at end of file +test/coveraget +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index e7e9d11..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 492fd3e..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml deleted file mode 100644 index b70695f..0000000 --- a/.idea/php-test-framework.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index c854783..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml deleted file mode 100644 index 4ea9753..0000000 --- a/.idea/phpunit.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/shopify-api-php-sdk.iml b/.idea/shopify-api-php-sdk.iml deleted file mode 100644 index 3cf9ed4..0000000 --- a/.idea/shopify-api-php-sdk.iml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.phpunit.result.cache b/.phpunit.result.cache old mode 100644 new mode 100755 diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 diff --git a/phpunit.xml b/phpunit.xml old mode 100644 new mode 100755 diff --git a/src/Client.php b/src/Client.php index c913cd1..e44a71f 100755 --- a/src/Client.php +++ b/src/Client.php @@ -1,7 +1,9 @@ request($method,$url,$options); if (strtoupper($method) === 'GET' && $http_response->getHeaderLine(self::PAGINATION_STRING)) { $this->next_page = $this->parseLinkString($http_response->getHeaderLine(self::PAGINATION_STRING),'next'); @@ -188,27 +211,30 @@ public function call($method, $path , array $params = []) /** * Prepare data for graphql api request + * * @param string $url * @return string * */ - public function apiScopeUrl($url){ + public function apiScopeUrl($url) + { return str_replace('api/'.$this->getApiVersion().'/', 'oauth/', $url); } /** - * prepare data for graphql api request + * Prepare data for graphql api request + * * @param string $query - * @return mixed|void + * @return mixed * @throws ApiException - * @throws ClientException + * @throws GuzzleException */ public function callGraphql($query) { $url = $this->getGraphqlApiUrl(); $options = []; - if(is_array($this->getRestApiHeaders()) && count($this->getRestApiHeaders())) { - $options['headers'] = $this->getRestApiHeaders(); + if(is_array($this->getGraphqlApiHeaders()) && count($this->getGraphqlApiHeaders())) { + $options['headers'] = $this->getGraphqlApiHeaders(); } $options['body'] = $query; $http_response = $this->request('POST', $url, $options); @@ -227,12 +253,13 @@ public function callGraphql($query) } /** - * send http request + * Send http request + * * @param string $method * @param string $url * @param array $options - * @return array|mixed - * @throws ApiException + * @return ResponseInterface + * @throws ApiException|GuzzleException */ public function request($method,$url,array $options) { @@ -244,22 +271,16 @@ public function request($method,$url,array $options) catch (RequestException $e) { $json_error = json_decode($e->getResponse()->getBody()->getContents(),true); - if (isset($json_error['errors'])) { - $error_message = $json_error['errors']; - } - else { - $error_message = $e->getMessage(); - } - + $error_message = $json_error['errors'] ?? $e->getMessage(); if(is_array($error_message)) $error_message = json_encode($error_message); - throw new ApiException($error_message,$e->getCode()); } } /** - * get previous page_info for any resource(products/orders) + * Get previous page_info for any resource(products/orders) + * * @return string */ public function getPrevPage() @@ -268,8 +289,9 @@ public function getPrevPage() } /** - * check previous page_info for any resource(products/orders) - * @return string + * Check previous page_info for any resource(products/orders) + * + * @return bool */ public function hasPrevPage() { @@ -277,23 +299,28 @@ public function hasPrevPage() } /** - * get next page_info for any resource(products/orders) + * Get next page_info for any resource(products/orders) + * * @return string */ - public function getNextPage(){ + public function getNextPage() + { return $this->next_page; } /** - * check next page_info for any resource(products/orders) - * @return string + * Check next page_info for any resource(products/orders) + * + * @return bool */ - public function hasNextPage(){ + public function hasNextPage() + { return !empty($this->next_page); } /** - * parse header string for previous and next page_info + * Parse header string for previous and next page_info + * * @param $pagination_string * @param $page_link * @return string @@ -306,7 +333,8 @@ public function parseLinkString($pagination_string,$page_link) } /** - * return allowed http api methods + * Return allowed http api methods + * * @return array */ public function getHttpMethods() @@ -315,7 +343,8 @@ public function getHttpMethods() } /** - * set shopify domain + * Set shopify domain + * * @param $shop * Exception for invalid shop name * @throws ApiException @@ -331,7 +360,8 @@ public function setShop($shop) } /** - * return latest api version + * Return latest api version + * * @return string */ public function getApiVersion() @@ -340,7 +370,8 @@ public function getApiVersion() } /** - * set api version + * Set api version + * * @param api_version * Exception for valid value * @throws ApiException @@ -355,7 +386,8 @@ public function setApiVersion($ap_params) } /** - * return Shopify domain + * Return Shopify domain + * * @return string */ public function getShop() @@ -364,7 +396,22 @@ public function getShop() } /** - * set rest api url + * Set new graphql api url for storefront API + * + * @param array + */ + public function setStoreFrontApi($api_params) + { + // Change graphql url and api_type for Storefront API + if (isset($api_params['api_type']) && $api_params['api_type'] == 'storefront') { + $this->graphql_api_url = 'https://{shopify_domain}/api/{version}/graphql.json'; + $this->api_type = 'storefront'; + } + } + + /** + * Set rest api url + * * @param $rest_api_url * @param $app_type */ @@ -387,15 +434,18 @@ public function setRestApiUrl($rest_api_url, $app_type = '') } /** - * get rest api url app + * Get rest api url app + * * @return string */ - public function getRestApiUrl(){ + public function getRestApiUrl() + { return $this->rest_api_url; } /** - * set graphql api url + * Set graphql api url + * * @param $graphql_api_url */ public function setGraphqlApiUrl($graphql_api_url) @@ -406,18 +456,22 @@ public function setGraphqlApiUrl($graphql_api_url) } /** - * get graphql api url + * Get graphql api url + * * @return string */ - public function getGraphqlApiUrl(){ + public function getGraphqlApiUrl() + { return $this->graphql_api_url; } /** - * set rest api headers - * @return string + * Set rest api headers + * + * @return void */ - public function setRestApiHeaders($access_token = ''){ + public function setRestApiHeaders($access_token = '') + { $this->restApiRequestHeaders['Content-Type'] = "application/json"; if($access_token){ $this->restApiRequestHeaders[self::SHOPIFY_ACCESS_TOKEN] = $this->access_token; @@ -426,93 +480,119 @@ public function setRestApiHeaders($access_token = ''){ /** - * get rest api headers + * Get rest api headers + * * @return array */ - public function getRestApiHeaders(){ + public function getRestApiHeaders() + { return $this->restApiRequestHeaders; } /** - * get graphql api url - * @return string + * Get graphql api url + * + * @param $access_token */ - public function setGraphqlApiHeaders($access_token){ + public function setGraphqlApiHeaders($access_token) + { $this->graphqlApiRequestHeaders['Content-Type'] = "application/graphql"; $this->graphqlApiRequestHeaders['X-GraphQL-Cost-Include-Fields'] = true; - $this->graphqlApiRequestHeaders[self::SHOPIFY_ACCESS_TOKEN] = $access_token; + + // Set api token header according to api type either admin or storefront API + $token_header = $this->api_type == 'storefront' ? self::SHOPIFY_STOREFRONT_ACCESS_TOKEN + : self::SHOPIFY_ACCESS_TOKEN; + $this->graphqlApiRequestHeaders[$token_header] = $access_token; } /** - * get graphql api url - * @return string + * Get graphql api url + * + * @return array */ - public function getGraphqlApiHeaders(){ + public function getGraphqlApiHeaders() + { return $this->graphqlApiRequestHeaders; } /** - * set api_key of public or private app - * @param $api_key + * Set api_key of public or private app + * + * @param $api_key */ - public function setApiKey($api_key){ + public function setApiKey($api_key) + { $this->api_key = $api_key; } /** - * get api_key of public or private app + * Get api_key of public or private app + * * @return string */ - public function getApiKey(){ + public function getApiKey() + { return $this->api_key; } /** - * set api_key of public or private app - * @param $api_password + * Set api_key of public or private app + * + * @param $api_password */ - public function setApiPassword($api_password){ + public function setApiPassword($api_password) + { $this->password = $api_password; } /** - * get api_password of private app + * Get api_password of private app + * * @return string */ - public function getApiPassword(){ + public function getApiPassword() + { return $this->password; } /** - * set api secret key for public app + * Set api secret key for public app + * * @param $api_secret_key */ - public function setApiSecretKey($api_secret_key){ + public function setApiSecretKey($api_secret_key) + { $this->api_secret_key = $api_secret_key; } /** - * get api secret key for public app + * Get api secret key for public app + * * @return string */ - public function getApiSecretKey(){ + public function getApiSecretKey() + { return $this->api_secret_key; } /** - * set api_params of public or private app + * Set api_params of public or private app + * * @param $api_params */ - public function setApiParams($api_params){ + public function setApiParams($api_params) + { $this->api_params = $api_params; } /** - * get api_params of public or private app + * Get api_params of public or private app + * * @return string */ - public function getApiParams(){ + public function getApiParams() + { return $this->api_params; } } diff --git a/src/Common/AppInterface.php b/src/Common/AppInterface.php old mode 100644 new mode 100755 diff --git a/src/PrivateApp.php b/src/PrivateApp.php index 66493e9..c45478e 100755 --- a/src/PrivateApp.php +++ b/src/PrivateApp.php @@ -10,14 +10,15 @@ class PrivateApp extends Client implements AppInterface { /** - * Shopify rest base url + * Shopify rest API base url * @var string */ protected $rest_api_url = 'https://{api_key}:{password}@{shopify_domain}/admin/api/{version}/{resource}.json'; /** - * PrivateApp constructor. - * Shopify url : testshop.myshopify.com + * Initialize shop, API details with version for private APP + * + * Shopify url : test-shop.myshopify.com * @param $shop * Shopify api key of private app * @param $api_key @@ -33,6 +34,7 @@ public function __construct($shop, $api_key, $password, array $api_params = []) $this->api_key = $api_key; $this->password = $password; $this->api_params = $api_params; + $this->setStoreFrontApi($this->api_params); $this->setApiVersion($this->api_params); $this->setGraphqlApiUrl($this->graphql_api_url); $this->setRestApiUrl($this->rest_api_url, self::PRIVATE_APP); diff --git a/src/PublicApp.php b/src/PublicApp.php index 93ab713..7434414 100755 --- a/src/PublicApp.php +++ b/src/PublicApp.php @@ -1,6 +1,7 @@ testshop.myshopify.com * @param $shop * Shopify api key @@ -51,7 +55,8 @@ public function __construct($shop, $api_key, $api_secret_key, array $api_params } /** - * assign access token for api call + * Assign access token for api call + * * @param $access_token */ public function setAccessToken($access_token) @@ -63,10 +68,11 @@ public function setAccessToken($access_token) /** * Once the User has authorized the app, call to get the access token + * * @param $get_params - * @return mixed + * @return mixed|void * @throws ApiException - * @throws ClientException + * @throws GuzzleException */ public function getAccessToken($get_params) { @@ -96,11 +102,12 @@ public function getAccessToken($get_params) } /** - * prepare url to authorize public app with Oauth for given shop domain + * Prepare url to authorize public app with Oauth for given shop domain + * * @param $scope * @param null $redirect_url * @param $state - * @return false|string + * @return string */ public function prepareAuthorizeUrl($redirect_url='', $scope='', $state=false) { @@ -123,7 +130,8 @@ public function prepareAuthorizeUrl($redirect_url='', $scope='', $state=false) } /** - * set random unique value for authorization request + * Set random unique value for authorization request + * * @param $state */ public function setState($state) @@ -132,7 +140,8 @@ public function setState($state) } /** - * get random unique value for authorization request + * Get random unique value for authorization request + * * @return string */ public function getState() @@ -142,6 +151,7 @@ public function getState() /** * HMAC verification procedure for OAuth/webhooks + * * @param $data * @param $hmac * @return bool @@ -157,8 +167,9 @@ public function validateHmac($data, $hmac) } /** - * check random value same with previous value set for authorization request - * @param $state + * Check random value same with previous value set for authorization request + * + * @param $params * @return bool */ public function validateState($params) diff --git a/test/coverage/.css/bootstrap.min.css b/test/coverage/.css/bootstrap.min.css old mode 100644 new mode 100755 diff --git a/test/coverage/.css/nv.d3.min.css b/test/coverage/.css/nv.d3.min.css old mode 100644 new mode 100755 diff --git a/test/coverage/.css/style.css b/test/coverage/.css/style.css old mode 100644 new mode 100755 diff --git a/test/coverage/.fonts/glyphicons-halflings-regular.eot b/test/coverage/.fonts/glyphicons-halflings-regular.eot old mode 100644 new mode 100755 diff --git a/test/coverage/.fonts/glyphicons-halflings-regular.svg b/test/coverage/.fonts/glyphicons-halflings-regular.svg old mode 100644 new mode 100755 diff --git a/test/coverage/.fonts/glyphicons-halflings-regular.ttf b/test/coverage/.fonts/glyphicons-halflings-regular.ttf old mode 100644 new mode 100755 diff --git a/test/coverage/.fonts/glyphicons-halflings-regular.woff b/test/coverage/.fonts/glyphicons-halflings-regular.woff old mode 100644 new mode 100755 diff --git a/test/coverage/.fonts/glyphicons-halflings-regular.woff2 b/test/coverage/.fonts/glyphicons-halflings-regular.woff2 old mode 100644 new mode 100755 diff --git a/test/coverage/.js/bootstrap.min.js b/test/coverage/.js/bootstrap.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/d3.min.js b/test/coverage/.js/d3.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/file.js b/test/coverage/.js/file.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/holder.min.js b/test/coverage/.js/holder.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/html5shiv.min.js b/test/coverage/.js/html5shiv.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/jquery.min.js b/test/coverage/.js/jquery.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/nv.d3.min.js b/test/coverage/.js/nv.d3.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/.js/respond.min.js b/test/coverage/.js/respond.min.js old mode 100644 new mode 100755 diff --git a/test/coverage/Client.php.html b/test/coverage/Client.php.html old mode 100644 new mode 100755 diff --git a/test/coverage/Common/AppInterface.php.html b/test/coverage/Common/AppInterface.php.html old mode 100644 new mode 100755 diff --git a/test/coverage/Common/ClientInterface.php.html b/test/coverage/Common/ClientInterface.php.html old mode 100644 new mode 100755 diff --git a/test/coverage/Common/dashboard.html b/test/coverage/Common/dashboard.html old mode 100644 new mode 100755 diff --git a/test/coverage/Common/index.html b/test/coverage/Common/index.html old mode 100644 new mode 100755 diff --git a/test/coverage/Exception/ApiException.php.html b/test/coverage/Exception/ApiException.php.html old mode 100644 new mode 100755 diff --git a/test/coverage/Exception/dashboard.html b/test/coverage/Exception/dashboard.html old mode 100644 new mode 100755 diff --git a/test/coverage/Exception/index.html b/test/coverage/Exception/index.html old mode 100644 new mode 100755 diff --git a/test/coverage/PrivateApp.php.html b/test/coverage/PrivateApp.php.html old mode 100644 new mode 100755 diff --git a/test/coverage/PublicApp.php.html b/test/coverage/PublicApp.php.html old mode 100644 new mode 100755 diff --git a/test/coverage/dashboard.html b/test/coverage/dashboard.html old mode 100644 new mode 100755 diff --git a/test/coverage/index.html b/test/coverage/index.html old mode 100644 new mode 100755