Class: RedboothRuby::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/redbooth-ruby/session.rb

Constant Summary collapse

OAUTH_URLS =
{
    :site => 'https://redbooth.com/api/3',
    :authorize_url => 'https://redbooth.com/oauth2/authorize',
    :token_url => 'https://redbooth.com/oauth2/token'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Session

Returns a new instance of Session.



16
17
18
19
20
21
22
# File 'lib/redbooth-ruby/session.rb', line 16

def initialize(opts = {})
  @token = opts[:token]
  @consumer_key = opts[:consumer_key] || RedboothRuby.configuration[:consumer_key]
  @consumer_secret = opts[:consumer_secret] || RedboothRuby.configuration[:consumer_secret]
  @oauth_verifier = opts[:oauth_verifier]
  @oauth_token = opts[:oauth_token]
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/redbooth-ruby/session.rb', line 6

def access_token
  @access_token
end

#consumer_keyObject

Returns the value of attribute consumer_key.



7
8
9
# File 'lib/redbooth-ruby/session.rb', line 7

def consumer_key
  @consumer_key
end

#consumer_secretObject

Returns the value of attribute consumer_secret.



7
8
9
# File 'lib/redbooth-ruby/session.rb', line 7

def consumer_secret
  @consumer_secret
end

#oauth_tokenObject

Returns the value of attribute oauth_token.



8
9
10
# File 'lib/redbooth-ruby/session.rb', line 8

def oauth_token
  @oauth_token
end

#oauth_verifierObject

Returns the value of attribute oauth_verifier.



8
9
10
# File 'lib/redbooth-ruby/session.rb', line 8

def oauth_verifier
  @oauth_verifier
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



6
7
8
# File 'lib/redbooth-ruby/session.rb', line 6

def refresh_token
  @refresh_token
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/redbooth-ruby/session.rb', line 6

def token
  @token
end

Instance Method Details

#clientObject



29
30
31
# File 'lib/redbooth-ruby/session.rb', line 29

def client
  @client ||= OAuth2::Client.new(consumer_key, consumer_secret, OAUTH_URLS)
end

#get_access_token_urlObject



33
34
35
36
37
# File 'lib/redbooth-ruby/session.rb', line 33

def get_access_token_url
  url = OAUTH_URLS[:request_token_url]
  url += "?oauth_verifier=#{oauth_verifier}" if oauth_verifier
  url += "&oauth_token=#{oauth_token}" if oauth_token
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/redbooth-ruby/session.rb', line 24

def valid?
  return false unless token
  true
end