Class: Redlink::Configuration

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

Constant Summary collapse

CONFIG_FILE =
'~/.redlink'

Class Method Summary collapse

Class Method Details

.app_tokenObject



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

def self.app_token
  config_file['app_token']
end

.app_token=(val) ⇒ Object



11
12
13
14
# File 'lib/redlink/configuration.rb', line 11

def self.app_token=(val)
  self.config_file['app_token'] = val
  save
end

.clear!Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/redlink/configuration.rb', line 67

def self.clear!
  new_config = @config_file.dup

  [:session_id, :session_id_expires, :user, :username, :password].each do |k|
    new_config.delete(k.to_s)
  end

  @config_file = new_config
  self.save
end

.passwordObject



50
51
52
# File 'lib/redlink/configuration.rb', line 50

def self.password
  config_file['password']
end

.password=(val) ⇒ Object



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

def self.password=(val)
  config_file['password'] = val
end

.saveObject



58
59
60
61
62
63
64
65
# File 'lib/redlink/configuration.rb', line 58

def self.save
  File.open(File.expand_path(CONFIG_FILE), 'w+') do |f|
    f.write YAML.dump(@config_file)
  end

  # reset to force reload next time a read happens
  @config_file = nil
end

.session_expired?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/redlink/configuration.rb', line 29

def self.session_expired?
  return true unless config_file['session_id_expires']
  config_file['session_id_expires'] < Time.now
end

.session_idObject



16
17
18
# File 'lib/redlink/configuration.rb', line 16

def self.session_id
  config_file['session_id']
end

.session_id=(val) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/redlink/configuration.rb', line 20

def self.session_id=(val)
  config_file['session_id'] = val
  if val
    config_file['session_id_expires'] = Time.now + 3600 # one hour from now
  else
    config_file['session_id_expires'] = nil
  end
end

.userObject



34
35
36
# File 'lib/redlink/configuration.rb', line 34

def self.user
  config_file['user']
end

.user=(val) ⇒ Object



38
39
40
# File 'lib/redlink/configuration.rb', line 38

def self.user=(val)
  config_file['user'] = val
end

.usernameObject



42
43
44
# File 'lib/redlink/configuration.rb', line 42

def self.username
  config_file['username']
end

.username=(val) ⇒ Object



46
47
48
# File 'lib/redlink/configuration.rb', line 46

def self.username=(val)
  config_file['username'] = val
end