Class: Gliffy::Credentials

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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, , 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 .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 = 
  @default_protocol = default_protocol
end

Instance Attribute Details

#access_tokenObject (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_idObject (readonly)

Returns the value of attribute account_id.



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

def 
  @account_id
end

#consumer_keyObject (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_secretObject (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_protocolObject (readonly)

Returns the value of attribute default_protocol.



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

def default_protocol
  @default_protocol
end

#descriptionObject (readonly)

Returns the value of attribute description.



30
31
32
# File 'lib/gliffy/credentials.rb', line 30

def description
  @description
end

#usernameObject (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_tokenObject

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

Returns:

  • (Boolean)


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

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)



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