Class: Oauthio::AccessToken

Inherits:
OAuth2::AccessToken
  • Object
show all
Defined in:
lib/oauthio/access_token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, provider, token, oauth_token, oauth_secret, opts = {}) ⇒ AccessToken

Returns a new instance of AccessToken.



22
23
24
25
26
27
# File 'lib/oauthio/access_token.rb', line 22

def initialize(client, provider, token, oauth_token, oauth_secret, opts={})
  super client, token, opts
  @provider = provider
  @oauth_token = oauth_token.to_s
  @oauth_token_secret = oauth_secret.to_s
end

Instance Attribute Details

#oauth_tokenObject (readonly)

Returns the value of attribute oauth_token.



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

def oauth_token
  @oauth_token
end

#oauth_token_secretObject (readonly)

Returns the value of attribute oauth_token_secret.



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

def oauth_token_secret
  @oauth_token_secret
end

#providerObject (readonly)

Returns the value of attribute provider.



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

def provider
  @provider
end

Class Method Details

.from_hash(client, hash) ⇒ AccessToken

Initializes an AccessToken from a Hash

Parameters:

  • the (Client)

    OAuth2::Client instance

  • a (Hash)

    hash of AccessToken property values

Returns:



11
12
13
14
15
16
17
18
19
# File 'lib/oauthio/access_token.rb', line 11

def from_hash(client, hash)
  provider = hash.delete('provider') || hash.delete(:provider)
  access_token = hash.delete('access_token') || hash.delete(:access_token)
  oauth_token = hash.delete('oauth_token') || hash.delete(:oauth_token)
  oauth_token_secret = hash.delete('oauth_token_secret') ||
                       hash.delete(:oauth_token_secret)
  new(client, provider, access_token, oauth_token, oauth_token_secret,
      hash)
end

Instance Method Details

#meObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/oauthio/access_token.rb', line 29

def me
  k = @client.id
  # oauthv = 1  # TODO: Update this

  if !@token.empty?
    # oauthv=#{oauthv}
    oauthio_header = "k=#{k}&access_token=#{@token}"
  elsif !@oauth_token.empty? && !@oauth_token_secret.empty?
    # oauthv=#{oauthv}
    oauthio_header = "k=#{k}&oauth_token=#{@oauth_token}&" +
                     "oauth_token_secret=#{@oauth_token_secret}"
  else
    # TODO: Throw error if no tokens found
  end
  opts = {:headers => {:oauthio => oauthio_header}}
  me_url = client.me_url(provider)
  request(:get, me_url, opts)
end