Sha256: d23364403e5b890dfb68e72080b43bbd09b428612cc8e3d0458d88c32354dec3

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Http
  module Remote
    module Route
      extend ActiveSupport::Concern

      def send_request(verb, route, body)
        logger = Logger.new 'log/faraday.log'

        conn = Faraday.new 'https://api.github.com/' do |c| # TODO: Pass host as a parameter
          # NOTE: The order is **important**! Leave HttpCache first
          c.use Faraday::HttpCache, serializer: Marshal, store: :file_store, store_options: ['/tmp/faraday'], logger: logger
          c.use FaradayMiddleware::EncodeJson # query params are not JSON(body) but data are
          c.use Faraday::Response::Logger, logger
          c.use Faraday::Adapter::NetHttp
        end

        conn.headers[:user_agent] = 'RSpec API'
        conn.authorization *authorization.flatten
        sleep 0.5 # TODO: Pass as a parameter

        @last_response = conn.send verb, route, body do |request|
          @last_request = request
        end
      end

      def authorization
        # TODO: Any other way to access metadata in a before(:all) ?
        self.class.metadata[:rspec_api][:authorization]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-api-0.4.0 lib/rspec-api/http/remote/route.rb
rspec-api-0.2.0 lib/rspec-api/http/remote/route.rb