Class: PT::Client
- Inherits:
-
Object
- Object
- PT::Client
- Defined in:
- lib/pt/client.rb
Constant Summary collapse
- STORY_FIELDS =
':default,requested_by(initials),owners(initials),tasks(complete,description),comments(text,file_attachment_ids,person(initials))'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#total_record ⇒ Object
readonly
Returns the value of attribute total_record.
Instance Method Summary collapse
- #add_label(task, label) ⇒ Object
- #assign_story(story, owner) ⇒ Object
- #comment_task(story, comment) ⇒ Object
- #create_story(args) ⇒ Object
- #current_page ⇒ Object
- #estimate_story(task, points) ⇒ Object
- #find_member(query) ⇒ Object
- #get_member(query) ⇒ Object
- #get_members ⇒ Object
- #get_stories(params = {}) ⇒ Object
- #get_stories_from_iteration(params = {}) ⇒ Object
- #get_stories_to_accept(params = {}) ⇒ Object
- #get_stories_to_assign(params = {}) ⇒ Object
- #get_stories_to_deliver(params = {}) ⇒ Object
- #get_stories_to_estimate(params = {}) ⇒ Object
- #get_stories_to_finish(params = {}) ⇒ Object
- #get_stories_to_reject(params = {}) ⇒ Object
- #get_stories_to_start(params = {}) ⇒ Object
- #get_stories_to_unstart(params = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #mark_task_as(task, state) ⇒ Object
- #project ⇒ Object
- #total_page ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/pt/client.rb', line 12 def initialize @client = TrackerApi::Client.new(token: Settings[:pivotal_api_key]) @limit = Settings[:limit] || 10 end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/pt/client.rb', line 10 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/pt/client.rb', line 10 def config @config end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
10 11 12 |
# File 'lib/pt/client.rb', line 10 def limit @limit end |
#total_record ⇒ Object (readonly)
Returns the value of attribute total_record.
10 11 12 |
# File 'lib/pt/client.rb', line 10 def total_record @total_record end |
Instance Method Details
#add_label(task, label) ⇒ Object
119 120 121 122 |
# File 'lib/pt/client.rb', line 119 def add_label(task, label) task.add_label(label) task.save end |
#assign_story(story, owner) ⇒ Object
114 115 116 117 |
# File 'lib/pt/client.rb', line 114 def assign_story(story, owner) story.add_owner(owner) story.save end |
#comment_task(story, comment) ⇒ Object
124 125 126 |
# File 'lib/pt/client.rb', line 124 def comment_task(story, comment) story.create_comment(text: comment) end |
#create_story(args) ⇒ Object
128 129 130 |
# File 'lib/pt/client.rb', line 128 def create_story(args) project.create_story(args) end |
#current_page ⇒ Object
22 23 24 25 |
# File 'lib/pt/client.rb', line 22 def current_page offset = @client.last_response.env.response_headers["X-Tracker-Pagination-Offset"] offset ? ((offset.to_f/limit)+1).to_i.ceil : 1 end |
#estimate_story(task, points) ⇒ Object
109 110 111 112 |
# File 'lib/pt/client.rb', line 109 def estimate_story(task, points) task.estimate = points task.save end |
#find_member(query) ⇒ Object
93 94 95 96 97 |
# File 'lib/pt/client.rb', line 93 def find_member(query) project.memberships.detect do |m| m.person.name.downcase.start_with?(query.downcase) || m.person.initials.downcase == query.downcase end end |
#get_member(query) ⇒ Object
88 89 90 91 |
# File 'lib/pt/client.rb', line 88 def get_member(query) member = project.memberships.select{ |m| m.person.name.downcase.start_with?(query.downcase) || m.person.initials.downcase == query.downcase } member.empty? ? nil : member.first end |
#get_members ⇒ Object
99 100 101 |
# File 'lib/pt/client.rb', line 99 def get_members project.memberships fields: ':default,person' end |
#get_stories(params = {}) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/pt/client.rb', line 72 def get_stories(params={}) limit = @limit || 10 page = params[:page] || 0 offset = page*limit filter = params[:filter] || '-state=accepted' project.stories limit: limit, fields: STORY_FIELDS, auto_paginate: false, offset: offset, filter: filter end |
#get_stories_from_iteration(params = {}) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/pt/client.rb', line 80 def get_stories_from_iteration(params={}) page = params[:page] || 0 puts "page #{page}" scope = params[:scope] || 'current' project.iterations(scope: scope, fields: ":default,stories(#{STORY_FIELDS})")[page]&.stories || [] end |
#get_stories_to_accept(params = {}) ⇒ Object
57 58 59 60 |
# File 'lib/pt/client.rb', line 57 def get_stories_to_accept(params={}) params[:filter] = "owner:#{Settings[:user_name]} -state:accepted" get_stories(params) end |
#get_stories_to_assign(params = {}) ⇒ Object
67 68 69 70 |
# File 'lib/pt/client.rb', line 67 def get_stories_to_assign(params={}) params[:filter] = "-state:accepted" get_stories(params) end |
#get_stories_to_deliver(params = {}) ⇒ Object
52 53 54 55 |
# File 'lib/pt/client.rb', line 52 def get_stories_to_deliver(params={}) params[:filter] = "owner:#{Settings[:user_name]} -state:delivered,accepted,rejected" get_stories(params) end |
#get_stories_to_estimate(params = {}) ⇒ Object
31 32 33 34 |
# File 'lib/pt/client.rb', line 31 def get_stories_to_estimate(params={}) params[:filter] = "owner:#{Settings[:user_name]} type:feature estimate:-1" get_stories(params) end |
#get_stories_to_finish(params = {}) ⇒ Object
47 48 49 50 |
# File 'lib/pt/client.rb', line 47 def get_stories_to_finish(params={}) params[:filter] = "owner:#{Settings[:user_name]} -state:unscheduled,rejected" get_stories(params) end |
#get_stories_to_reject(params = {}) ⇒ Object
62 63 64 65 |
# File 'lib/pt/client.rb', line 62 def get_stories_to_reject(params={}) params[:filter] = "owner:#{Settings[:user_name]} -state:rejected" get_stories(params) end |
#get_stories_to_start(params = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/pt/client.rb', line 41 def get_stories_to_start(params={}) params[:filter] = "owner:#{Settings[:user_name]} type:feature,bug state:unscheduled,rejected,unstarted" tasks = get_stories(params) tasks.reject{ |t| (t.story_type == 'feature') && (!t.estimate) } end |
#get_stories_to_unstart(params = {}) ⇒ Object
36 37 38 39 |
# File 'lib/pt/client.rb', line 36 def get_stories_to_unstart(params={}) params[:filter] = "owner:#{Settings[:user_name]} -state:unstarted" get_stories(params) end |
#mark_task_as(task, state) ⇒ Object
104 105 106 107 |
# File 'lib/pt/client.rb', line 104 def mark_task_as(task, state) task.current_state = state task.save end |
#project ⇒ Object
27 28 29 |
# File 'lib/pt/client.rb', line 27 def project @client.project(Settings[:project_id]) end |
#total_page ⇒ Object
17 18 19 20 |
# File 'lib/pt/client.rb', line 17 def total_page @total_record = @client.last_response.env.response_headers["X-Tracker-Pagination-Total"] @total_record ? (@total_record.to_f/limit).ceil : 1 end |