Module: Amara::Connection
- Included in:
- API
- Defined in:
- lib/amara/connection.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
[ :headers, :url, :params, :request, :ssl ].freeze
Instance Method Summary collapse
Instance Method Details
#connection(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/amara/connection.rb', line 34 def connection(={}) opts = () Faraday.new(opts) do |connection| connection.request :url_encoded connection.response :mashify connection.response :logger if ENV['DEBUG'] connection.response :json connection.adapter(adapter) end end |
#merge_default_options(opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/amara/connection.rb', line 16 def (opts={}) headers = opts.delete(:headers) || {} = HashWithIndifferentAccess.new( { :headers => { 'User-Agent' => user_agent, 'Accept' => "application/json", 'Content-Type' => "application/json" }, :ssl => {:verify => false}, :url => endpoint } ).merge(opts) [:headers] = [:headers].merge(headers) Amara::HEADERS.each{|k,v| [:headers][v] = .delete(k) if .key?(k)} .slice(*ALLOWED_OPTIONS) end |