Sha256: bc57e5f04e7d78eb96d47c8d4c3d9feaba2eadcc9108be57904c864cb457effa

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'httparty'

module SEPOMEX_Acrogenesis
  module JsonApi
    module ClassMethods
      def default_headers
        {
          'Content-type' => 'application/json'
        }
      end

      def api_get(url:, headers: {})
        custom_headers = headers.merge(default_headers)
        response = HTTParty.get(SEPOMEX_Acrogenesis.api_base + url, headers: custom_headers)

        JSON.parse(response.body, symbolize_names: true)
      end

      def api_post(url:, body: {}, headers: {})
        custom_headers = headers.merge(default_headers)

        response =
          HTTParty.post(
            SEPOMEX_Acrogenesis.api_base + url,
            body: body.to_json, headers: custom_headers
          )

        JSON.parse(response.body, symbolize_names: true)
      end

      def api_post_multipart(url:, body: {}, headers: {})
        custom_headers = headers.merge(default_headers)

        response =
          HTTParty.post(
            SEPOMEX_Acrogenesis.api_base + url,
            multipart: true, body: body, headers: custom_headers
          )

        response.body
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sepomex_acrogenesis-0.6.0 lib/sepomex_acrogenesis/client/json_api.rb
sepomex_acrogenesis-0.5.2 lib/sepomex_acrogenesis/client/json_api.rb