Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to PUT to Story #4

Merged
merged 5 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pivotal wouldn't recognize the PUT request's data unless Content-Type was set. Open to any better ways of doing this

Copy link
Member

Choose a reason for hiding this comment

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

This works for now. I'll think on it and refactor later if the need arises.

)
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 find(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