Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/tracker_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def post(path, options = {})
request(:post, parse_query_and_convenience_headers(path, options))
end

def put(path, options = {})
request(:put, parse_query_and_convenience_headers(path, options))
end

# Make one or more HTTP GET requests, optionally fetching
# the next page of results from information passed back in headers
# based on value in {#auto_paginate}.
Expand Down
6 changes: 6 additions & 0 deletions lib/tracker_api/endpoints/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def create(project_id, params={})

Resources::Story.new({ client: client }.merge(data))
end

def update(project_id, story_id, params={})
data = client.put("/projects/#{project_id}/stories/#{story_id}", params: params).body

Resources::Story.new({ client: client }.merge(data))
end
end
end
end
7 changes: 7 additions & 0 deletions lib/tracker_api/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def story(story_id)
def create_story(params)
Endpoints::Story.new(client).create(id, params)
end

# @param [Integer] id of story to update
# @param [Hash] hash of attributes to update the story
# @return [Story] Story with given id
def update_story(story_id, params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thegrubbsian why isn't the update in the context of the Story object.

project  = client.project(123456)
story = project.story(847762630) 
story.attributes = { :name => 'Jane' }
story.save

or wrap setting the attributes and saving in an update method.

story.update(:name => 'Jane')

Seems more intuitive that you would get an existing Story, change some data, and then save.

Endpoints::Story.new(client).update(id, story_id, params)
end
end
end
end
14 changes: 14 additions & 0 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,19 @@
story.name.must_equal 'Test story'
end
end

it 'can update story' do
VCR.use_cassette('update story') do
story = project.create_story(name: 'Test story')

story.name.must_equal 'Test story'

project.update_story(story.id, { name: 'Changed name' })

retrieved_story = project.story(story.id)

retrieved_story.name.must_equal 'Changed name'
end
end
end
end
1 change: 1 addition & 0 deletions test/vcr/cassettes/update_story.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"post","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories?name=Test+story","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["Ruby/2.1.3 (x86_64-darwin14.0; ruby) TrackerApi/0.2.6 Faraday/0.9.0"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"],"Content-Length":["0"]}},"response":{"status":{"code":200,"message":null},"headers":{"Content-Type":["application/json; charset=utf-8"],"Status":["200 OK"],"X-Tracker-Project-Version":["28"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"0af20736c4d17830ba4d82ed274fb7a8\""],"Cache-Control":["max-age=0, private, must-revalidate"],"X-Request-Id":["de140d9de307c1891d45f223568a9ae1"],"X-Runtime":["0.225279"],"Date":["Wed, 10 Dec 2014 05:20:17 GMT"],"X-Rack-Cache":["invalidate, pass"],"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":"{\n \"kind\": \"story\",\n \"id\": 84269322,\n \"project_id\": 1027488,\n \"name\": \"Test story\",\n \"story_type\": \"feature\",\n \"current_state\": \"unscheduled\",\n \"requested_by_id\": 1266314,\n \"owner_ids\": [\n\n ],\n \"labels\": [\n\n ],\n \"created_at\": \"2014-12-10T05:20:17Z\",\n \"updated_at\": \"2014-12-10T05:20:17Z\",\n \"url\": \"https://www.pivotaltracker.com/story/show/84269322\"\n}"},"http_version":null},"recorded_at":"Wed, 10 Dec 2014 05:20:17 GMT"},{"request":{"method":"put","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/84269322?name=Changed+name","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["Ruby/2.1.3 (x86_64-darwin14.0; ruby) TrackerApi/0.2.6 Faraday/0.9.0"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"],"Content-Length":["0"]}},"response":{"status":{"code":200,"message":null},"headers":{"Content-Type":["application/json; charset=utf-8"],"Status":["200 OK"],"X-Tracker-Project-Version":["29"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"dc6c6116d5985962aac5b28c5e7ababe\""],"Cache-Control":["max-age=0, private, must-revalidate"],"X-Request-Id":["0bfc5b0d7ae22f04f73d8da869e61453"],"X-Runtime":["0.162157"],"Date":["Wed, 10 Dec 2014 05:20:18 GMT"],"X-Rack-Cache":["invalidate, pass"],"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":"{\n \"kind\": \"story\",\n \"id\": 84269322,\n \"project_id\": 1027488,\n \"name\": \"Changed name\",\n \"story_type\": \"feature\",\n \"current_state\": \"unscheduled\",\n \"requested_by_id\": 1266314,\n \"owner_ids\": [\n\n ],\n \"labels\": [\n\n ],\n \"created_at\": \"2014-12-10T05:20:17Z\",\n \"updated_at\": \"2014-12-10T05:20:18Z\",\n \"url\": \"https://www.pivotaltracker.com/story/show/84269322\"\n}"},"http_version":null},"recorded_at":"Wed, 10 Dec 2014 05:20:18 GMT"},{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/84269322","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.1.3 (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":["29"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"dc6c6116d5985962aac5b28c5e7ababe\""],"Cache-Control":["max-age=0, private, must-revalidate"],"X-Request-Id":["e5c646f3993e35a931093c8c978d9ec6"],"X-Runtime":["0.042098"],"Date":["Wed, 10 Dec 2014 05:20:18 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":"{\n \"kind\": \"story\",\n \"id\": 84269322,\n \"project_id\": 1027488,\n \"name\": \"Changed name\",\n \"story_type\": \"feature\",\n \"current_state\": \"unscheduled\",\n \"requested_by_id\": 1266314,\n \"owner_ids\": [\n\n ],\n \"labels\": [\n\n ],\n \"created_at\": \"2014-12-10T05:20:17Z\",\n \"updated_at\": \"2014-12-10T05:20:18Z\",\n \"url\": \"https://www.pivotaltracker.com/story/show/84269322\"\n}"},"http_version":null},"recorded_at":"Wed, 10 Dec 2014 05:20:18 GMT"}],"recorded_with":"VCR 2.9.3"}