Module: CodasetAPI

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

Defined Under Namespace

Classes: Base, Error, Project, Ticket

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.accountObject

Returns the value of attribute account.



19
20
21
# File 'lib/codaset/codaset-api.rb', line 19

def 
  @account
end

.client_idObject

Returns the value of attribute client_id.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def client_id
  @client_id
end

.client_secretObject

Returns the value of attribute client_secret.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def client_secret
  @client_secret
end

.domain_formatObject

Returns the value of attribute domain_format.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def domain_format
  @domain_format
end

.host_formatObject

Returns the value of attribute host_format.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def host_format
  @host_format
end

.passwordObject

Returns the value of attribute password.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def password
  @password
end

.protocolObject

Returns the value of attribute protocol.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def protocol
  @protocol
end

.siteObject

Returns the value of attribute site.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def site
  @site
end

.tokenObject

Returns the value of attribute token.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def token
  @token
end

.usernameObject

Returns the value of attribute username.



18
19
20
# File 'lib/codaset/codaset-api.rb', line 18

def username
  @username
end

Class Method Details

.access_token(master) ⇒ Object

Gets the OAuth2’s access token



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/codaset/codaset-api.rb', line 45

def access_token(master)
  @auth_url = '/authorization/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},
                                                'Content-Type' => 'application/x-www-form-urlencoded')

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

end

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/codaset/codaset-api.rb', line 21

def authenticate(username, password, client_id, client_secret)
  @username = username
  @password = password
  @client_id = client_id
  @client_secret = client_secret
  @site = 'https://api.codaset.com'
  
  self::Base.user = username
  self::Base.password = password
  self::Base.site = @site
 
  self.token = access_token(self)

end

.resourcesObject



77
78
79
# File 'lib/codaset/codaset-api.rb', line 77

def resources
  @resources ||= []
end