Module: Http::Remote::Route

Extended by:
ActiveSupport::Concern
Defined in:
lib/rspec-api/http/remote/route.rb

Instance Method Summary collapse

Instance Method Details

#authorizationObject



26
27
28
29
# File 'lib/rspec-api/http/remote/route.rb', line 26

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

#send_request(verb, route, body) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rspec-api/http/remote/route.rb', line 6

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