Sha256: 642810808f7a3b0caf23f4b494d06aa1291db05fd56af3cfb7388ae4ccac8040

Contents?: true

Size: 854 Bytes

Versions: 8

Compression:

Stored size: 854 Bytes

Contents

# frozen_string_literal: true
require 'json'

module Cxeed
  class Credential

    attr_accessor :login_url, :company_code, :employee_code, :password

    CREDENTIAL_FILE_PATH = '~/.cxeed'

    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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cxeed-0.3.7 lib/cxeed/credential.rb
cxeed-0.3.6 lib/cxeed/credential.rb
cxeed-0.3.5 lib/cxeed/credential.rb
cxeed-0.3.4 lib/cxeed/credential.rb
cxeed-0.3.2 lib/cxeed/credential.rb
cxeed-0.3.1 lib/cxeed/credential.rb
cxeed-0.3.0 lib/cxeed/credential.rb
cxeed-0.2.2 lib/cxeed/credential.rb