module Tweetsentiments::Connection

Private Instance Methods

connection(raw=false) click to toggle source
# File lib/tweetsentiments/connection.rb, line 7
def connection(raw=false)
  options = {
    :headers => {'Accept' => "application/#{format}", 'User-Agent' => user_agent},
    :proxy => proxy,
    :ssl => {:verify => false},
    :url => endpoint,
  }

  Faraday::Connection.new(options) do |connection|
    connection.use Faraday::Request::Multipart
    connection.adapter(adapter)
    connection.use Faraday::Response::RaiseHttp5xx
    unless raw
      case format.to_s.downcase
        when 'json' then connection.use Faraday::Response::ParseJson
        when 'xml' then connection.use Faraday::Response::ParseXml
      end
    end
    connection.use Faraday::Response::RaiseHttp4xx
    connection.use Faraday::Response::Mashify unless raw
  end
end