Class: Rnote::AuthCache

Inherits:
Object
  • Object
show all
Includes:
ConfigFile
Defined in:
lib/rnote/persister.rb

Instance Method Summary collapse

Methods included from ConfigFile

#modify_config, #read_config

Constructor Details

#initializeAuthCache

Returns a new instance of AuthCache.



68
69
70
# File 'lib/rnote/persister.rb', line 68

def initialize
  @config_file = AUTH_FILE
end

Instance Method Details

#after_vivifyObject



84
85
86
# File 'lib/rnote/persister.rb', line 84

def after_vivify
  FileUtils.chmod 0600, AUTH_FILE
end

#forget_developer_tokenObject



119
120
121
122
123
# File 'lib/rnote/persister.rb', line 119

def forget_developer_token
  modify_config do |config|
    config.delete(:developer_token)
  end
end

#forget_sandboxObject



188
189
190
191
192
# File 'lib/rnote/persister.rb', line 188

def forget_sandbox
  modify_config do |config|
    config.delete(:sandbox)
  end
end

#forget_user_tokenObject



107
108
109
110
111
# File 'lib/rnote/persister.rb', line 107

def forget_user_token
  modify_config do |config|
    config.delete(:user_token)
  end
end

#forget_usernameObject



113
114
115
116
117
# File 'lib/rnote/persister.rb', line 113

def forget_username
  modify_config do |config|
    config.delete(:username)
  end
end

#get_consumer_keyObject



149
150
151
152
153
154
155
156
157
# File 'lib/rnote/persister.rb', line 149

def get_consumer_key
  read_config do |config|
    if config[:consumer_key].nil?
      raise "no consumer key saved"
    else
      config[:consumer_key]
    end
  end
end

#get_consumer_secretObject



159
160
161
162
163
164
165
166
167
# File 'lib/rnote/persister.rb', line 159

def get_consumer_secret
  read_config do |config|
    if config[:consumer_secret].nil?
      raise "noc consumer secret saved"
    else
      config[:consumer_secret]
    end
  end
end

#get_developer_tokenObject



137
138
139
140
141
# File 'lib/rnote/persister.rb', line 137

def get_developer_token
  read_config do |config|
    config[:developer_token]
  end
end

#get_sandboxObject



143
144
145
146
147
# File 'lib/rnote/persister.rb', line 143

def get_sandbox
  read_config do |config|
    config[:sandbox]
  end
end

#get_user_tokenObject



125
126
127
128
129
# File 'lib/rnote/persister.rb', line 125

def get_user_token
  read_config do |config|
    config[:user_token]
  end
end

#get_usernameObject



131
132
133
134
135
# File 'lib/rnote/persister.rb', line 131

def get_username
  read_config do |config|
    config[:username]
  end
end

#headerObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rnote/persister.rb', line 72

def header
  <<EOF
  
#
# This file is auto-generated and shouldn't be edited by hand
#
# deleting this file is akin to logging out.
#

EOF
end

#persist_consumer_key(consumer_key) ⇒ Object



176
177
178
179
180
# File 'lib/rnote/persister.rb', line 176

def persist_consumer_key(consumer_key)
  modify_config do|config|
    config[:consumer_key] = consumer_key
  end
end

#persist_consumer_secret(consumer_secret) ⇒ Object



182
183
184
185
186
# File 'lib/rnote/persister.rb', line 182

def persist_consumer_secret(consumer_secret)
  modify_config do |config|
    config[:consumer_secret] = consumer_secret
  end
end

#persist_developer_token(developer_token) ⇒ Object



101
102
103
104
105
# File 'lib/rnote/persister.rb', line 101

def persist_developer_token(developer_token)
  modify_config do |config|
    config[:developer_token] = developer_token
  end
end

#persist_sandbox(sandbox) ⇒ Object



169
170
171
172
173
174
# File 'lib/rnote/persister.rb', line 169

def persist_sandbox(sandbox)
  raise if ! sandbox and RNOTE_SANDBOX_ONLY
  modify_config do |config|
    config[:sandbox] = sandbox
  end
end

#persist_user_token(user_token) ⇒ Object



95
96
97
98
99
# File 'lib/rnote/persister.rb', line 95

def persist_user_token(user_token)
  modify_config do |config|
    config[:user_token] = user_token
  end
end

#persist_username(username) ⇒ Object



88
89
90
91
92
# File 'lib/rnote/persister.rb', line 88

def persist_username(username)
  modify_config do |config|
    config[:username] = username
  end
end