Class: RFGraph::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/rfgraph/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, app_secret) ⇒ Auth

Returns a new instance of Auth.



11
12
13
14
# File 'lib/rfgraph/auth.rb', line 11

def initialize(app_id, app_secret)
  @app_id = app_id
  @app_secret = app_secret
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



8
9
10
# File 'lib/rfgraph/auth.rb', line 8

def access_token
  @access_token
end

#app_idObject

Returns the value of attribute app_id.



6
7
8
# File 'lib/rfgraph/auth.rb', line 6

def app_id
  @app_id
end

#app_secretObject

Returns the value of attribute app_secret.



7
8
9
# File 'lib/rfgraph/auth.rb', line 7

def app_secret
  @app_secret
end

#expiresObject

Returns the value of attribute expires.



9
10
11
# File 'lib/rfgraph/auth.rb', line 9

def expires
  @expires
end

Instance Method Details

#authorize(callback_url, code) ⇒ Object



20
21
22
23
24
# File 'lib/rfgraph/auth.rb', line 20

def authorize(callback_url, code)
  data = open("#{BASE_URL}/oauth/access_token?client_id=#{app_id}&redirect_uri=#{CGI.escape callback_url}&client_secret=#{app_secret}&code=#{CGI.escape code}").read
  @expires = data.match(/expires=([^&]+)/)[1]
  @access_token = data.match(/access_token=([^&]+)/)[1]
end

#authorize_url(callback_url) ⇒ Object



16
17
18
# File 'lib/rfgraph/auth.rb', line 16

def authorize_url(callback_url)
  "#{BASE_URL}/oauth/authorize?client_id=#{app_id}&redirect_uri=#{callback_url}"
end