Class: Jirack::Credential
- Inherits:
-
Object
- Object
- Jirack::Credential
- Defined in:
- lib/jirack/credential.rb
Constant Summary collapse
- CREDENTIAL_FILE_PATH =
'~/.jirack'
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#slack_webhook_url ⇒ Object
Returns the value of attribute slack_webhook_url.
-
#username ⇒ Object
Returns the value of attribute username.
-
#workflow_ids ⇒ Object
Returns the value of attribute workflow_ids.
Instance Method Summary collapse
- #domain ⇒ Object
-
#initialize(filename = CREDENTIAL_FILE_PATH) ⇒ Credential
constructor
A new instance of Credential.
- #jira_client ⇒ Object
- #store ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(filename = CREDENTIAL_FILE_PATH) ⇒ Credential
Returns a new instance of Credential.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jirack/credential.rb', line 12 def initialize(filename = CREDENTIAL_FILE_PATH) if File.exists?(File.(filename)) json = open(File.(filename)) {|io| JSON.load(io) } @username = json['username'] @host = json['host'] @project_name = json['project_name'] @workflow_ids = json['workflow_ids'] @password = json['password'] @slack_webhook_url = json['slack_webhook_url'] end end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/jirack/credential.rb', line 8 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/jirack/credential.rb', line 8 def password @password end |
#project_name ⇒ Object
Returns the value of attribute project_name.
8 9 10 |
# File 'lib/jirack/credential.rb', line 8 def project_name @project_name end |
#slack_webhook_url ⇒ Object
Returns the value of attribute slack_webhook_url.
8 9 10 |
# File 'lib/jirack/credential.rb', line 8 def slack_webhook_url @slack_webhook_url end |
#username ⇒ Object
Returns the value of attribute username.
8 9 10 |
# File 'lib/jirack/credential.rb', line 8 def username @username end |
#workflow_ids ⇒ Object
Returns the value of attribute workflow_ids.
8 9 10 |
# File 'lib/jirack/credential.rb', line 8 def workflow_ids @workflow_ids end |
Instance Method Details
#domain ⇒ Object
37 38 39 |
# File 'lib/jirack/credential.rb', line 37 def domain "https://#{ @host }" end |
#jira_client ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jirack/credential.rb', line 41 def jira_client = { :username => @username, :password => @password, :site => domain, :context_path => '', :auth_type => :basic, :read_timeout => 120 } JIRA::Client.new() end |
#store ⇒ Object
31 32 33 34 35 |
# File 'lib/jirack/credential.rb', line 31 def store File.open(File.(CREDENTIAL_FILE_PATH), 'w', 0600) do |file| file.puts self.to_json end end |
#to_json ⇒ Object
24 25 26 27 28 29 |
# File 'lib/jirack/credential.rb', line 24 def to_json hash = {} instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) } hash['workflow_ids'] = [1, 3, 10_603, 10_600, 10_604, 10_001] hash.to_json end |