Class: Tinder::Connection
- Inherits:
-
Object
- Object
- Tinder::Connection
- Defined in:
- lib/vendor/tinder/lib/tinder/connection.rb
Defined Under Namespace
Modules: HTTPartyExtensions
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.
Instance Method Summary collapse
-
#initialize(subdomain, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #metaclass ⇒ Object
- #method_missing(*args, &block) ⇒ Object
-
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?.
- #token ⇒ Object
Constructor Details
#initialize(subdomain, options = {}) ⇒ Connection
Returns a new instance of Connection.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 23 def initialize(subdomain, = {}) @subdomain = subdomain @options = { :ssl => false, :proxy => ENV['HTTP_PROXY'] }.merge() @uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}") @token = [:token] class << self include HTTParty extend HTTPartyExtensions headers 'Content-Type' => 'application/json' end if @options[:proxy] proxy_uri = URI.parse(@options[:proxy]) http_proxy proxy_uri.host, proxy_uri.port end base_uri @uri.to_s basic_auth token, 'X' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
64 65 66 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 64 def method_missing(*args, &block) .send(*args, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 21 def @options end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
21 22 23 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 21 def subdomain @subdomain end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
21 22 23 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 21 def uri @uri end |
Instance Method Details
#metaclass ⇒ Object
60 61 62 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 60 def class << self; self; end end |
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?
69 70 71 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 69 def ssl? uri.scheme == 'https' end |
#token ⇒ Object
53 54 55 56 57 58 |
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 53 def token @token ||= begin self.basic_auth([:username], [:password]) self.get('/users/me.json')['user']['api_auth_token'] end end |