class ShopifyAPI::Clients::Rest::Admin

def delete(path:, body: nil, query: nil, headers: nil, tries: 1)

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

def get(path:, body: nil, query: nil, headers: nil, tries: 1)

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

def initialize(session: nil, api_version: nil)

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

def make_request(http_method:, path:, body:, query:, headers:, tries:)

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

def post(path:, body:, query: nil, headers: nil, tries: 1)

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

def put(path:, body:, query: nil, headers: nil, tries: 1)

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

def request_url(request)

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