class ShopifyAPI::Clients::Rest::Admin

Public Class Methods

new(session: nil, api_version: nil) click to toggle source
Calls superclass method ShopifyAPI::Clients::HttpClient::new
# File lib/shopify_api/clients/rest/admin.rb, line 11
def initialize(session: nil, api_version: nil)
  @api_version = T.let(api_version || Context.api_version, String)
  if api_version
    if api_version == Context.api_version
      Context.logger.debug("Rest client has a redundant API version override "\
        "to the default #{Context.api_version}")
    else
      Context.logger.debug("Rest client overriding default API version "\
        "#{Context.api_version} with #{api_version}")
    end
  end

  super(session: session, base_path: "/admin/api/#{@api_version}")
end

Public Instance Methods

delete(path:, body: nil, query: nil, headers: nil, tries: 1) click to toggle source
# File lib/shopify_api/clients/rest/admin.rb, line 51
def delete(path:, body: nil, query: nil, headers: nil, tries: 1)
  request(
    make_request(http_method: :delete, path: path, body: body, query: query, headers: headers,
      tries: T.must(tries)),
  )
end
get(path:, body: nil, query: nil, headers: nil, tries: 1) click to toggle source
# File lib/shopify_api/clients/rest/admin.rb, line 35
def get(path:, body: nil, query: nil, headers: nil, tries: 1)
  request(
    make_request(http_method: :get, path: path, body: body, query: query, headers: headers,
      tries: T.must(tries)),
  )
end
post(path:, body:, query: nil, headers: nil, tries: 1) click to toggle source
# File lib/shopify_api/clients/rest/admin.rb, line 83
def post(path:, body:, query: nil, headers: nil, tries: 1)
  request(
    make_request(http_method: :post, path: path, body: body, query: query, headers: headers,
      tries: T.must(tries)),
  )
end
put(path:, body:, query: nil, headers: nil, tries: 1) click to toggle source
# File lib/shopify_api/clients/rest/admin.rb, line 67
def put(path:, body:, query: nil, headers: nil, tries: 1)
  request(
    make_request(http_method: :put, path: path, body: body, query: query, headers: headers,
      tries: T.must(tries)),
  )
end

Protected Instance Methods

request_url(request) click to toggle source
# File lib/shopify_api/clients/rest/admin.rb, line 93
def request_url(request)
  request_path = request.path.sub(%r/\A\//, "").sub(/\.json\z/, "") + ".json"

  if request_path.start_with?("admin/")
    "#{@base_uri}/#{request_path}"
  else
    "#{@base_uri_and_path}/#{request_path}"
  end
end

Private Instance Methods

make_request(http_method:, path:, body:, query:, headers:, tries:) click to toggle source
# File lib/shopify_api/clients/rest/admin.rb, line 115
def make_request(http_method:, path:, body:, query:, headers:, tries:)
  HttpRequest.new(
    http_method: http_method,
    path: path,
    body: body,
    query: query,
    extra_headers: headers,
    body_type: body.nil? ? nil : "application/json",
    tries: tries,
  )
end