module Repro::Connection

Public Instance Methods

last_response() click to toggle source
# File lib/repro/connection.rb, line 20
def last_response
  @last_response
end
post(endpoint, path, payload) click to toggle source
# File lib/repro/connection.rb, line 10
def post(endpoint, path, payload)
  @last_response = connection(endpoint).post do |request|
    request.url path
    request.body = JSON.generate(payload)
  end

  error = Repro::Error.from_response(last_response)
  error ? raise(error) : Repro::Response.new(last_response)
end

Private Instance Methods

connection(endpoint) click to toggle source
# File lib/repro/connection.rb, line 26
def connection(endpoint)
  @connection ||= {}
  @connection[endpoint] ||= Faraday.new(endpoint) do |faraday|
    faraday.headers["Content-Type"] = "application/json"
    faraday.headers["X-Repro-Token"] = token
    faraday.adapter Faraday.default_adapter
  end
end