Module: TeamboxAPI

Defined in:
lib/teambox/teambox-api.rb

Overview

This library is a small wrapper around the REST interface

Defined Under Namespace

Classes: Base, Comment, Error, Project, Task

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.client_idObject

Returns the value of attribute client_id.



15
16
17
# File 'lib/teambox/teambox-api.rb', line 15

def client_id
  @client_id
end

.client_secretObject

Returns the value of attribute client_secret.



15
16
17
# File 'lib/teambox/teambox-api.rb', line 15

def client_secret
  @client_secret
end

.passwordObject

Returns the value of attribute password.



15
16
17
# File 'lib/teambox/teambox-api.rb', line 15

def password
  @password
end

.siteObject

Returns the value of attribute site.



15
16
17
# File 'lib/teambox/teambox-api.rb', line 15

def site
  @site
end

.tokenObject

Returns the value of attribute token.



15
16
17
# File 'lib/teambox/teambox-api.rb', line 15

def token
  @token
end

.usernameObject

Returns the value of attribute username.



15
16
17
# File 'lib/teambox/teambox-api.rb', line 15

def username
  @username
end

Class Method Details

.access_token(master) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/teambox/teambox-api.rb', line 29

def access_token(master)
  @auth_url = '/oauth/token'
  consumer = OAuth2::Client.new(master.client_id,
                                master.client_secret,
                                {:site => 
                                          {:url => master.site, 
                                           :ssl => {:verify => OpenSSL::SSL::VERIFY_NONE,
                                                    :ca_file => nil
                                                   }
                                          },
                                :authorize_url => @auth_url,
                                :parse_json => true})
                                  
  response = consumer.request(:post, @auth_url, {:grant_type => 'password', 
                                                :client_id => master.client_id,
                                                :client_secret => master.client_secret,
                                                :username => master.username, 
                                                :password => master.password,
                                                :scope => 'read_projects write_projects'},
                              'Content-Type' => 'application/x-www-form-urlencoded')

  OAuth2::AccessToken.new(consumer, response['access_token']).token

end

.authenticate(client_id, client_secret, username, password) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/teambox/teambox-api.rb', line 16

def authenticate(client_id, client_secret, username, password)
  @username  = username
  @password  = password
  @site = 'https://teambox.com/'
  @client_id = client_id
  @client_secret = client_secret

  self::Base.user = username
  self::Base.password = password
  self.token = access_token(self)

end

.resourcesObject



61
62
63
# File 'lib/teambox/teambox-api.rb', line 61

def resources
  @resources ||= []
end