Class: APIClient
- Inherits:
-
Object
- Object
- APIClient
- Defined in:
- lib/jira/worklog/api_client.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#url_base ⇒ Object
readonly
Returns the value of attribute url_base.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #add_worklog(worklog) ⇒ Object
- #delete_worklog(issue, worklog_id) ⇒ Object
-
#initialize(url_base, user, password) ⇒ APIClient
constructor
A new instance of APIClient.
- #issues ⇒ Object
- #worklogs(issue) ⇒ Object
Constructor Details
#initialize(url_base, user, password) ⇒ APIClient
Returns a new instance of APIClient.
4 5 6 7 8 |
# File 'lib/jira/worklog/api_client.rb', line 4 def initialize(url_base, user, password) @user = user @password = password @url_base = url_base end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
2 3 4 |
# File 'lib/jira/worklog/api_client.rb', line 2 def password @password end |
#url_base ⇒ Object (readonly)
Returns the value of attribute url_base.
2 3 4 |
# File 'lib/jira/worklog/api_client.rb', line 2 def url_base @url_base end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
2 3 4 |
# File 'lib/jira/worklog/api_client.rb', line 2 def user @user end |
Instance Method Details
#add_worklog(worklog) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jira/worklog/api_client.rb', line 20 def add_worklog(worklog) req = { comment: worklog[:comment], started: worklog[:date].strftime('%Y-%m-%d') + 'T07:00:00.000+0100', timeSpentSeconds: worklog[:duration] } data = post_request("issue/#{worklog[:issue]}/worklog", req.to_json) # puts "added: #{worklog.inspect}" data['id'] end |
#delete_worklog(issue, worklog_id) ⇒ Object
16 17 18 |
# File 'lib/jira/worklog/api_client.rb', line 16 def delete_worklog(issue, worklog_id) delete_request("issue/#{issue}/worklog/#{worklog_id}") end |
#issues ⇒ Object
11 12 13 14 |
# File 'lib/jira/worklog/api_client.rb', line 11 def issues data = request("search?jql=assignee=#{user}") data['issues'].map { |issue| {key: issue['key'], id: issue['id'], summary: issue['fields']['summary']} } end |
#worklogs(issue) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jira/worklog/api_client.rb', line 32 def worklogs(issue) data = request("issue/#{issue}/worklog") # pp data data['worklogs'].map { |worklog| { duration: worklog['timeSpentSeconds'], comment: worklog['comment'], issue_id: worklog['issueId'], id: worklog['id'], date: Date.strptime(worklog['started'][0..9], '%Y-%m-%d') } } end |