lib/footrest/connection.rb in footrest-0.1 vs lib/footrest/connection.rb in footrest-0.1.2
- old
+ new
@@ -3,23 +3,24 @@
require 'faraday/response/raise_footrest_http_error'
module Footrest
module Connection
- def connection
- @options ||= {}
- @connection ||= Faraday.new(url: @options[:domain]) do |faraday|
+ attr_reader :connection
+
+ def set_connection(config, &block)
+ @connection = Faraday.new(url: config[:prefix]) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
- faraday.response :logger if @options[:logging]
+ faraday.response :logger if config[:logging]
faraday.adapter Faraday.default_adapter
faraday.use FaradayMiddleware::FollowRedirects
faraday.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
faraday.use Faraday::Response::RaiseFootrestHttpError
faraday.headers[:accept] = "application/json"
- faraday.headers[:authorization] = "Bearer #{@options[:token]}"
+ faraday.headers[:authorization] = "Bearer #{config[:token]}" if config[:token]
faraday.headers[:user_agent] = "Footrest"
- @faraday_option_block.call(faraday) if @faraday_option_block
+ yield faraday if block_given?
end
end
end
end
\ No newline at end of file