Skip to content

Commit

Permalink
Add ability to PUT to Story (#4)
Browse files Browse the repository at this point in the history
* Fix JSON request to always specify content type so sending in a JSON body works
* Add update story endpoint
* Test for updating story
* Update README to contain story PUT
* Updating documentation to have correct funct name
  • Loading branch information
Steve Klebanoff authored and forest committed Jul 5, 2016
1 parent 0122749 commit db7a937
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Based heavily on the [Tentacat](https://github.com/edgurgel/tentacat) and [ExTwi
* [ ] Post
* [x] Story
* [x] Get
* [ ] Put
* [x] Put
* [ ] Delete
* [ ] Story Tasks
* [ ] Story Transitions
Expand Down
5 changes: 4 additions & 1 deletion lib/extracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ defmodule ExTracker do
end

def _request(method, url, auth, body \\ "") do
json_request(method, url, body, authorization_header(auth, @user_agent))
json_request(
method, url, body,
["Content-Type": "application/json"] ++ authorization_header(auth, @user_agent)
)
end

def json_request(method, url, body \\ "", headers \\ [], options \\ []) do
Expand Down
14 changes: 14 additions & 0 deletions lib/extracker/stories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ defmodule ExTracker.Stories do
|> ExTracker.Parser.parse_story
end

@doc """
Update a single `story`
## Example
ExTracker.Stories.update(client, "124273751", %{name: "New Cool Name"})
More info at: https://www.pivotaltracker.com/help/api/rest/v5#projects_project_id_stories_story_id_put
"""
@spec update(Client.t, pos_integer, {atom, binary}) :: ExTracker.Record.Story.t
def update(client, story_id, params) do
put("stories/#{story_id}", client, params)
|> ExTracker.Parser.parse_story
end

@doc """
Get all stories from project
Expand Down
41 changes: 41 additions & 0 deletions test/fixture/vcr_cassettes/stories#update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"request": {
"body": "{\"name\":\"Name From Test\"}",
"headers": {
"Content-Type": "application/json",
"User-agent": "extracker",
"X-TrackerToken": "d55c3bc1f74346b843ca84ba340b29bf"
},
"method": "put",
"options": [],
"request_body": "",
"url": "https://www.pivotaltracker.com/services/v5/stories/66727974"
},
"response": {
"body": "{\"kind\":\"story\",\"id\":66727974,\"project_id\":1027488,\"name\":\"Name From Test\",\"description\":\"We need 2 machines set up\",\"story_type\":\"chore\",\"current_state\":\"accepted\",\"accepted_at\":\"2014-02-11T00:00:00Z\",\"requested_by_id\":1266314,\"owner_ids\":[],\"labels\":[],\"created_at\":\"2014-02-10T00:00:00Z\",\"updated_at\":\"2016-07-01T23:37:17Z\",\"url\":\"https://www.pivotaltracker.com/story/show/66727974\"}",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Status": "200 OK",
"Cache-Control": "max-age=0, private, must-revalidate",
"Date": "Fri, 01 Jul 2016 23:37:17 GMT",
"X-Tracker-Project-Version": "145",
"X-Request-Id": "406a244d4c7fd5c55d5bc87e594bdfe1",
"X-UA-Compatible": "IE=Edge,chrome=1",
"ETag": "\"080d23e10d0537d78e12a9f6dfe73941\"",
"X-Runtime": "0.147122",
"X-Rack-Cache": "invalidate, pass",
"X-Powered-By": "Phusion Passenger Enterprise",
"Server": "nginx + Phusion Passenger",
"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": "12"
},
"status_code": 200,
"type": "ok"
}
}
]
7 changes: 7 additions & 0 deletions test/stories_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ defmodule ExTracker.StoriesTest do
assert length(stories) == 63
end
end

test "update/3" do
use_cassette "stories#update" do
%Story{name: name} = update(@client, @story_id, %{name: "Name From Test"})
assert name == "Name From Test"
end
end
end

0 comments on commit db7a937

Please sign in to comment.