Skip to content

Commit

Permalink
Merge pull request #2 from diacode/feature/stories-endpoint
Browse files Browse the repository at this point in the history
Story endpoint integration
  • Loading branch information
forest committed Mar 2, 2016
2 parents a8fcfc5 + 3e24b51 commit 0122749
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ Based heavily on the [Tentacat](https://github.com/edgurgel/tentacat) and [ExTwi
* [ ] Source Commits
* [x] Stories
* [x] Get
* [ ] Story
* [ ] Post
* [x] Story
* [x] Get
* [ ] Put
* [ ] Delete
* [ ] Story Tasks
* [ ] Story Transitions
* [ ] Workspaces
Expand Down
6 changes: 3 additions & 3 deletions lib/extracker/projects.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ defmodule ExTracker.Projects do
## Example
ExTracker.Projects.find("12345", client)
ExTracker.Projects.find(client, "12345")
More info at: https://www.pivotaltracker.com/help/api/rest/v5#Project
"""
@spec find(pos_integer, Client.t, [{atom, binary}] | []) :: ExTracker.Record.Project.t
def find(project_id, client, params \\ []) do
@spec find(Client.t, pos_integer, [{atom, binary}] | []) :: ExTracker.Record.Project.t
def find(client, project_id, params \\ []) do
get("projects/#{project_id}", client, params)
|> ExTracker.Parser.parse_project
end
Expand Down
18 changes: 17 additions & 1 deletion lib/extracker/stories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@ defmodule ExTracker.Stories do
import ExTracker
alias Extracker.Client

@doc """
Get a single `story`.
## Example
ExTracker.Stories.find(client, "12345")
More info at: https://www.pivotaltracker.com/help/api/rest/v5#stories_story_id_get
"""
@spec find(Client.t, pos_integer, [{atom, binary}] | []) :: ExTracker.Record.Story.t
def find(client, story_id, params \\ []) do
get("stories/#{story_id}", client, params)
|> ExTracker.Parser.parse_story
end


@doc """
Get all stories from project
## Example
ExTracker.Stories.list(client, project_id)
More info at:https://www.pivotaltracker.com/help/api/rest/v5#Stories
More info at: https://www.pivotaltracker.com/help/api/rest/v5#Stories
"""
@spec list(Client.t, pos_integer, [{atom, binary}] | []) :: [ExTracker.Record.Story.t] | []
def list(client, project_id, params \\ []) do
Expand Down
40 changes: 40 additions & 0 deletions test/fixture/vcr_cassettes/stories#find.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"request": {
"body": "\"\"",
"headers": {
"User-agent": "extracker",
"X-TrackerToken": "d55c3bc1f74346b843ca84ba340b29bf"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://www.pivotaltracker.com/services/v5/stories/66727974"
},
"response": {
"body": "{\"kind\":\"story\",\"id\":66727974,\"created_at\":\"2014-02-10T00:00:00Z\",\"updated_at\":\"2014-03-02T07:11:04Z\",\"accepted_at\":\"2014-02-11T00:00:00Z\",\"story_type\":\"chore\",\"name\":\"Setup development environment\",\"description\":\"We need 2 machines set up\",\"current_state\":\"accepted\",\"requested_by_id\":1266314,\"url\":\"https://www.pivotaltracker.com/story/show/66727974\",\"project_id\":1027488,\"owner_ids\":[],\"labels\":[]}",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Status": "200 OK",
"Cache-Control": "max-age=0, private, must-revalidate",
"Date": "Tue, 01 Mar 2016 06:04:50 GMT",
"X-Tracker-Project-Version": "120",
"X-Request-Id": "75bae1844699644e82d9257ef0a3a29f",
"X-UA-Compatible": "IE=Edge,chrome=1",
"ETag": "\"cb76acb351c88232bdc0a95c1ab73bc9\"",
"X-Runtime": "0.056699",
"X-Rack-Cache": "miss",
"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"
}
}
]
4 changes: 2 additions & 2 deletions test/projects_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule ExTracker.ProjectsTest do

test "find/3" do
use_cassette "projects#find" do
%Project{name: name, week_start_day: week_start_day} = find(@project_id, @client)
%Project{name: name, week_start_day: week_start_day} = find(@client, @project_id)
assert name == "My Sample Project"
assert week_start_day == "Monday"
end
Expand All @@ -30,7 +30,7 @@ defmodule ExTracker.ProjectsTest do
test "find/3 with fields param" do
use_cassette "projects#find and include epics and epic label" do
%Project{name: name, epics: epics} =
find( @project_id, @client,
find(@client, @project_id,
fields: ":default,epics(:default,label(name))")
assert name == "My Sample Project"
assert length(epics) > 1
Expand Down
9 changes: 9 additions & 0 deletions test/stories_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ defmodule ExTracker.StoriesTest do
doctest ExTracker.Stories

alias ExTracker.Support.Helpers
alias ExTracker.Record.Story

@client ExTracker.Client.new(%{access_token: Helpers.pt_user_1.token})
@project_id Helpers.pt_user_1.project_id
@story_id Helpers.pt_user_1.story_id

setup_all do
HTTPoison.start
end

test "find/2" do
use_cassette "stories#find" do
%Story{name: name} = find(@client, @story_id)
assert name == "Setup development environment"
end
end

test "list/2" do
use_cassette "stories#list" do
stories = list(@client, @project_id)
Expand Down
2 changes: 1 addition & 1 deletion test/support/helpers.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ExTracker.Support.Helpers do
# These API Tokens are for a user with just one Public Sample Project
def pt_user_1 do
%{ username: "trackerapi1", password: "trackerapi1", token: "d55c3bc1f74346b843ca84ba340b29bf", project_id: 1027488 }
%{ username: "trackerapi1", password: "trackerapi1", token: "d55c3bc1f74346b843ca84ba340b29bf", project_id: 1027488, story_id: 66727974 }
end

def pt_user_2 do
Expand Down

0 comments on commit 0122749

Please sign in to comment.