Class: OAuth2::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/access_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, token, refresh_token = nil, expires_in = nil) ⇒ AccessToken

Returns a new instance of AccessToken.



5
6
7
8
9
10
11
# File 'lib/oauth2/access_token.rb', line 5

def initialize(client, token, refresh_token = nil, expires_in = nil)
  @client = client
  @token = token
  @refresh_token = refresh_token
  @expires_in = (expires_in.nil? || expires_in == '') ? nil : expires_in.to_i
  @expires_at = Time.now + @expires_in if @expires_in
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/oauth2/access_token.rb', line 3

def client
  @client
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



3
4
5
# File 'lib/oauth2/access_token.rb', line 3

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



3
4
5
# File 'lib/oauth2/access_token.rb', line 3

def expires_in
  @expires_in
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



3
4
5
# File 'lib/oauth2/access_token.rb', line 3

def refresh_token
  @refresh_token
end

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/oauth2/access_token.rb', line 3

def token
  @token
end

Instance Method Details

#delete(path, params = {}, headers = {}) ⇒ Object



34
35
36
# File 'lib/oauth2/access_token.rb', line 34

def delete(path, params = {}, headers = {})
  request(:delete, path, params, headers)
end

#expires?Boolean

True if the token in question has an expiration time.

Returns:

  • (Boolean)


14
15
16
# File 'lib/oauth2/access_token.rb', line 14

def expires?
  !!@expires_in
end

#get(path, params = {}, headers = {}) ⇒ Object



22
23
24
# File 'lib/oauth2/access_token.rb', line 22

def get(path, params = {}, headers = {})
  request(:get, path, params, headers)
end

#post(path, params = {}, headers = {}) ⇒ Object



26
27
28
# File 'lib/oauth2/access_token.rb', line 26

def post(path, params = {}, headers = {})
  request(:post, path, params, headers)
end

#put(path, params = {}, headers = {}) ⇒ Object



30
31
32
# File 'lib/oauth2/access_token.rb', line 30

def put(path, params = {}, headers = {})
  request(:put, path, params, headers)
end

#request(verb, path, params = {}, headers = {}) ⇒ Object



18
19
20
# File 'lib/oauth2/access_token.rb', line 18

def request(verb, path, params = {}, headers = {})
  @client.request(verb, path, params.merge('access_token' => @token), headers.merge('Authorization' => "Token token=\"#{@token}\""))
end