Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Commit

Permalink
feat: 2.6 api endpoints (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
dated authored and faustbrian committed Oct 28, 2019
1 parent f96865d commit c597fe7
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/arkecosystem/client/api/bridgechains.ex
@@ -0,0 +1,22 @@
defmodule ArkEcosystem.Client.API.Bridgechains do
@moduledoc """
Documentation for ArkEcosystem.Client.API.Bridgechains
"""

import ArkEcosystem.Client

@spec list(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def list(client, parameters \\ []) do
client |> get("bridgechains", parameters)
end

@spec show(Tesla.Client.t(), String.t()) :: ArkEcosystem.Client.response()
def show(client, id) do
client |> get("bridgechains/#{id}")
end

@spec search(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def search(client, parameters) do
client |> post("bridgechains/search", parameters)
end
end
27 changes: 27 additions & 0 deletions lib/arkecosystem/client/api/businesses.ex
@@ -0,0 +1,27 @@
defmodule ArkEcosystem.Client.API.Businesses do
@moduledoc """
Documentation for ArkEcosystem.Client.API.Businesses
"""

import ArkEcosystem.Client

@spec list(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def list(client, parameters \\ []) do
client |> get("businesses", parameters)
end

@spec show(Tesla.Client.t(), String.t()) :: ArkEcosystem.Client.response()
def show(client, id) do
client |> get("businesses/#{id}")
end

@spec bridgechains(Tesla.Client.t(), String.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def bridgechains(client, id, parameters \\ []) do
client |> get("businesses/#{id}/bridgechains", parameters)
end

@spec search(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def search(client, parameters) do
client |> post("businesses/search", parameters)
end
end
27 changes: 27 additions & 0 deletions lib/arkecosystem/client/api/locks.ex
@@ -0,0 +1,27 @@
defmodule ArkEcosystem.Client.API.Locks do
@moduledoc """
Documentation for ArkEcosystem.Client.API.Locks
"""

import ArkEcosystem.Client

@spec list(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def list(client, parameters \\ []) do
client |> get("locks", parameters)
end

@spec show(Tesla.Client.t(), String.t()) :: ArkEcosystem.Client.response()
def show(client, id) do
client |> get("locks/#{id}")
end

@spec search(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def search(client, parameters) do
client |> post("locks/search", parameters)
end

@spec search(Tesla.Client.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def search(client, parameters) do
client |> post("unlocked/search", parameters)
end
end
5 changes: 5 additions & 0 deletions lib/arkecosystem/client/api/wallets.ex
Expand Up @@ -20,6 +20,11 @@ defmodule ArkEcosystem.Client.API.Wallets do
client |> get("wallets/#{id}")
end

@spec locks(Tesla.Client.t(), String.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def locks(client, id, parameters \\ []) do
client |> get("wallets/#{id}/locks", parameters)
end

@spec transactions(Tesla.Client.t(), String.t(), Keyword.t()) :: ArkEcosystem.Client.response()
def transactions(client, id, parameters \\ []) do
client |> get("wallets/#{id}/transactions", parameters)
Expand Down
42 changes: 42 additions & 0 deletions test/arkecosystem/client/bridgechains_test.exs
@@ -0,0 +1,42 @@
defmodule ArkEcosystem.Client.API.BridgechainsTest do
use ExUnit.Case
import ArkEcosystem.Client.API.Bridgechains
import Tesla.Mock

@client ArkEcosystem.Client.new(%{
host: "http://127.0.0.1:4003/api",
nethash: "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23",
version: "1.1.1"
})

setup do
mock fn
%{method: :get, url: "http://127.0.0.1:4003/api/bridgechains/dummyId"} ->
json(%{"success" => true, "data" => %{ id: "dummyId" }})
%{method: :get, url: "http://127.0.0.1:4003/api/bridgechains"} ->
json(%{"success" => true, "data" => [%{ id: "dummyId" }]})
%{method: :post, url: "http://127.0.0.1:4003/api/bridgechains/search"} ->
json(%{"success" => true, "data" => [%{ id: "dummySearch" }]})
end
:ok
end

test "call ArkEcosystem.Client.API.Bridgechains.list" do
assert {:ok, response} = list(@client)
assert Enum.at(response["data"],0)["id"] == "dummyId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Bridgechains.show" do
assert {:ok, response} = show(@client, "dummyId")
assert response["data"]["id"] == "dummyId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Bridgechains.search" do
assert {:ok, response} = search(@client, %{q: "searchQuery"})
assert Enum.at(response["data"], 0)["id"] == "dummySearch"
assert response["success"] == true
end

end
50 changes: 50 additions & 0 deletions test/arkecosystem/client/businesses_test.exs
@@ -0,0 +1,50 @@
defmodule ArkEcosystem.Client.API.BusinessesTest do
use ExUnit.Case
import ArkEcosystem.Client.API.Businesses
import Tesla.Mock

@client ArkEcosystem.Client.new(%{
host: "http://127.0.0.1:4003/api",
nethash: "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23",
version: "1.1.1"
})

setup do
mock fn
%{method: :get, url: "http://127.0.0.1:4003/api/businesses/dummyId"} ->
json(%{"success" => true, "data" => %{ id: "dummyId" }})
%{method: :get, url: "http://127.0.0.1:4003/api/businesses"} ->
json(%{"success" => true, "data" => [%{ id: "dummyId" }]})
%{method: :get, url: "http://127.0.0.1:4003/api/businesses/dummyId/bridgechains"} ->
json(%{"success" => true, "data" => [%{ id: "dummyBridgechainId" }]})
%{method: :post, url: "http://127.0.0.1:4003/api/businesses/search"} ->
json(%{"success" => true, "data" => [%{ id: "dummySearch" }]})
end
:ok
end

test "call ArkEcosystem.Client.API.Businesses.list" do
assert {:ok, response} = list(@client)
assert Enum.at(response["data"],0)["id"] == "dummyId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Businesses.show" do
assert {:ok, response} = show(@client, "dummyId")
assert response["data"]["id"] == "dummyId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Businesses.bridgechains" do
assert {:ok, response} = bridgechains(@client, "dummyId")
assert Enum.at(response["data"], 0)["id"] == "dummyBridgechainId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Businesses.search" do
assert {:ok, response} = search(@client, %{q: "searchQuery"})
assert Enum.at(response["data"], 0)["id"] == "dummySearch"
assert response["success"] == true
end

end
50 changes: 50 additions & 0 deletions test/arkecosystem/client/locks_test.exs
@@ -0,0 +1,50 @@
defmodule ArkEcosystem.Client.API.LocksTest do
use ExUnit.Case
import ArkEcosystem.Client.API.Locks
import Tesla.Mock

@client ArkEcosystem.Client.new(%{
host: "http://127.0.0.1:4003/api",
nethash: "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23",
version: "1.1.1"
})

setup do
mock fn
%{method: :get, url: "http://127.0.0.1:4003/api/locks/dummyId"} ->
json(%{"success" => true, "data" => %{ id: "dummyId" }})
%{method: :get, url: "http://127.0.0.1:4003/api/locks"} ->
json(%{"success" => true, "data" => [%{ id: "dummyId" }]})
%{method: :post, url: "http://127.0.0.1:4003/api/locks/search"} ->
json(%{"success" => true, "data" => [%{ id: "dummySearch" }]})
%{method: :post, url: "http://127.0.0.1:4003/api/locks/unlocked"} ->
json(%{"success" => true, "data" => [%{ id: "dummySearch" }]})
end
:ok
end

test "call ArkEcosystem.Client.API.Locks.list" do
assert {:ok, response} = list(@client)
assert Enum.at(response["data"],0)["id"] == "dummyId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Locks.show" do
assert {:ok, response} = show(@client, "dummyId")
assert response["data"]["id"] == "dummyId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Locks.search" do
assert {:ok, response} = search(@client, %{q: "searchQuery"})
assert Enum.at(response["data"], 0)["id"] == "dummySearch"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Locks.unlocked" do
assert {:ok, response} = unlocked(@client, %{q: "searchQuery"})
assert Enum.at(response["data"], 0)["id"] == "dummySearch"
assert response["success"] == true
end

end
8 changes: 8 additions & 0 deletions test/arkecosystem/client/wallets_test.exs
Expand Up @@ -17,6 +17,8 @@ defmodule ArkEcosystem.Client.API.WalletsTest do
json(%{"success" => true, "data" => [%{ id: "dummyId" }]})
%{method: :get, url: "http://127.0.0.1:4003/api/wallets/top"} ->
json(%{"success" => true, "data" => [%{ id: "dummyTopId" }]})
%{method: :get, url: "http://127.0.0.1:4003/api/wallets/dummyId/locks"} ->
json(%{"success" => true, "data" => [%{ id: "dummyLockId" }]})
%{method: :get, url: "http://127.0.0.1:4003/api/wallets/dummyId/transactions"} ->
json(%{"success" => true, "data" => [%{ id: "dummyTransactionId" }]})
%{method: :get, url: "http://127.0.0.1:4003/api/wallets/dummyId/transactions/sent"} ->
Expand Down Expand Up @@ -49,6 +51,12 @@ defmodule ArkEcosystem.Client.API.WalletsTest do
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Wallets.locks" do
assert {:ok, response} = locks(@client, "dummyId")
assert Enum.at(response["data"],0)["id"] == "dummyLockId"
assert response["success"] == true
end

test "call ArkEcosystem.Client.API.Wallets.transactions" do
assert {:ok, response} = transactions(@client, "dummyId")
assert Enum.at(response["data"],0)["id"] == "dummyTransactionId"
Expand Down

0 comments on commit c597fe7

Please sign in to comment.