Module: YahooContentAnalysis::Connection
- Included in:
- Client
- Defined in:
- lib/yahoo_content_analysis/connection.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
[ :headers, :url, :params, :request, :ssl ].freeze
Instance Method Summary collapse
- #add_default_options(opts = {}) ⇒ Object
- #connection(options = {}) ⇒ Object
- #oauth_opts(opts) ⇒ Object
Instance Method Details
#add_default_options(opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yahoo_content_analysis/connection.rb', line 16 def (opts={}) headers = opts.delete(:headers) || {} = { :consumer_key => api_key, :consumer_secret => api_secret, :headers => { # generic http headers 'User-Agent' => user_agent, 'Accept' => "application/json;charset=utf-8" }, :ssl => {:verify => false}, :url => endpoint }.merge(opts) [:headers] = [:headers].merge(headers) end |
#connection(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yahoo_content_analysis/connection.rb', line 33 def connection(={}) opts = () oauth = oauth_opts(opts) Faraday::Connection.new(opts) do |connection| connection.request :oauth, oauth if oauth connection.request :url_encoded connection.response :mashify connection.response :logger if ENV['DEBUG'] connection.response :json connection.adapter(adapter) end end |
#oauth_opts(opts) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/yahoo_content_analysis/connection.rb', line 46 def oauth_opts(opts) oauth_opts = if opts.key?(:consumer_secret) && opts.key?(:consumer_key) {:consumer_secret => opts.delete(:consumer_secret), :consumer_key => opts.delete(:consumer_key)} else nil end end |