Module: Vermonster::Authentication

Included in:
Client
Defined in:
lib/vermonster/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authorize_url(options = {}) ⇒ Object

Returns the URL for authorizing the user.



4
5
6
7
8
9
10
11
12
# File 'lib/vermonster/authentication.rb', line 4

def authorize_url(options={})
  url = "https://api.cheddarapp.com/oauth/authorize?client_id=#{@client[:id]}"

  options.each do |key, value|
    url = url << "&#{key}=#{value}"
  end

  url
end

#authorized?Boolean

Check if authorized or not.

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/vermonster/authentication.rb', line 41

def authorized?
  if Vermonster::Client.connection.get("me").status == 200
    true
  else
    false
  end
end

#token!(code) ⇒ Object

Get the token for the user.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vermonster/authentication.rb', line 15

def token!(code)
  Vermonster::Client.connection.basic_auth(@client[:id], @client[:secret])

  response = Vermonster::Client.connection.post "/oauth/token", { :grant_type => "authorization_code", :code => code }

  if response.body["access_token"]
    @client = @client.merge(:token => response.body["access_token"])

    self.connect!(@client[:token])

    authorized?
  else
    false
  end
end

#use_token!(token) ⇒ Object

Skip the code and just use the developer’s user access token.



32
33
34
35
36
37
38
# File 'lib/vermonster/authentication.rb', line 32

def use_token!(token)
  @client = @client.merge(:token => token)

  self.connect!(@client[:token])

  authorized?
end