Class: Tinder::Connection
- Inherits:
-
Object
- Object
- Tinder::Connection
- Defined in:
- lib/tinder/connection.rb
Constant Summary collapse
- HOST =
'campfirenow.com'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #basic_auth_settings ⇒ Object
- #connection ⇒ Object
- #get(url, *args) ⇒ Object
-
#initialize(subdomain, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(url, body = nil, *args) ⇒ Object
- #put(url, body = nil, *args) ⇒ Object
- #raw_connection ⇒ Object
- #raw_post(url, body = nil, *args) ⇒ Object
-
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?.
- #token ⇒ Object
Constructor Details
#initialize(subdomain, options = {}) ⇒ Connection
Returns a new instance of Connection.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tinder/connection.rb', line 37 def initialize(subdomain, = {}) @subdomain = subdomain @options = {:ssl => true, :ssl_options => {:verify => true}, :proxy => ENV['HTTP_PROXY']} @options[:ssl_options][:verify] = .delete(:ssl_verify) unless [:ssl_verify].nil? @options.merge!() @uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}") @token = [:token] @oauth_token = [: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 |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/tinder/connection.rb', line 13 def @options end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
13 14 15 |
# File 'lib/tinder/connection.rb', line 13 def subdomain @subdomain end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
13 14 15 |
# File 'lib/tinder/connection.rb', line 13 def uri @uri end |
Class Method Details
.connection ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tinder/connection.rb', line 15 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 |
.raw_connection ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tinder/connection.rb', line 26 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 |
Instance Method Details
#basic_auth_settings ⇒ Object
55 56 57 |
# File 'lib/tinder/connection.rb', line 55 def basic_auth_settings {:username => token, :password => 'X'} end |
#connection ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/tinder/connection.rb', line 59 def connection @connection ||= begin conn = self.class.connection.dup (conn) conn end end |
#get(url, *args) ⇒ Object
82 83 84 85 |
# File 'lib/tinder/connection.rb', line 82 def get(url, *args) response = connection.get(url, *args) response.body end |
#post(url, body = nil, *args) ⇒ Object
87 88 89 90 |
# File 'lib/tinder/connection.rb', line 87 def post(url, body = nil, *args) response = connection.post(url, body, *args) response.body end |
#put(url, body = nil, *args) ⇒ Object
96 97 98 99 |
# File 'lib/tinder/connection.rb', line 96 def put(url, body = nil, *args) response = connection.put(url, body, *args) response.body end |
#raw_connection ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/tinder/connection.rb', line 67 def raw_connection @raw_connection ||= begin conn = self.class.raw_connection.dup (conn) conn end end |
#raw_post(url, body = nil, *args) ⇒ Object
92 93 94 |
# File 'lib/tinder/connection.rb', line 92 def raw_post(url, body = nil, *args) response = raw_connection.post(url, body, *args) end |
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?
102 103 104 |
# File 'lib/tinder/connection.rb', line 102 def ssl? uri.scheme == 'https' end |
#token ⇒ Object
75 76 77 78 79 80 |
# File 'lib/tinder/connection.rb', line 75 def token @token ||= begin connection.basic_auth([:username], [:password]) get('/users/me.json')['user']['api_auth_token'] end end |