Sha256: 53260873b0cb3267e032eea635b1143d5030c61cf9a3fb2ee239a29f63fab8c0

Contents?: true

Size: 908 Bytes

Versions: 4

Compression:

Stored size: 908 Bytes

Contents

module Finnegans
  module Core
    module Request

      private

      def default_headers
        {
          "Accept-Encoding" => "application/json"
        }
      end

      def request_call(resource, request_params = {})
        unless request_params.is_a?(Hash)
          raise ArgumentError, 'The second argument in the :request_call must be a Hash ({}) ' \
            'or nil. Definition -> request_call(resource, request_params = {})'
        end

        request_params[:headers] = default_headers.merge(request_params[:headers] || {})

        request = Typhoeus::Request.new("#{@base_url}#{resource}", request_params)
        request.run
        request.response
      end

      def json_dump(hash)
        Oj.dump(hash)
      end

      def json_load(string)
        begin
          Oj.load(string)
        rescue Oj::ParseError => e
          string
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
finnegans-0.1.4 lib/finnegans/core/request.rb
finnegans-0.1.3 lib/finnegans/core/request.rb
finnegans-0.1.2 lib/finnegans/core/request.rb
finnegans-0.1.1 lib/finnegans/core/request.rb