Class: Springnote::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/springnote/configuration.rb

Constant Summary collapse

SERVER_URL =
"api.springnote.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_secretObject

Returns the value of attribute access_secret.



8
9
10
# File 'lib/springnote/configuration.rb', line 8

def access_secret
  @access_secret
end

#access_tokenObject

Returns the value of attribute access_token.



8
9
10
# File 'lib/springnote/configuration.rb', line 8

def access_token
  @access_token
end

#app_keyObject



65
66
67
# File 'lib/springnote/configuration.rb', line 65

def app_key
  @app_key
end

#consumer_secretObject

Returns the value of attribute consumer_secret.



7
8
9
# File 'lib/springnote/configuration.rb', line 7

def consumer_secret
  @consumer_secret
end

#consumer_tokenObject

Returns the value of attribute consumer_token.



7
8
9
# File 'lib/springnote/configuration.rb', line 7

def consumer_token
  @consumer_token
end

#domainObject

Returns the value of attribute domain.



9
10
11
# File 'lib/springnote/configuration.rb', line 9

def domain
  @domain
end

#protocolObject

Returns the value of attribute protocol.



9
10
11
# File 'lib/springnote/configuration.rb', line 9

def protocol
  @protocol
end

#user_key=(value) ⇒ Object (writeonly)

deprecated



54
55
56
# File 'lib/springnote/configuration.rb', line 54

def user_key=(value)
  @user_key = value
end

#user_openid=(value) ⇒ Object (writeonly)

Sets the attribute user_openid

Parameters:

  • value

    the value to set the attribute user_openid to.



55
56
57
# File 'lib/springnote/configuration.rb', line 55

def user_openid=(value)
  @user_openid = value
end

Instance Method Details

#consumerObject



49
50
51
# File 'lib/springnote/configuration.rb', line 49

def consumer
  @consumer ||= OAuth::Consumer.new @consumer_token, @consumer_secret, :site => "https://api.openmaru.com" if @consumer_token && @consumer_secret
end

#load(file) ⇒ Object



17
18
19
# File 'lib/springnote/configuration.rb', line 17

def load(file)
  set YAML.load(File.read(file))
end

#passwordObject



61
62
63
# File 'lib/springnote/configuration.rb', line 61

def password
  @user_key ? [@user_key, app_key].join('.') : app_key
end

#set(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/springnote/configuration.rb', line 21

def set(options = {})
  #reset
  @token = nil
  @consumer = nil

  options.each{|k,v| self.send("#{k}=", v)}
  Springnote::Base.site = self.site
  if @app_key && Springnote::Base.respond_to?(:user=)
    Springnote::Base.user = self.username
    Springnote::Base.password = self.password
  end
  self
end

#siteObject



39
40
41
42
43
# File 'lib/springnote/configuration.rb', line 39

def site
  @app_key ? 
    "#{protocol}://#{username}:#{password}@#{SERVER_URL}/" :
    "#{protocol}://#{SERVER_URL}/"
end

#tokenObject



45
46
47
# File 'lib/springnote/configuration.rb', line 45

def token
  @token ||= OAuth::AccessToken.new consumer, @access_token, @access_secret if @access_token && @access_secret
end

#usernameObject



57
58
59
# File 'lib/springnote/configuration.rb', line 57

def username
  CGI.escape(@user_openid || 'anonymous')
end