-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
223 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Created by Prex | ||
defmodule Newapi do | ||
@moduledoc """ | ||
""" | ||
|
||
@base_url "" | ||
|
||
### | ||
# API Calls | ||
### | ||
|
||
# Tasks | ||
|
||
@doc """ | ||
## Parameters | ||
- status: | ||
- priority: | ||
- number: | ||
""" | ||
def list_all_tasks(status, priority, number) do | ||
req_url = Path.join @base_url, "/tasks/tasks?priority=#{priority |> URI.encode_www_form}" <> | ||
(if number != nil, do: "number=#{number |> URI.encode_www_form}", else: "") <> "&" <> | ||
(if status != nil, do: "status=#{status |> URI.encode_www_form}", else: "") | ||
|
||
HTTPotion.request(:get, req_url, body: Poison.encode!(%{"status" => status, "priority" => priority, "number" => number}), headers: ["Content-Type": "application/json"]) | ||
end | ||
|
||
def list_all_tasks!(status, priority, number) do | ||
{:ok, result} = list_all_tasks(status, priority, number) | ||
result | ||
end | ||
|
||
@doc """ | ||
This is a state transition to another resource. | ||
## Parameters | ||
- status: | ||
- priority: | ||
- number: | ||
- id: | ||
""" | ||
def retrieve_task(status, priority, number, id) do | ||
req_url = Path.join @base_url, "/tasks/tasks?priority=#{priority |> URI.encode_www_form}" <> | ||
(if number != nil, do: "number=#{number |> URI.encode_www_form}", else: "") <> "&" <> | ||
(if status != nil, do: "status=#{status |> URI.encode_www_form}", else: "") | ||
|
||
HTTPotion.request(:get, req_url, body: Poison.encode!(%{"status" => status, "priority" => priority, "number" => number, "id" => id}), headers: ["Content-Type": "application/json"]) | ||
end | ||
|
||
def retrieve_task!(status, priority, number, id) do | ||
{:ok, result} = retrieve_task(status, priority, number, id) | ||
result | ||
end | ||
|
||
@doc """ | ||
## Parameters | ||
- status: | ||
- priority: | ||
- number: | ||
- id: | ||
""" | ||
def delete_task(status, priority, number, id) do | ||
req_url = Path.join @base_url, "/tasks/tasks?priority=#{priority |> URI.encode_www_form}" <> | ||
(if number != nil, do: "number=#{number |> URI.encode_www_form}", else: "") <> "&" <> | ||
(if status != nil, do: "status=#{status |> URI.encode_www_form}", else: "") | ||
|
||
HTTPotion.request(:delete, req_url, body: Poison.encode!(%{"status" => status, "priority" => priority, "number" => number, "id" => id}), headers: ["Content-Type": "application/json"]) | ||
end | ||
|
||
def delete_task!(status, priority, number, id) do | ||
{:ok, result} = delete_task(status, priority, number, id) | ||
result | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
%{"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], []}, | ||
"ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]}, | ||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}} | ||
%{"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, | ||
"ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
FORMAT: 1A | ||
|
||
# Advanced Action API | ||
A resource action is – in fact – a state transition. This API example | ||
demonstrates an action - state transition - to another resource. | ||
|
||
## API Blueprint | ||
+ [Previous: Resource Model](11.%20Resource%20Model.md) | ||
+ [This: Raw API Blueprint](https://raw.github.com/apiaryio/api-blueprint/master/examples/12.%20Advanced%20Action.md) | ||
+ [Next: Named Endpoints](13.%20Named%20Endpoints.md) | ||
|
||
# Tasks [/tasks/tasks{?status,priority,?number}] | ||
|
||
+ Parameters | ||
+ status (string) | ||
+ priority (number) | ||
+ number (number) | ||
|
||
## List All Tasks [GET] | ||
|
||
+ Response 200 (application/json) | ||
|
||
[ | ||
{ | ||
"id": 123, | ||
"name": "Exercise in gym", | ||
"done": false, | ||
"type": "task" | ||
}, | ||
{ | ||
"id": 124, | ||
"name": "Shop for groceries", | ||
"done": true, | ||
"type": "task" | ||
} | ||
] | ||
|
||
## Retrieve Task [GET /task/{id}] | ||
This is a state transition to another resource. | ||
|
||
+ Parameters | ||
+ id (string) | ||
|
||
+ Response 200 (application/json) | ||
|
||
{ | ||
"id": 123, | ||
"name": "Go to gym", | ||
"done": false, | ||
"type": "task" | ||
} | ||
|
||
## Delete Task [DELETE /task/{id}] | ||
|
||
+ Parameters | ||
+ id (string) | ||
|
||
+ Response 204 |