Class: ShopifyCLI::Theme::ThemeAccessAPI
- Defined in:
- lib/shopify_cli/theme/theme_access_api.rb
Overview
ShopifyCLI::ThemeAccessAPI is a wrapper to use Shopify Theme Access API, which allows using passwords generated from Shopify Theme Access app to access the Shopify Admin API (for theme operations)
Constant Summary collapse
- BASE_URL =
"theme-kit-access.shopifyapps.com"
Class Method Summary collapse
- .get_shop_or_abort(ctx) ⇒ Object
-
.rest_request(ctx, shop:, path:, query: nil, body: nil, method: "GET", api_version: "unstable") ⇒ Object
#### Parameters - ‘ctx`: running context from your command - `shop`: shop domain string for shop whose admin you are calling - `path`: path string (excluding prefixes and API version) for specific JSON that you are requesting ex.
Instance Method Summary collapse
Methods inherited from API
Class Method Details
.get_shop_or_abort(ctx) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/shopify_cli/theme/theme_access_api.rb', line 49 def get_shop_or_abort(ctx) env_store = Environment.store return env_store unless env_store.nil? ctx.abort( ctx.("core.api.error.theme_access_no_store") ) end |
.rest_request(ctx, shop:, path:, query: nil, body: nil, method: "GET", api_version: "unstable") ⇒ Object
#### Parameters
-
‘ctx`: running context from your command
-
‘shop`: shop domain string for shop whose admin you are calling
-
‘path`: path string (excluding prefixes and API version) for specific JSON that you are requesting
ex. "data.json" instead of "/admin/api/unstable/data.json"
-
‘body`: data string for corresponding REST request types
-
‘method`: REST request string for the type of request; if nil, will perform GET request
-
‘api_version`: an api version string to specify version. Default value: unstable
#### Raises
-
http 404 will raise a ShopifyCLI::API::APIRequestNotFoundError
-
http 400..499 will raise a ShopifyCLI::API::APIRequestClientError
-
http 500..599 will raise a ShopifyCLI::API::APIRequestServerError
-
All other codes will raise ShopifyCLI::API::APIRequestUnexpectedError
#### Returns
-
‘resp` - JSON response array
#### Example
ThemeAccessAPI.rest_request(@ctx, shop: 'shop.myshopify.com', path: 'data.json')
40 41 42 43 44 45 46 47 |
# File 'lib/shopify_cli/theme/theme_access_api.rb', line 40 def rest_request(ctx, shop:, path:, query: nil, body: nil, method: "GET", api_version: "unstable") client = api_client(ctx, api_version, shop, path: path) url = build_url(api_version, path, query) client.request(url: url, body: body, headers: headers(shop), method: method) rescue ShopifyCLI::API::APIRequestForbiddenError, ShopifyCLI::API::APIRequestUnauthorizedError ctx.abort(ctx.("core.api.error.theme_access_invalid_password")) end |
Instance Method Details
#auth_headers(token) ⇒ Object
82 83 84 85 86 |
# File 'lib/shopify_cli/theme/theme_access_api.rb', line 82 def auth_headers(token) { "X-Shopify-Access-Token" => token, } end |