Class: PT::Client
- Inherits:
-
Object
- Object
- PT::Client
- Defined in:
- lib/pt/client.rb
Constant Summary collapse
- STORY_FIELDS =
':default,requested_by,owners,tasks,comments(:default,person,file_attachments)'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #add_label(task, label) ⇒ Object
- #assign_task(task, owner) ⇒ Object
- #comment_task(task, comment) ⇒ Object
- #create_story(args) ⇒ Object
- #current_page(limit = nil) ⇒ Object
- #estimate_story(task, points) ⇒ Object
- #find_member(query) ⇒ Object
- #get_activities ⇒ Object
- #get_current_iteration(project) ⇒ Object
- #get_member(query) ⇒ Object
- #get_members ⇒ Object
- #get_membership(email) ⇒ Object
- #get_my_info ⇒ Object
- #get_my_open_tasks(params = {}) ⇒ Object
- #get_my_work ⇒ Object
- #get_project(project_id) ⇒ Object
- #get_projects ⇒ Object
- #get_stories(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_task_by_id(id) ⇒ Object (also: #get_story)
- #get_work ⇒ Object
-
#initialize(token, local_config = nil) ⇒ Client
constructor
A new instance of Client.
- #mark_task_as(task, state) ⇒ Object
- #search_for_story(query, params = {}) ⇒ Object
- #total_page(limit = nil) ⇒ Object
Constructor Details
#initialize(token, local_config = nil) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 |
# File 'lib/pt/client.rb', line 18 def initialize(token, local_config=nil) @client = TrackerApi::Client.new(token: token) @config = local_config @project = @client.project(local_config[:project_id]) if local_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/pt/client.rb', line 10 def config @config end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
10 11 12 |
# File 'lib/pt/client.rb', line 10 def project @project end |
Class Method Details
.get_api_token(email, password) ⇒ Object
12 13 14 15 16 |
# File 'lib/pt/client.rb', line 12 def self.get_api_token(email, password) PivotalAPI::Me.retrieve(email, password) rescue RestClient:: raise PT::InputError.new("Bad email/password combination.") end |
Instance Method Details
#add_label(task, label) ⇒ Object
163 164 165 166 167 |
# File 'lib/pt/client.rb', line 163 def add_label(task, label) task = get_story(task.id) task.add_label(label) task.save end |
#assign_task(task, owner) ⇒ Object
158 159 160 161 |
# File 'lib/pt/client.rb', line 158 def assign_task(task, owner) task = get_story(task.id) task.add_owner(owner) end |
#comment_task(task, comment) ⇒ Object
169 170 171 172 |
# File 'lib/pt/client.rb', line 169 def comment_task(task, comment) task = get_story(task.id) task.create_comment(text: comment) end |
#create_story(args) ⇒ Object
174 175 176 |
# File 'lib/pt/client.rb', line 174 def create_story(args) project.create_story(args) end |
#current_page(limit = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/pt/client.rb', line 30 def current_page(limit=nil) limit ||= @config[:limit] 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
152 153 154 155 156 |
# File 'lib/pt/client.rb', line 152 def estimate_story(task, points) task = get_story(task.id) task.estimate = points task.save end |
#find_member(query) ⇒ Object
135 136 137 138 139 |
# File 'lib/pt/client.rb', line 135 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_activities ⇒ Object
58 59 60 |
# File 'lib/pt/client.rb', line 58 def get_activities project.activity end |
#get_current_iteration(project) ⇒ Object
54 55 56 |
# File 'lib/pt/client.rb', line 54 def get_current_iteration(project) PivotalTracker::Iteration.current(project) end |
#get_member(query) ⇒ Object
130 131 132 133 |
# File 'lib/pt/client.rb', line 130 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
141 142 143 |
# File 'lib/pt/client.rb', line 141 def get_members project.memberships fields: ':default,person' end |
#get_membership(email) ⇒ Object
46 47 48 |
# File 'lib/pt/client.rb', line 46 def get_membership(email) PivotalTracker::Membership.all(project).select{ |m| m.email == email }.first end |
#get_my_info ⇒ Object
50 51 52 |
# File 'lib/pt/client.rb', line 50 def get_my_info @client.me end |
#get_my_open_tasks(params = {}) ⇒ Object
80 81 82 83 |
# File 'lib/pt/client.rb', line 80 def get_my_open_tasks(params={}) params[:filter] = "owner:#{config[:user_name]}" get_stories(params) end |
#get_my_work ⇒ Object
66 67 68 |
# File 'lib/pt/client.rb', line 66 def get_my_work project.stories(filter: "owner:#{config[:user_name]} -state:accepted", limit: 50, fields: STORY_FIELDS) end |
#get_project(project_id) ⇒ Object
37 38 39 40 |
# File 'lib/pt/client.rb', line 37 def get_project(project_id) project = @client.project(project_id) project end |
#get_projects ⇒ Object
42 43 44 |
# File 'lib/pt/client.rb', line 42 def get_projects @client.projects end |
#get_stories(params = {}) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/pt/client.rb', line 121 def get_stories(params={}) limit = params[:limit] || config[:limit] || 10 page = params[:page] || 1 offset = (page-1)*limit filter = params[:filter] || '-state=accepted' project.stories limit: limit, fields: STORY_FIELDS, auto_paginate: false, offset: offset, filter: filter end |
#get_stories_to_accept(params = {}) ⇒ Object
106 107 108 109 |
# File 'lib/pt/client.rb', line 106 def get_stories_to_accept(params={}) params[:filter] = "owner:#{config[:user_name]} -state:accepted" get_stories(params) end |
#get_stories_to_assign(params = {}) ⇒ Object
116 117 118 119 |
# File 'lib/pt/client.rb', line 116 def get_stories_to_assign(params={}) params[:filter] = "-state:accepted" get_stories(params) end |
#get_stories_to_deliver(params = {}) ⇒ Object
101 102 103 104 |
# File 'lib/pt/client.rb', line 101 def get_stories_to_deliver(params={}) params[:filter] = "owner:#{config[:user_name]} -state:delivered,accepted,rejected" get_stories(params) end |
#get_stories_to_estimate(params = {}) ⇒ Object
85 86 87 88 |
# File 'lib/pt/client.rb', line 85 def get_stories_to_estimate(params={}) params[:filter] = "owner:#{config[:user_name]} type:feature estimate:-1" get_stories(params) end |
#get_stories_to_finish(params = {}) ⇒ Object
96 97 98 99 |
# File 'lib/pt/client.rb', line 96 def get_stories_to_finish(params={}) params[:filter] = "owner:#{config[:user_name]} -state:unscheduled,rejected" get_stories(params) end |
#get_stories_to_reject(params = {}) ⇒ Object
111 112 113 114 |
# File 'lib/pt/client.rb', line 111 def get_stories_to_reject(params={}) params[:filter] = "owner:#{config[:user_name]} -state:rejected" get_stories(params) end |
#get_stories_to_start(params = {}) ⇒ Object
90 91 92 93 94 |
# File 'lib/pt/client.rb', line 90 def get_stories_to_start(params={}) params[:filter] = "owner:#{config[:user_name]} type:feature,bug state:unscheduled,rejected,unstarted" tasks = get_stories(params) tasks.reject{ |t| (t.story_type == 'feature') && (!t.estimate) } end |
#get_task_by_id(id) ⇒ Object Also known as: get_story
75 76 77 |
# File 'lib/pt/client.rb', line 75 def get_task_by_id(id) project.story(id, fields: STORY_FIELDS) end |
#get_work ⇒ Object
62 63 64 |
# File 'lib/pt/client.rb', line 62 def get_work project.stories(filter: 'state:unscheduled,unstarted,started', fields: STORY_FIELDS ) end |
#mark_task_as(task, state) ⇒ Object
146 147 148 149 150 |
# File 'lib/pt/client.rb', line 146 def mark_task_as(task, state) task = get_story(task.id) task.current_state = state task.save end |
#search_for_story(query, params = {}) ⇒ Object
70 71 72 73 |
# File 'lib/pt/client.rb', line 70 def search_for_story(query, params={}) params[:filter] = "#{query}" get_stories(params) end |
#total_page(limit = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/pt/client.rb', line 24 def total_page(limit=nil) limit ||= @config[:limit] @total_record = @client.last_response.env.response_headers["X-Tracker-Pagination-Total"] @total_record ? (@total_record.to_f/limit).ceil : 1 end |