Class: Cxeed::Credential

Inherits:
Object
  • Object
show all
Defined in:
lib/cxeed/credential.rb

Constant Summary collapse

CREDENTIAL_FILE_PATH =
'~/.cxeed'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = CREDENTIAL_FILE_PATH) ⇒ Credential

Returns a new instance of Credential.



11
12
13
14
15
16
17
18
19
# File 'lib/cxeed/credential.rb', line 11

def initialize(filename = CREDENTIAL_FILE_PATH)
  if File.exists?(File.expand_path(filename))
    json = open(File.expand_path(filename)) {|io| JSON.load(io) }
    @login_url = json['login_url']
    @company_code = json['company_code']
    @employee_code = json['employee_code']
    @password = json['password']
  end
end

Instance Attribute Details

#company_codeObject

Returns the value of attribute company_code.



7
8
9
# File 'lib/cxeed/credential.rb', line 7

def company_code
  @company_code
end

#employee_codeObject

Returns the value of attribute employee_code.



7
8
9
# File 'lib/cxeed/credential.rb', line 7

def employee_code
  @employee_code
end

#login_urlObject

Returns the value of attribute login_url.



7
8
9
# File 'lib/cxeed/credential.rb', line 7

def 
  @login_url
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/cxeed/credential.rb', line 7

def password
  @password
end

Instance Method Details

#storeObject



27
28
29
30
31
# File 'lib/cxeed/credential.rb', line 27

def store
  File.open(File.expand_path(CREDENTIAL_FILE_PATH), 'w', 0600) do |file|
    file.puts self.to_json
  end
end

#to_jsonObject



21
22
23
24
25
# File 'lib/cxeed/credential.rb', line 21

def to_json
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
  hash.to_json
end