Skip to content

Commit db7a937

Browse files
Steve Klebanoffforest
authored andcommitted
Add ability to PUT to Story (#4)
* 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
1 parent 0122749 commit db7a937

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Based heavily on the [Tentacat](https://github.com/edgurgel/tentacat) and [ExTwi
4747
* [ ] Post
4848
* [x] Story
4949
* [x] Get
50-
* [ ] Put
50+
* [x] Put
5151
* [ ] Delete
5252
* [ ] Story Tasks
5353
* [ ] Story Transitions

lib/extracker.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ defmodule ExTracker do
4242
end
4343

4444
def _request(method, url, auth, body \\ "") do
45-
json_request(method, url, body, authorization_header(auth, @user_agent))
45+
json_request(
46+
method, url, body,
47+
["Content-Type": "application/json"] ++ authorization_header(auth, @user_agent)
48+
)
4649
end
4750

4851
def json_request(method, url, body \\ "", headers \\ [], options \\ []) do

lib/extracker/stories.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ defmodule ExTracker.Stories do
1717
|> ExTracker.Parser.parse_story
1818
end
1919

20+
@doc """
21+
Update a single `story`
22+
23+
## Example
24+
25+
ExTracker.Stories.update(client, "124273751", %{name: "New Cool Name"})
26+
27+
More info at: https://www.pivotaltracker.com/help/api/rest/v5#projects_project_id_stories_story_id_put
28+
"""
29+
@spec update(Client.t, pos_integer, {atom, binary}) :: ExTracker.Record.Story.t
30+
def update(client, story_id, params) do
31+
put("stories/#{story_id}", client, params)
32+
|> ExTracker.Parser.parse_story
33+
end
2034

2135
@doc """
2236
Get all stories from project
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[
2+
{
3+
"request": {
4+
"body": "{\"name\":\"Name From Test\"}",
5+
"headers": {
6+
"Content-Type": "application/json",
7+
"User-agent": "extracker",
8+
"X-TrackerToken": "d55c3bc1f74346b843ca84ba340b29bf"
9+
},
10+
"method": "put",
11+
"options": [],
12+
"request_body": "",
13+
"url": "https://www.pivotaltracker.com/services/v5/stories/66727974"
14+
},
15+
"response": {
16+
"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\"}",
17+
"headers": {
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Transfer-Encoding": "chunked",
20+
"Status": "200 OK",
21+
"Cache-Control": "max-age=0, private, must-revalidate",
22+
"Date": "Fri, 01 Jul 2016 23:37:17 GMT",
23+
"X-Tracker-Project-Version": "145",
24+
"X-Request-Id": "406a244d4c7fd5c55d5bc87e594bdfe1",
25+
"X-UA-Compatible": "IE=Edge,chrome=1",
26+
"ETag": "\"080d23e10d0537d78e12a9f6dfe73941\"",
27+
"X-Runtime": "0.147122",
28+
"X-Rack-Cache": "invalidate, pass",
29+
"X-Powered-By": "Phusion Passenger Enterprise",
30+
"Server": "nginx + Phusion Passenger",
31+
"Access-Control-Allow-Origin": "*",
32+
"Access-Control-Allow-Credentials": "false",
33+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
34+
"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",
35+
"X-Tracker-Client-Pinger-Interval": "12"
36+
},
37+
"status_code": 200,
38+
"type": "ok"
39+
}
40+
}
41+
]

test/stories_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ defmodule ExTracker.StoriesTest do
3030
assert length(stories) == 63
3131
end
3232
end
33+
34+
test "update/3" do
35+
use_cassette "stories#update" do
36+
%Story{name: name} = update(@client, @story_id, %{name: "Name From Test"})
37+
assert name == "Name From Test"
38+
end
39+
end
3340
end

0 commit comments

Comments
 (0)