Class: Outreach::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/outreach/authorization.rb

Constant Summary collapse

API_URL =
"https://api.outreach.io/oauth/token"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Authorization

Returns a new instance of Authorization.



9
10
11
12
13
# File 'lib/outreach/authorization.rb', line 9

def initialize(attrs)
  @token = attrs['access_token']
  @refresh_token = attrs['refresh_token']
  @expires_in = attrs['expires_in']
end

Instance Attribute Details

#expires_inObject (readonly)

Returns the value of attribute expires_in.



7
8
9
# File 'lib/outreach/authorization.rb', line 7

def expires_in
  @expires_in
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



7
8
9
# File 'lib/outreach/authorization.rb', line 7

def refresh_token
  @refresh_token
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/outreach/authorization.rb', line 7

def token
  @token
end

Class Method Details

.authorization_urlObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/outreach/authorization.rb', line 15

def self.authorization_url
  url = "https://api.outreach.io/oauth/authorize"
  params = {
    client_id:     Outreach.application_identifier,
    redirect_uri:  Outreach.redirect_uri,
    response_type: 'code',
    scope:         Outreach.scopes
  }
  url + "?" + URI.encode_www_form(params)
end

.create(authorization_code) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/outreach/authorization.rb', line 26

def self.create(authorization_code)
  params = {
    client_id:     Outreach.application_identifier,
    client_secret: Outreach.application_secret,
    redirect_uri:  Outreach.redirect_uri,
    grant_type:    'authorization_code',
    code:          authorization_code
  }
  response = Outreach::Request.new.post(API_URL, params)
  new(response)
end

.refresh(refresh_token) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/outreach/authorization.rb', line 38

def self.refresh(refresh_token)
  params = {
    client_id:     Outreach.application_identifier,
    client_secret: Outreach.application_secret,
    redirect_uri:  Outreach.redirect_uri,
    grant_type:    'refresh_token',
    refresh_token: refresh_token
  }
  response = Request.new.post(API_URL, params)
  new(response)
end