Class: Cxeed::Credential
- Inherits:
-
Object
- Object
- Cxeed::Credential
- Defined in:
- lib/cxeed/credential.rb
Constant Summary collapse
- CREDENTIAL_FILE_PATH =
'~/.cxeed'
Instance Attribute Summary collapse
-
#company_code ⇒ Object
Returns the value of attribute company_code.
-
#employee_code ⇒ Object
Returns the value of attribute employee_code.
-
#login_url ⇒ Object
Returns the value of attribute login_url.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
-
#initialize(filename = CREDENTIAL_FILE_PATH) ⇒ Credential
constructor
A new instance of Credential.
- #store ⇒ Object
- #to_json ⇒ Object
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.(filename)) json = open(File.(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_code ⇒ Object
Returns the value of attribute company_code.
7 8 9 |
# File 'lib/cxeed/credential.rb', line 7 def company_code @company_code end |
#employee_code ⇒ Object
Returns the value of attribute employee_code.
7 8 9 |
# File 'lib/cxeed/credential.rb', line 7 def employee_code @employee_code end |
#login_url ⇒ Object
Returns the value of attribute login_url.
7 8 9 |
# File 'lib/cxeed/credential.rb', line 7 def login_url @login_url end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/cxeed/credential.rb', line 7 def password @password end |
Instance Method Details
#store ⇒ Object
27 28 29 30 31 |
# File 'lib/cxeed/credential.rb', line 27 def store File.open(File.(CREDENTIAL_FILE_PATH), 'w', 0600) do |file| file.puts self.to_json end end |
#to_json ⇒ Object
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 |