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, params = {}) ⇒ AccessToken

Returns a new instance of AccessToken.



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

def initialize(client, token, refresh_token = nil, expires_in = nil, params = {})
  @client = client
  @token = token.to_s
  @refresh_token = refresh_token.to_s
  @expires_in = (expires_in.nil? || expires_in == '') ? nil : expires_in.to_i
  @expires_at = Time.now + @expires_in if @expires_in
  @params = params
  @token_param = 'oauth_token'
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

#token_paramObject

Returns the value of attribute token_param.



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

def token_param
  @token_param
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/oauth2/access_token.rb', line 16

def [](key)
  @params[key]
end

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



43
44
45
# File 'lib/oauth2/access_token.rb', line 43

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)


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

def expires?
  !!@expires_in
end

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



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

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

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



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

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

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



39
40
41
# File 'lib/oauth2/access_token.rb', line 39

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

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



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

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