Sha256: b2bec737a027e0f9aed31a3e06b5149de71e423ccb3e326be1dce73e17dfbd7a

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

require 'faraday'

module ComicVine
  class Api
    module HTTPService
      class << self
        attr_accessor :faraday_middleware, :http_options

        private

        def faraday_options(options)
          valid_options = %i(
            request proxy ssl builder url parallel_manager params headers
            builder_class
          )
          Hash[options.select { |key, _| valid_options.include?(key) }]
        end
      end

      self.http_options ||= {}

      DEFAULT_MIDDLEWARE = proc do |builder|
        builder.adapter Faraday.default_adapter
      end

      def self.make_request(request)
        connection = Faraday.new(
          request.server, faraday_options(request.options),
          &(faraday_middleware || DEFAULT_MIDDLEWARE)
        )
        response = connection.send(request.verb, request.path, request.args)
        ComicVine::Api::Response.new(
          status: response.status.to_i, headers: response.headers,
          body: response.body
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comic_vine-api-0.1.1 lib/comic_vine/api/http_service.rb