Class: Jirack::Credential

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

Constant Summary collapse

CREDENTIAL_FILE_PATH =
'~/.jirack'

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(filename))
    json = open(File.expand_path(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

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/jirack/credential.rb', line 8

def host
  @host
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/jirack/credential.rb', line 8

def password
  @password
end

#project_nameObject

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_urlObject

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

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/jirack/credential.rb', line 8

def username
  @username
end

#workflow_idsObject

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

#domainObject



37
38
39
# File 'lib/jirack/credential.rb', line 37

def domain
  "https://#{ @host }"
end

#jira_clientObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jirack/credential.rb', line 41

def jira_client
  client_options = {
    :username => @username,
    :password => @password,
    :site     => domain,
    :context_path => '',
    :auth_type => :basic,
    :read_timeout => 120
  }

  JIRA::Client.new(client_options)
end

#storeObject



31
32
33
34
35
# File 'lib/jirack/credential.rb', line 31

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

#to_jsonObject



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