Class: Gliffy::Credentials
- Inherits:
-
Object
- Object
- Gliffy::Credentials
- Defined in:
- lib/gliffy/credentials.rb
Overview
Encapsulates all the information needed to make a request of Gliffy outside of request-specific information.
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#consumer_key ⇒ Object
readonly
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
-
#default_protocol ⇒ Object
readonly
Returns the value of attribute default_protocol.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#clear_access_token ⇒ Object
Clear the access token if, for some reason, you know the one you have is bad.
- #has_access_token? ⇒ Boolean
-
#initialize(consumer_key, consumer_secret, description, account_id, username, default_protocol = :http, access_token = nil) ⇒ Credentials
constructor
Create a new Credentials object.
-
#nonce ⇒ Object
Return a nonce that hasn’t been used before (at least not in this space/time continuum).
-
#update_access_token(token) ⇒ Object
Update the access token.
Constructor Details
#initialize(consumer_key, consumer_secret, description, account_id, username, 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
description
-
Description of the application you are writing
account_id
-
Your account id
username
-
the Gliffy user name/identifier
access_token
-
The access token you were given as a AccessToken, or nil if you don’t have one yet.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gliffy/credentials.rb', line 41 def initialize(consumer_key, consumer_secret, description, account_id, username, 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? raise ArgumentError.new("description required") if description.nil? || description.strip == '' raise ArgumentError.new("account_id required") if account_id.nil? raise ArgumentError.new("username required") if username.nil? @consumer_key = consumer_key @consumer_secret = consumer_secret @username = username @access_token = access_token @description = description @account_id = account_id @default_protocol = default_protocol end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
27 28 29 |
# File 'lib/gliffy/credentials.rb', line 27 def access_token @access_token end |
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
29 30 31 |
# File 'lib/gliffy/credentials.rb', line 29 def account_id @account_id end |
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
25 26 27 |
# File 'lib/gliffy/credentials.rb', line 25 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
26 27 28 |
# File 'lib/gliffy/credentials.rb', line 26 def consumer_secret @consumer_secret end |
#default_protocol ⇒ Object (readonly)
Returns the value of attribute default_protocol.
31 32 33 |
# File 'lib/gliffy/credentials.rb', line 31 def default_protocol @default_protocol end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
30 31 32 |
# File 'lib/gliffy/credentials.rb', line 30 def description @description end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
28 29 30 |
# File 'lib/gliffy/credentials.rb', line 28 def username @username end |
Instance Method Details
#clear_access_token ⇒ Object
Clear the access token if, for some reason, you know the one you have is bad.
69 70 71 |
# File 'lib/gliffy/credentials.rb', line 69 def clear_access_token update_access_token(nil) end |
#has_access_token? ⇒ Boolean
57 58 59 |
# File 'lib/gliffy/credentials.rb', line 57 def has_access_token? !@access_token.nil? end |
#nonce ⇒ Object
Return a nonce that hasn’t been used before (at least not in this space/time continuum)
74 75 76 |
# File 'lib/gliffy/credentials.rb', line 74 def nonce Time.now.to_f.to_s end |
#update_access_token(token) ⇒ Object
Update the access token
62 63 64 65 |
# File 'lib/gliffy/credentials.rb', line 62 def update_access_token(token) @access_token = token @access_token end |