Skip to content

Commit b4e1489

Browse files
committed
Merge pull request #1 from diacode/feature/stories-endpoint
Stories list
2 parents cb5b229 + 226cab0 commit b4e1489

6 files changed

Lines changed: 200 additions & 2 deletions

File tree

lib/extracker/parser.ex

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,46 @@ defmodule ExTracker.Parser do
117117
def parse_label(object) do
118118
struct(ExTracker.Record.Label, object)
119119
end
120+
121+
@doc """
122+
Parse stories from the API response json.
123+
"""
124+
@spec parse_stories([Map.t] | nil) :: [ExTracker.Record.Story.t] | nil
125+
def parse_stories(nil), do: nil
126+
def parse_stories(object) do
127+
object |> Enum.map(&ExTracker.Parser.parse_story/1)
128+
end
129+
130+
@doc """
131+
Parse story from the API response json.
132+
"""
133+
@spec parse_story(Map.t) :: ExTracker.Record.Story.t
134+
def parse_story(object) do
135+
struct(ExTracker.Record.Story, object)
136+
end
137+
138+
@doc """
139+
Parse story transactions from the API response json.
140+
"""
141+
@spec parse_story_transactions([Map.t] | nil) :: [ExTracker.Record.StoryTransaction.t] | nil
142+
def parse_story_transactions(nil), do: nil
143+
def parse_story_transactions(object) do
144+
object |> Enum.map(&ExTracker.Parser.parse_story_transaction/1)
145+
end
146+
147+
@doc """
148+
Parse story transactions from the API response json.
149+
"""
150+
@spec parse_story_transaction(Map.t) :: ExTracker.Record.StoryTransaction.t
151+
def parse_story_transaction(object) do
152+
struct(ExTracker.Record.StoryTransaction, object)
153+
end
154+
155+
@doc """
156+
Parse cicle time details from the API response json.
157+
"""
158+
@spec parse_cicle_time_details(Map.t) :: ExTracker.Record.CicleTimeDetails.t
159+
def parse_cicle_time_details(object) do
160+
struct(ExTracker.Record.CicleTimeDetails, object)
161+
end
120162
end

lib/extracker/record.ex

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,72 @@ defmodule ExTracker.Record.Account do
148148
kind: binary
149149
}
150150
end
151+
152+
defmodule ExTracker.Record.Story do
153+
defstruct [:id, :project_id, :name, :description, :story_type, :current_state,
154+
:estimate, :accepted_at, :deadline, :requested_by_id, :owner_ids,
155+
:label_ids, :task_ids, :follower_ids, :comment_ids, :created_at, :updated_at,
156+
:before_id, :after_id, :integration_id, :external_id, :url, :transitions,
157+
:cycle_time_details, :kind]
158+
159+
@type t :: %ExTracker.Record.Story{
160+
id: pos_integer,
161+
project_id: pos_integer,
162+
name: binary,
163+
description: binary,
164+
story_type: binary,
165+
current_state: binary,
166+
estimate: float,
167+
accepted_at: binary,
168+
deadline: binary,
169+
requested_by_id: pos_integer,
170+
owner_ids: [pos_integer],
171+
label_ids: [pos_integer],
172+
task_ids: [pos_integer],
173+
follower_ids: [pos_integer],
174+
comment_ids: [pos_integer],
175+
created_at: binary,
176+
updated_at: binary,
177+
before_id: pos_integer,
178+
after_id: pos_integer,
179+
integration_id: pos_integer,
180+
external_id: binary,
181+
url: binary,
182+
# transitions: [ExTracker.Record.StoryTransition.t],
183+
# cycle_time_details: ExTracker.Record.CycleTimeDetails.t,
184+
kind: binary
185+
}
186+
end
187+
188+
defmodule ExTracker.Record.StoryTransition do
189+
defstruct [:state, :story_id, :project_id, :project_version, :occurred_at, :performed_by_id, :kind]
190+
191+
@type t :: %ExTracker.Record.StoryTransition{
192+
state: binary,
193+
story_id: pos_integer,
194+
project_id: pos_integer,
195+
project_version: pos_integer,
196+
occurred_at: binary,
197+
performed_by_id: pos_integer,
198+
kind: binary
199+
}
200+
end
201+
202+
defmodule ExTracker.Record.CycleTimeDetails do
203+
defstruct [:total_cycle_time, :started_time, :started_count, :finished_time,
204+
:finished_count, :delivered_time, :delivered_count, :rejected_time,
205+
:rejected_count, :story_id, :kind]
206+
207+
@type t :: %ExTracker.Record.CycleTimeDetails{
208+
total_cycle_time: pos_integer,
209+
started_time: pos_integer,
210+
started_count: pos_integer,
211+
finished_time: pos_integer,
212+
finished_count: pos_integer,
213+
delivered_time: pos_integer,
214+
delivered_count: pos_integer,
215+
rejected_time: pos_integer,
216+
rejected_count: pos_integer,
217+
kind: binary
218+
}
219+
end

lib/extracker/stories.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule ExTracker.Stories do
2+
import ExTracker
3+
alias Extracker.Client
4+
5+
@doc """
6+
Get all stories from project
7+
8+
## Example
9+
10+
ExTracker.Stories.list(client, project_id)
11+
12+
More info at:https://www.pivotaltracker.com/help/api/rest/v5#Stories
13+
"""
14+
@spec list(Client.t, pos_integer, [{atom, binary}] | []) :: [ExTracker.Record.Story.t] | []
15+
def list(client, project_id, params \\ []) do
16+
get("projects/#{project_id}/stories", client, params)
17+
|> ExTracker.Parser.parse_stories
18+
end
19+
end

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"earmark": {:hex, :earmark, "0.2.1"},
33
"ex_doc": {:hex, :ex_doc, "0.11.4"},
44
"exactor": {:hex, :exactor, "2.2.0"},
5-
"excoveralls": {:hex, :excoveralls, "0.4.5"},
5+
"excoveralls": {:hex, :excoveralls, "0.5.1"},
66
"exjsx": {:hex, :exjsx, "3.2.0"},
77
"exvcr": {:hex, :exvcr, "0.7.1"},
88
"hackney": {:hex, :hackney, "1.4.8"},
@@ -12,5 +12,5 @@
1212
"jsx": {:hex, :jsx, "2.6.2"},
1313
"meck": {:hex, :meck, "0.8.4"},
1414
"mimerl": {:hex, :mimerl, "1.0.2"},
15-
"poison": {:hex, :poison, "2.0.1"},
15+
"poison": {:hex, :poison, "2.1.0"},
1616
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5"}}

test/fixture/vcr_cassettes/stories#list.json

Lines changed: 44 additions & 0 deletions
Large diffs are not rendered by default.

test/stories_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
defmodule ExTracker.StoriesTest do
2+
use ExUnit.Case
3+
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
4+
5+
import ExTracker.Stories
6+
7+
doctest ExTracker.Stories
8+
9+
alias ExTracker.Support.Helpers
10+
11+
@client ExTracker.Client.new(%{access_token: Helpers.pt_user_1.token})
12+
@project_id Helpers.pt_user_1.project_id
13+
14+
setup_all do
15+
HTTPoison.start
16+
end
17+
18+
test "list/2" do
19+
use_cassette "stories#list" do
20+
stories = list(@client, @project_id)
21+
assert length(stories) == 63
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)