Sha256: f0840976f2b8899b8ff2f7cf0bad3927aaac341535d7c7b7b257fbcfaa02e5c2

Contents?: true

Size: 723 Bytes

Versions: 2

Compression:

Stored size: 723 Bytes

Contents

require 'httparty'

module PostmanMta
  class ApiClient
    include ::HTTParty
    base_uri PostmanMta.api_endpoint

    [:get, :post, :put, :patch, :delete].each do |type|
      define_method type do |url, options = {}|
        perform_request(type.to_s.upcase, url, options)
      end
    end

    private

    def perform_request(request_type, path, options = {})
      headers = PostmanMta::Utils::SignedRequest.new(
        request_method: request_type.upcase, path: path
      ).headers

      response = self.class.send(
        request_type.downcase,
        path,
        { headers: headers, format: :json }.merge(options)
      )

      { json: response.parsed_response, status: response.code }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
postman_mta-0.1.3 lib/postman_mta/api_client.rb
postman_mta-0.1.2 lib/postman_mta/api_client.rb