Sha256: a5961ae86ca6dbbf98230b23b006dbd0d076bea6e79312a419c2fb08b0184deb
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true module ShopifyApiBruv module Clients class HttpClient attr_reader :config, :endpoint, :headers def initialize(config:, path:) raise Errors::HttpClientError, 'Missing or invalid config.' unless config.is_a?(Auth::Config) @config = config @endpoint = "#{config.api_domain}/#{path}" @headers = { 'User-Agent': "Bruv #{VERSION}", 'Accept': 'application/json', 'X-Shopify-Access-Token': config.api_access_token } end def request(http_request:) raise Errors::HttpClientError, 'Missing or invalid http request.' unless http_request.is_a?(HttpRequest) headers.merge(http_request.headers) unless http_request.headers.nil? headers['Content-Type'] = http_request.content_type response = HTTParty.public_send( http_request.method, "https://#{endpoint}/#{http_request.path}", headers:, query: http_request.query, body: http_request.body ) HttpResponse.new(code: response.code, headers: response.headers, body: response.parsed_response) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems