Class: Crazylegs::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/crazylegs/credentials.rb

Overview

Encapsulates all the information needed to make a request of the server outside of request-specific information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer_key, consumer_secret, default_protocol = :http, access_token = nil) ⇒ Credentials

Create a new Credentials object.

consumer_key

The OAuth consumer key given to you when you signed up

consumer_secret

The OAuth consumer secret given to you when you signed up

default_protocol

Symbol, defaults to :http, set this if you must request via :https

access_token

The access token you were given as a AccessToken, or nil if you don’t have one yet.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
# File 'lib/crazylegs/credentials.rb', line 41

def initialize(consumer_key, consumer_secret, default_protocol=:http, access_token = nil)
  raise ArgumentError.new("consumer_key required") if consumer_key.nil?
  raise ArgumentError.new("consumer_secret required") if consumer_secret.nil?

  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @access_token = access_token
  @default_protocol = default_protocol
end

Instance Attribute Details

#access_tokenObject (readonly)

Access Token you might have acquired



31
32
33
# File 'lib/crazylegs/credentials.rb', line 31

def access_token
  @access_token
end

#consumer_keyObject (readonly)

Consumer key, provided by the service provider



27
28
29
# File 'lib/crazylegs/credentials.rb', line 27

def consumer_key
  @consumer_key
end

#consumer_secretObject (readonly)

Consumer secret, provided by the service provider



29
30
31
# File 'lib/crazylegs/credentials.rb', line 29

def consumer_secret
  @consumer_secret
end

#default_protocolObject (readonly)

The default protocol to use for requests



33
34
35
# File 'lib/crazylegs/credentials.rb', line 33

def default_protocol
  @default_protocol
end

Instance Method Details

#clear_access_tokenObject

Clear the access token if, for some reason, you know the one you have is bad.



64
65
66
# File 'lib/crazylegs/credentials.rb', line 64

def clear_access_token
  update_access_token(nil)
end

#has_access_token?Boolean

True if we have an access token

Returns:

  • (Boolean)


52
53
54
# File 'lib/crazylegs/credentials.rb', line 52

def has_access_token?
  !@access_token.nil?
end

#nonceObject

Return a nonce that hasn’t been used before (at least not in this space/time continuum)



69
70
71
# File 'lib/crazylegs/credentials.rb', line 69

def nonce
  Time.now.to_f.to_s
end

#update_access_token(token) ⇒ Object

Update the access token



57
58
59
60
# File 'lib/crazylegs/credentials.rb', line 57

def update_access_token(token)
  @access_token = token
  @access_token
end