Skip to content

Commit

Permalink
Added project activity endpoint to cover all the activities.
Browse files Browse the repository at this point in the history
  • Loading branch information
forest committed Jan 27, 2015
1 parent 67bc211 commit 012aa7a
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 39 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ $ gem install tracker_api
client = TrackerApi::Client.new(token: 'my-api-token') # Create API client

client.me.email # Get email for the authenticated person
client.my_activity # Get all activities for the authenticated person
client.activity # Get a list of all the activity performed the authenticated person
client.notifications # Get notifications for the authenticated person

projects = client.projects # Get all projects
project = client.project(123456) # Find project with given ID
project.activity # Get a list of all the activity performed on this project

project.stories # Get all stories for a project
project.stories(with_state: :unscheduled, limit: 10) # Get 10 unscheduled stories for a project
project.stories(filter: 'requester:OWK label:"jedi stuff"') # Get all stories that match the given filters
project.create_story(name: 'Destroy death star') # Create a story with the name 'Destroy death star'

story = project.story(847762630) # Find a story with the given ID
story.activity # Get activity on a story
story.activity # Get a list of all the activity performed on this story

story.name = 'Save the Ewoks' # Update a single story attribute
story.attributes = { name: 'Save the Ewoks', description: '...' } # Update multiple story attributes
Expand Down
16 changes: 8 additions & 8 deletions lib/tracker_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ def paginate(path, options = {}, &block)
data
end

# Get my_activity
#
# @param [Hash] params
# @return [Array[TrackerApi::Resources::Activity]]
def my_activity(params={})
Endpoints::Activity.new(self).get(params)
end

# Get projects
#
# @param [Hash] params
Expand Down Expand Up @@ -156,6 +148,14 @@ def notifications(params={})
Endpoints::Notifications.new(self).get(params)
end

# Provides a list of all the activity performed the authenticated person.
#
# @param [Hash] params
# @return [Array[TrackerApi::Resources::Activity]]
def activity(params={})
Endpoints::Activity.new(self).get(params)
end

private

def parse_query_and_convenience_headers(path, options)
Expand Down
13 changes: 11 additions & 2 deletions lib/tracker_api/endpoints/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ def initialize(client)
end

def get(params={})
data = client.paginate("/my/activity", params: params)
data = client.paginate("/my/activity", params: params)
raise TrackerApi::Errors::UnexpectedData, 'Array of activities expected' unless data.is_a? Array

data.map do |activity|
Resources::Activity.new({ client: client }.merge(activity))
end
end

def get_project(project_id, params={})
data = client.paginate("/projects/#{project_id}/activity", params: params)
raise TrackerApi::Errors::UnexpectedData, 'Array of activities expected' unless data.is_a? Array

data.map do |activity|
Expand All @@ -21,7 +30,7 @@ def get_story(project_id, story_id, params={})
raise TrackerApi::Errors::UnexpectedData, 'Array of activities expected' unless data.is_a? Array

data.map do |activity|
Resources::Activity.new({ client: client, project_id: project_id }.merge(activity))
Resources::Activity.new({ client: client }.merge(activity))
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/tracker_api/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def memberships(params = {})
Endpoints::Memberships.new(client).get(id, params)
end

# Provides a list of all the activity performed on a project.
#
# @param [Hash] params
# @return [Array[Activity]]
def activity(params = {})
Endpoints::Activity.new(client).get_project(id, params)
end

# @param [Fixnum] story_id id of story to get
# @return [Story] story with given id
def story(story_id)
Expand Down
2 changes: 2 additions & 0 deletions lib/tracker_api/resources/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def label_list
@label_list ||= labels.collect(&:name).join(',')
end

# Provides a list of all the activity performed on the story.
#
# @param [Hash] params
# @return [Array[Activity]]
def activity(params = {})
Expand Down
50 changes: 25 additions & 25 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,6 @@
client.logger.must_equal LOGGER
end

describe '.my_activity' do
let(:pt_user) { PT_USER_1 }
let(:client) { TrackerApi::Client.new token: pt_user[:token] }

it 'gets all my activities' do
VCR.use_cassette('get my activities', record: :new_episodes) do
activities = client.my_activity(fields: ':default')

activities.wont_be_empty
activity = activities.first
activity.must_be_instance_of TrackerApi::Resources::Activity

activity.changes.wont_be_empty
activity.changes.first.must_be_instance_of TrackerApi::Resources::Change

activity.primary_resources.wont_be_empty
activity.primary_resources.first.must_be_instance_of TrackerApi::Resources::PrimaryResource

activity.project.must_be_instance_of TrackerApi::Resources::Project

activity.performed_by.must_be_instance_of TrackerApi::Resources::Person
end
end
end

describe '.projects' do
let(:pt_user) { PT_USER_1 }
let(:client) { TrackerApi::Client.new token: pt_user[:token] }
Expand Down Expand Up @@ -180,4 +155,29 @@
end
end
end

describe '.activity' do
let(:pt_user) { PT_USER_1 }
let(:client) { TrackerApi::Client.new token: pt_user[:token] }

it 'gets all my activities' do
VCR.use_cassette('get my activities', record: :new_episodes) do
activities = client.activity(fields: ':default')

activities.wont_be_empty
activity = activities.first
activity.must_be_instance_of TrackerApi::Resources::Activity

activity.changes.wont_be_empty
activity.changes.first.must_be_instance_of TrackerApi::Resources::Change

activity.primary_resources.wont_be_empty
activity.primary_resources.first.must_be_instance_of TrackerApi::Resources::PrimaryResource

activity.project.must_be_instance_of TrackerApi::Resources::Project

activity.performed_by.must_be_instance_of TrackerApi::Resources::Person
end
end
end
end
23 changes: 23 additions & 0 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,27 @@
end
end
end

describe '.activity' do
let(:story) { VCR.use_cassette('get unscheduled story') { project.stories(with_state: :unscheduled).first } }

before do
# create some activity
story.name = "#{story.name}+"

VCR.use_cassette('update story to create activity', record: :new_episodes) do
story.save
end
end

it 'gets all the activity for this project' do
VCR.use_cassette('get project activity', record: :new_episodes) do
activity = project.activity

activity.wont_be_empty
event = activity.first
event.must_be_instance_of TrackerApi::Resources::Activity
end
end
end
end
2 changes: 1 addition & 1 deletion test/story_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
end

it 'gets all the activity for this story' do
VCR.use_cassette('get activity', record: :new_episodes) do
VCR.use_cassette('get story activity', record: :new_episodes) do
activity = story.activity

activity.wont_be_empty
Expand Down
1 change: 1 addition & 0 deletions test/vcr/cassettes/get_project_activity.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/vcr/cassettes/get_story_activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/66728004/activity","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.1.5 (x86_64-darwin14.0; ruby) TrackerApi/0.2.6 Faraday/0.9.0"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"]}},"response":{"status":{"code":200,"message":null},"headers":{"Content-Type":["application/json; charset=utf-8"],"Status":["200 OK"],"X-Tracker-Project-Version":["46"],"X-Tracker-Pagination-Total":["2"],"X-Tracker-Pagination-Offset":["0"],"X-Tracker-Pagination-Limit":["100"],"X-Tracker-Pagination-Returned":["2"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"7eb28add246278a7c818baa7c8f9bcae\""],"Cache-Control":["max-age=0, private, must-revalidate"],"X-Request-Id":["8ce630d5c52b5083f222cb1bacf271eb"],"X-Runtime":["0.065811"],"Date":["Tue, 27 Jan 2015 21:28:25 GMT"],"X-Rack-Cache":["miss"],"X-Powered-By":["Phusion Passenger 4.0.41"],"Server":["nginx/1.6.0 + Phusion Passenger 4.0.41"],"Access-Control-Allow-Origin":["*"],"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"X-Tracker-Client-Pinger-Interval":["8"]},"body":{"encoding":"UTF-8","string":"[{\"kind\":\"story_update_activity\",\"guid\":\"1027488_33\",\"project_version\":33,\"message\":\"Tracker API User1 edited this bug\",\"highlight\":\"edited\",\"changes\":[{\"kind\":\"story\",\"change_type\":\"update\",\"id\":66728004,\"original_values\":{\"description\":null,\"updated_at\":\"2015-01-20T06:12:06Z\"},\"new_values\":{\"description\":\"+\",\"updated_at\":\"2015-01-20T06:24:29Z\"},\"name\":\"Some product photos not scaled properly when browsing products+\",\"story_type\":\"bug\"}],\"primary_resources\":[{\"kind\":\"story\",\"id\":66728004,\"name\":\"Some product photos not scaled properly when browsing products+\",\"story_type\":\"bug\",\"url\":\"https://www.pivotaltracker.com/story/show/66728004\"}],\"project\":{\"kind\":\"project\",\"id\":1027488,\"name\":\"My Sample Project\"},\"performed_by\":{\"kind\":\"person\",\"id\":1266314,\"name\":\"Tracker API User1\",\"initials\":\"TU1\"},\"occurred_at\":\"2015-01-20T06:24:29Z\"},{\"kind\":\"story_update_activity\",\"guid\":\"1027488_32\",\"project_version\":32,\"message\":\"Tracker API User1 edited this bug\",\"highlight\":\"edited\",\"changes\":[{\"kind\":\"story\",\"change_type\":\"update\",\"id\":66728004,\"original_values\":{\"name\":\"Some product photos not scaled properly when browsing products\",\"updated_at\":\"2014-06-02T12:44:52Z\"},\"new_values\":{\"name\":\"Some product photos not scaled properly when browsing products+\",\"updated_at\":\"2015-01-20T06:12:06Z\"},\"name\":\"Some product photos not scaled properly when browsing products+\",\"story_type\":\"bug\"}],\"primary_resources\":[{\"kind\":\"story\",\"id\":66728004,\"name\":\"Some product photos not scaled properly when browsing products+\",\"story_type\":\"bug\",\"url\":\"https://www.pivotaltracker.com/story/show/66728004\"}],\"project\":{\"kind\":\"project\",\"id\":1027488,\"name\":\"My Sample Project\"},\"performed_by\":{\"kind\":\"person\",\"id\":1266314,\"name\":\"Tracker API User1\",\"initials\":\"TU1\"},\"occurred_at\":\"2015-01-20T06:12:06Z\"}]"},"http_version":null},"recorded_at":"Tue, 27 Jan 2015 21:28:25 GMT"}],"recorded_with":"VCR 2.9.3"}
Loading

0 comments on commit 012aa7a

Please sign in to comment.