Sha256: eb67aff0e5f9b75d959ccd068b41eb1f421fa1d2cfef4eba663f352496b4b63e

Contents?: true

Size: 835 Bytes

Versions: 9

Compression:

Stored size: 835 Bytes

Contents

require 'poms/api/client'

module Poms
  module Api
    # The JsonClient module is a wrapper around the regular Client module. It
    # requests and responses to handle JSON-formatted bodies.
    module JsonClient
      DEFAULT_HEADERS = {
        'Content-Type' => 'application/json',
        'Accept' => 'application/json'
      }.freeze

      module_function

      def get(uri, credentials, headers = {})
        response = Client.get(
          uri,
          credentials,
          DEFAULT_HEADERS.merge(headers)
        )
        JSON.parse(response.body)
      end

      def post(uri, body, credentials, headers = {})
        response = Client.post(
          uri,
          body.to_json,
          credentials,
          DEFAULT_HEADERS.merge(headers)
        )
        JSON.parse(response.body)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
poms-2.1.3 lib/poms/api/json_client.rb
poms-2.1.2.1 lib/poms/api/json_client.rb
poms-2.1.2 lib/poms/api/json_client.rb
poms-2.1.1 lib/poms/api/json_client.rb
poms-2.1.0 lib/poms/api/json_client.rb
poms-2.0.1 lib/poms/api/json_client.rb
poms-2.0.0 lib/poms/api/json_client.rb
poms-2.0.0.b lib/poms/api/json_client.rb
poms-2.0.0.a lib/poms/api/json_client.rb