Class: ShopifyCLI::PartnersAPI

Inherits:
API
  • Object
show all
Defined in:
lib/shopify_cli/partners_api.rb,
lib/shopify_cli/partners_api/organizations.rb,
lib/shopify_cli/partners_api/app_extensions.rb,
lib/shopify_cli/partners_api/app_extensions/job.rb

Overview

ShopifyCLI::PartnersAPI provides easy access to the partners dashboard CLI schema.

Defined Under Namespace

Classes: AppExtensions, Organizations

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from API

gid_to_id, #query, #request

Class Method Details

.partners_url_for(organization_id, api_client_id) ⇒ Object



57
58
59
60
61
62
# File 'lib/shopify_cli/partners_api.rb', line 57

def partners_url_for(organization_id, api_client_id)
  if ShopifyCLI::Shopifolk.acting_as_shopify_organization?
    organization_id = "internal"
  end
  "https://#{Environment.partners_domain}/#{organization_id}/apps/#{api_client_id}"
end

.query(ctx, query_name, **variables) ⇒ Object

issues a graphql query or mutation to the Shopify Partners Dashboard CLI Schema. It loads a graphql query from a file so that you do not need to use large unwieldy query strings. It also handles authentication for you as well.

#### Parameters

  • ‘ctx`: running context from your command

  • ‘query_name`: name of the query you want to use, loaded from the `lib/graphql` directory.

  • ‘**variables`: a hash of variables to be supplied to the query or mutation

#### 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` - graphql response data hash. This can be a different shape for every query.

#### Example

ShopifyCLI::PartnersAPI.query(@ctx, 'all_organizations')


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/shopify_cli/partners_api.rb', line 38

def query(ctx, query_name, **variables)
  CLI::Kit::Util.begin do
    api_client(ctx).query(query_name, variables: variables)
  end.retry_after(
    API::APIRequestUnauthorizedError,
    retries: 1,
    only: -> { !IdentityAuth::EnvAuthToken.partners_token_present? }
  ) do
    ShopifyCLI::IdentityAuth.new(ctx: ctx).reauthenticate
  end
rescue API::APIRequestUnauthorizedError => e
  if (request_info = auth_failure_info(ctx, e))
    ctx.puts(ctx.message("core.api.error.failed_auth_debugging", request_info))
  end
  ctx.abort(ctx.message("core.api.error.failed_auth"))
rescue API::APIRequestNotFoundError
  ctx.puts(ctx.message("core.partners_api.error.account_not_found", ShopifyCLI::TOOL_NAME))
end

Instance Method Details

#auth_headers(token) ⇒ Object



87
88
89
# File 'lib/shopify_cli/partners_api.rb', line 87

def auth_headers(token)
  { Authorization: "Bearer #{token}" }
end