Sha256: 5c992f12883273af0fb2aba8c6eadd30f5a595dcb5431fd5e2568eb433e29890

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 Bytes

Contents

# frozen_string_literal: true
require 'httparty'

module Eship
  module ApiClient
    def self.default_headers
      {
        "content-type" => 'application/json',
        ImmutableKey.new("api-key") => Eship.eship_key 
      }
    end

    def self.post(path:, body: {}, headers: {})
      path = "#{Eship.base_uri}#{path}"
      headers = headers.merge(ApiClient.default_headers)
      response = HTTParty.post(path, body: body.to_json, headers: headers)
      JSON.parse(response.body)
    end

    #Monkey patch to avoid headers capitalization https://jatindhankhar.in/blog/custom-http-header-and-ruby-standard-library/
    class ImmutableKey < String 
      def capitalize 
        self 
      end

      def to_s
        self 
       end 

       alias_method :to_str, :to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eship-ruby-0.1.0 lib/eship/api_client.rb