Sha256: b75d3765fdaf350cb8d10e84f74d4986870d7b914f991c88d8adebee6455c45b
Contents?: true
Size: 978 Bytes
Versions: 7
Compression:
Stored size: 978 Bytes
Contents
class TMS::Connection attr_accessor :auth_token, :api_root, :connection, :logger def get(href) resp = connection.get("#{href}.json") if resp.status != 200 raise RecordNotFound.new("Could not find resource at #{href} (status #{resp.status})") else resp.body end end def initialize(opts={}) self.auth_token = opts[:auth_token] self.api_root = opts[:api_root] self.logger = opts[:logger] setup_connection end def setup_connection self.connection = Faraday.new(:url => self.api_root) do |faraday| faraday.use TMS::Logger, self.logger if self.logger faraday.request :json faraday.headers['X-AUTH-TOKEN'] = auth_token faraday.headers[:user_agent] = "GovDelivery Ruby TMS::Client #{TMS::VERSION}" faraday.response :json, :content_type => /\bjson$/ faraday.adapter :net_http end end def dump_headers(headers) headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n") end end
Version data entries
7 entries across 7 versions & 2 rubygems