class Tinder::Connection
Constants
- HOST
Attributes
options[R]
subdomain[R]
uri[R]
Public Class Methods
connection()
click to toggle source
# File lib/tinder/connection.rb, line 19 def self.connection @connection ||= Faraday.new do |builder| builder.use FaradayMiddleware::EncodeJson builder.use FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson builder.use Faraday::Response::RemoveWhitespace builder.use Faraday::Response::RaiseOnAuthenticationFailure builder.adapter Faraday.default_adapter end end
new(subdomain, options = {})
click to toggle source
# File lib/tinder/connection.rb, line 41 def initialize(subdomain, options = {}) @subdomain = subdomain @options = {:ssl => true, :ssl_options => {:verify => true}, :proxy => ENV['HTTP_PROXY']} @options[:ssl_options][:verify] = options.delete(:ssl_verify) unless options[:ssl_verify].nil? @options.merge!(options) @uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}") @token = options[:token] @oauth_token = options[:oauth_token] if @oauth_token connection.headers["Authorization"] = "Bearer #{@oauth_token}" raw_connection.headers["Authorization"] = "Bearer #{@oauth_token}" else connection.basic_auth token, 'X' raw_connection.basic_auth token, 'X' end end
raw_connection()
click to toggle source
# File lib/tinder/connection.rb, line 30 def self.raw_connection @raw_connection ||= Faraday.new do |builder| builder.use Faraday::Request::Multipart builder.use FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson builder.use Faraday::Response::RemoveWhitespace builder.use Faraday::Response::RaiseOnAuthenticationFailure builder.adapter Faraday.default_adapter end end
Public Instance Methods
basic_auth_settings()
click to toggle source
# File lib/tinder/connection.rb, line 59 def basic_auth_settings {:username => token, :password => 'X'} end
connection()
click to toggle source
# File lib/tinder/connection.rb, line 63 def connection @connection ||= begin conn = self.class.connection.dup set_connection_options(conn) conn end end
get(url, *args)
click to toggle source
# File lib/tinder/connection.rb, line 86 def get(url, *args) response = connection.get(url, *args) response.body end
post(url, body = nil, *args)
click to toggle source
# File lib/tinder/connection.rb, line 91 def post(url, body = nil, *args) response = connection.post(url, body, *args) response.body end
put(url, body = nil, *args)
click to toggle source
# File lib/tinder/connection.rb, line 100 def put(url, body = nil, *args) response = connection.put(url, body, *args) response.body end
raw_connection()
click to toggle source
# File lib/tinder/connection.rb, line 71 def raw_connection @raw_connection ||= begin conn = self.class.raw_connection.dup set_connection_options(conn) conn end end
raw_post(url, body = nil, *args)
click to toggle source
# File lib/tinder/connection.rb, line 96 def raw_post(url, body = nil, *args) response = raw_connection.post(url, body, *args) end
ssl?()
click to toggle source
Is the connection to campfire using ssl?
# File lib/tinder/connection.rb, line 106 def ssl? uri.scheme == 'https' end
token()
click to toggle source
# File lib/tinder/connection.rb, line 79 def token @token ||= begin connection.basic_auth(options[:username], options[:password]) get('/users/me.json')['user']['api_auth_token'] end end
Private Instance Methods
set_connection_options(conn)
click to toggle source
# File lib/tinder/connection.rb, line 111 def set_connection_options(conn) conn.url_prefix = @uri.to_s conn.proxy options[:proxy] if options[:ssl_options] conn.ssl.merge!(options[:ssl_options]) end end