Class: Tinder::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/tinder/lib/tinder/connection.rb

Defined Under Namespace

Modules: HTTPartyExtensions

Constant Summary collapse

HOST =
"campfirenow.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @subdomain = subdomain
  @options = { :ssl => false, :proxy => ENV['HTTP_PROXY'] }.merge(options)
  @uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}")
  @token = options[: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)
  metaclass.send(*args, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 21

def options
  @options
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



21
22
23
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 21

def subdomain
  @subdomain
end

#uriObject (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

#metaclassObject



60
61
62
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 60

def metaclass
  class << self; self; end
end

#ssl?Boolean

Is the connection to campfire using ssl?

Returns:

  • (Boolean)


69
70
71
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 69

def ssl?
  uri.scheme == 'https'
end

#tokenObject



53
54
55
56
57
58
# File 'lib/vendor/tinder/lib/tinder/connection.rb', line 53

def token
  @token ||= begin
    self.basic_auth(options[:username], options[:password])
    self.get('/users/me.json')['user']['api_auth_token']
  end
end