Skip to content

Commit

Permalink
Publish 0.1.0 Version
Browse files Browse the repository at this point in the history
Publish initial 0.1.0 version with docs
  • Loading branch information
jrusso1020 committed May 31, 2020
1 parent 0c6122f commit 7a480dd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
6 changes: 5 additions & 1 deletion lib/alpaca/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Alpaca.Client do
end
end

@spec client_secret(atom) :: String.t()
@spec client_secret(atom()) :: String.t()
defp client_secret(env_key \\ :client_secret) do
case Confex.get_env(:alpaca_elixir, env_key, System.get_env("ALPACA_CLIENT_SECRET")) ||
:not_found do
Expand All @@ -60,6 +60,7 @@ defmodule Alpaca.Client do
Accepts path which is the url path of the request, will be added to the end of the base_url
and a map of params which will become the query list for the get request
"""
@spec get(String.t(), map()) :: {:ok, map()} | {:error, map()}
def get(path, params \\ %{}) do
create()
|> Tesla.get(path, query: map_to_klist(params))
Expand All @@ -71,6 +72,7 @@ defmodule Alpaca.Client do
Accepts path which is the url path of the request, will be added to the end of the base_url
and a map of params which will be the body of the post request
"""
@spec post(String.t(), map()) :: {:ok, map()} | {:error, map()}
def post(path, params \\ %{}) do
create()
|> Tesla.post(path, params)
Expand All @@ -82,6 +84,7 @@ defmodule Alpaca.Client do
Accepts path which is the url path of the request, will be added to the end of the base_url
and a map of params which will be the body of the post request
"""
@spec patch(String.t(), map()) :: {:ok, map()} | {:error, map()}
def patch(path, params \\ %{}) do
create()
|> Tesla.patch(path, params)
Expand All @@ -92,6 +95,7 @@ defmodule Alpaca.Client do
Accepts path which is the url path of the request, will be added to the end of the base_url
"""
@spec delete(String.t()) :: {:ok, map()} | {:error, map()}
def delete(path) do
create()
|> Tesla.delete(path)
Expand Down
12 changes: 6 additions & 6 deletions lib/alpaca/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Alpaca.Resource do
@doc """
A function to list all resources from the Alpaca API
"""
@spec list(Map.t()) :: {:ok, [__MODULE__.t()]} | {:error, Map.t()}
@spec list(map()) :: {:ok, [__MODULE__.t()]} | {:error, map()}
def list(params \\ %{}) do
with {:ok, resources} <- Client.get(base_url(), params) do
{:ok, Enum.map(resources, fn resource -> struct(__MODULE__, resource) end)}
Expand All @@ -54,7 +54,7 @@ defmodule Alpaca.Resource do
@doc """
A function to get a singlular resource from the Alpaca API
"""
@spec get(String.t(), Map.t()) :: {:ok, __MODULE__.t()} | {:error, Map.t()}
@spec get(String.t(), map()) :: {:ok, __MODULE__.t()} | {:error, map()}
def get(id, params \\ %{}) do
with {:ok, resource} <- Client.get(resource_url(id), params) do
{:ok, struct(__MODULE__, resource)}
Expand All @@ -66,7 +66,7 @@ defmodule Alpaca.Resource do
@doc """
A function to create a new resource from the Alpaca API
"""
@spec create(Map.t()) :: {:ok, __MODULE__.t()} | {:error, Map.t()}
@spec create(map()) :: {:ok, __MODULE__.t()} | {:error, map()}
def create(params) do
with {:ok, resource} <- Client.post(base_url(), params) do
{:ok, struct(__MODULE__, resource)}
Expand All @@ -78,7 +78,7 @@ defmodule Alpaca.Resource do
@doc """
A function to edit an existing resource using the Alpaca API
"""
@spec edit(String.t(), Map.t()) :: {:ok, __MODULE__.t()} | {:error, Map.t()}
@spec edit(String.t(), map()) :: {:ok, __MODULE__.t()} | {:error, map()}
def edit(id, params) do
with {:ok, resource} <- Client.patch(resource_url(id), params) do
{:ok, struct(__MODULE__, resource)}
Expand All @@ -90,7 +90,7 @@ defmodule Alpaca.Resource do
@doc """
A function to delete all resources of a given type using the Alpaca API
"""
@spec delete_all() :: {:ok, [Map.t()]} | {:error, Map.t()}
@spec delete_all() :: {:ok, [map()]} | {:error, map()}
def delete_all() do
with {:ok, response_body} <- Client.delete(base_url()) do
{:ok,
Expand All @@ -109,7 +109,7 @@ defmodule Alpaca.Resource do
@doc """
A function to delete a singular resource of a given type using the Alpaca API
"""
@spec(delete(String.t()) :: :ok, {:error, Map.t()})
@spec(delete(String.t()) :: :ok, {:error, map()})
def delete(id) do
with :ok <- Client.delete(resource_url(id)) do
:ok
Expand Down
2 changes: 1 addition & 1 deletion lib/alpaca/resources/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Alpaca.Account do
Allows us to retrieve our own account information as a result tuple {:ok, %Account{}}
if successful. If not success we will get back a result tuple {:error, {status: http_status_code, body: http_response_body}}
"""
@spec get() :: {:ok, __MODULE__.t()} | {:error, Map.t()}
@spec get() :: {:ok, __MODULE__.t()} | {:error, map()}
def get() do
with {:ok, account} <- Client.get("/v2/account") do
{:ok, struct(__MODULE__, account)}
Expand Down
22 changes: 12 additions & 10 deletions lib/alpaca/resources/order.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ defmodule Alpaca.Order do
get_by_client_order_id/1
```
The `get/1` method allows us to get a singular order by calling `Order.get(id)`.
The `get/1` method allows us to get a singular order by calling `Alpaca.Order.get(id)`.
Where `id` is the id of the order to get.
The `list/1` method allows us to list all orders by calling `Order.list(params)`.
The `list/1` method allows us to list all orders by calling `Alpaca.Order.list(params)`.
Where `params` is a Map of optional params you can use to retrieve orders
defined in the Alpaca API documentation
The `create/1` method allows us to create a new order by calling `Order.create(params)`.
The `create/1` method allows us to create a new order by calling `Alpaca.Order.create(params)`.
Where `params` is the Map of parameters to create the order
The `edit/2` method allows us to edit a specific order by calling `Order.edit(id, params)`.
The `edit/2` method allows us to edit a specific order by calling `Alpaca.Order.edit(id, params)`.
Where `id` is the id of the order and `params` are the parameters of the order we want to
change defined by the Alpaca API documentation.
The `delete_all/0` method allows us to delete all open orders by calling `Order.delete_all()`.
The `delete_all/0` method allows us to delete all open orders by calling `Alpaca.Order.delete_all()`.
The `delete/1` method allows us to delete a specific order by calling `Order.delete(id)`.
The `delete/1` method allows us to delete a specific order by calling `Alpaca.Order.delete(id)`.
Where id is the id of the order we want to delete.
The `get_by_client_order_id/1` method allows us to get a specific order by the client order id by calling
Order.get_by_client_order_id(client_order_id)`. Where client_order_id is the client order id on the order.
`Alpaca.Order.get_by_client_order_id(client_order_id)`. Where client_order_id is the client order id on the order.
"""
use Alpaca.Resource, endpoint: "orders"
use TypedStruct
Expand Down Expand Up @@ -73,12 +73,14 @@ defmodule Alpaca.Order do
Retrieve an order by client order id
### Example
```
iex> {:ok, %Order{} = order} = Order.get_by_client_order_id(client_order_id)
```
Allows us to retrieve our an order as a result tuple {:ok, %Order{}}
if successful. If not success we will get back a result tuple {:error, {status: http_status_code, body: http_response_body}}
Allows us to retrieve our an order as a result tuple `{:ok, %Alpaca.Order{}}`
if successful. If not success we will get back a result tuple `{:error, {status: http_status_code, body: http_response_body}}`
"""
@spec get_by_client_order_id(String.t()) :: {:ok, __MODULE__.t()} | {:error, Map.t()}
@spec get_by_client_order_id(String.t()) :: {:ok, __MODULE__.t()} | {:error, map()}
def get_by_client_order_id(client_order_id) do
case Client.get("/v2/orders:by_client_order_id", %{client_order_id: client_order_id}) do
{:ok, order} ->
Expand Down
12 changes: 11 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ defmodule AlpacaElixir.MixProject do
test_coverage: [tool: ExCoveralls],
description: "Alpaca Elixir Library",
package: package(),
deps: deps()
deps: deps(),

# Docs
name: "AlpacaElixir",
source_url: "https://github.com/jrusso1020/alpaca-elixir",
homepage_url: "https://github.com/jrusso1020/alpaca-elixir",
docs: [
main: "AlpacaElixir",
extra: ["README.md"]
]
]
end

Expand All @@ -31,6 +40,7 @@ defmodule AlpacaElixir.MixProject do
{:excoveralls, "~> 0.10", only: :test},
{:exvcr, "~> 0.11", only: :test},
{:hackney, "~> 1.15.2"},
{:ex_doc, "~> 0.22", only: :dev, runtime: false},
{:jason, "~> 1.2"},
{:tesla, "~> 1.3.0"},
{:typed_struct, "~> 0.1.4"}
Expand Down
5 changes: 5 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"cowboy": {:hex, :cowboy, "2.7.0", "91ed100138a764355f43316b1d23d7ff6bdb0de4ea618cb5d8677c93a7a2f115", [:rebar3], [{:cowlib, "~> 2.8.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "04fd8c6a39edc6aaa9c26123009200fc61f92a3a94f3178c527b70b767c6e605"},
"cowlib": {:hex, :cowlib, "2.8.0", "fd0ff1787db84ac415b8211573e9a30a3ebe71b5cbff7f720089972b2319c8a4", [:rebar3], [], "hexpm", "79f954a7021b302186a950a32869dbc185523d99d3e44ce430cd1f3289f41ed4"},
"credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"},
"earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"},
"ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"},
"exactor": {:hex, :exactor, "2.2.4", "5efb4ddeb2c48d9a1d7c9b465a6fffdd82300eb9618ece5d34c3334d5d7245b1", [:mix], [], "hexpm", "1222419f706e01bfa1095aec9acf6421367dcfab798a6f67c54cf784733cd6b5"},
"excoveralls": {:hex, :excoveralls, "0.12.3", "2142be7cb978a3ae78385487edda6d1aff0e482ffc6123877bb7270a8ffbcfe0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "568a3e616c264283f5dea5b020783ae40eef3f7ee2163f7a67cbd7b35bcadada"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm", "32e95820a97cffea67830e91514a2ad53b888850442d6d395f53a1ac60c82e07"},
Expand All @@ -15,10 +17,13 @@
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
"jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm", "fc3499fed7a726995aa659143a248534adc754ebd16ccd437cd93b649a95091f"},
"makeup": {:hex, :makeup, "1.0.2", "0b9f7bfb7a88bed961341b359bc2cc1b233517af891ba4890ec5a580ffe738b4", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "43833299231c6a6983afc75a34e43eeba638521d5527ff89809fa6372424fd7e"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
"meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm", "d34f013c156db51ad57cc556891b9720e6a1c1df5fe2e15af999c84d6cebeb1a"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
"plug": {:hex, :plug, "1.10.1", "c56a6d9da7042d581159bcbaef873ba9d87f15dce85420b0d287bca19f40f9bd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "b5cd52259817eb8a31f2454912ba1cff4990bca7811918878091cb2ab9e52cb8"},
"plug_cowboy": {:hex, :plug_cowboy, "2.2.1", "fcf58aa33227a4322a050e4783ee99c63c031a2e7f9a2eb7340d55505e17f30f", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3b43de24460d87c0971887286e7a20d40462e48eb7235954681a20cee25ddeb6"},
Expand Down

0 comments on commit 7a480dd

Please sign in to comment.