Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 2.6 endpoints #79

Merged
merged 15 commits into from
Feb 10, 2020
17 changes: 17 additions & 0 deletions client/bridgechain_requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is part of Ark Go Client.
//
// (c) Ark Ecosystem <info@ark.io>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

package client

type BridgechainsSearchRequest struct {
BridgechainId uint16 `json:"bridgechainId,omitempty"`
BusinessId uint16 `json:"businessId,omitempty"`
Name string `json:"name,omitempty"`
SeedNodes []string `json:"website,omitempty"`
GenesisHash string `json:"vat,omitempty"`
BridgechainRepository string `json:"repository,omitempty"`
}
56 changes: 56 additions & 0 deletions client/bridgechains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is part of Ark Go Client.
//
// (c) Ark Ecosystem <info@ark.io>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

package client

import (
"context"
"fmt"
"net/http"
)

// BridgechainsService handles communication with the bridgechains related
// methods of the Ark Core API - Version 2.
type BridgechainsService Service

// Get all bridgechains.
func (s *BridgechainsService) List(ctx context.Context, query *Pagination) (*Bridgechains, *http.Response, error) {
var responseStruct *Bridgechains
resp, err := s.client.SendRequest(ctx, "GET", "bridgechains", query, nil, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Get a bridgechains by the given id.
func (s *BridgechainsService) Get(ctx context.Context, id uint16) (*GetBridgechain, *http.Response, error) {
uri := fmt.Sprintf("bridgechains/%v", id)

var responseStruct *GetBridgechain
resp, err := s.client.SendRequest(ctx, "GET", uri, nil, nil, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Filter all bridgechains by the given criteria.
func (s *BridgechainsService) Search(ctx context.Context, query *Pagination, body *BridgechainsSearchRequest) (*Bridgechains, *http.Response, error) {
var responseStruct *Bridgechains
resp, err := s.client.SendRequest(ctx, "POST", "bridgechains/search", query, body, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}
26 changes: 26 additions & 0 deletions client/bridgechains_responses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is part of Ark Go Client.
//
// (c) Ark Ecosystem <info@ark.io>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

package client

type Bridgechain struct {
BridgechainId uint16 `json:"bridgechainId,omitempty"`
BusinessId uint16 `json:"businessId,omitempty"`
Name string `json:"name,omitempty"`
SeedNodes []string `json:"seedNodes,omitempty"`
GenesisHash string `json:"genesisHash,omitempty"`
BridgechainRepository string `json:"bridgechainRepository,omitempty"`
}

type Bridgechains struct {
Meta Meta `json:"meta,omitempty"`
Data []Bridgechain `json:"data,omitempty"`
}

type GetBridgechain struct {
Data Bridgechain `json:"data,omitempty"`
}
179 changes: 179 additions & 0 deletions client/bridgechains_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// This file is part of Ark Go Client.
//
// (c) Ark Ecosystem <info@ark.io>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

package client

import (
"context"
"fmt"
"net/http"
"testing"
)

// Get all bridgechains.
func TestBridgechainsService_List(t *testing.T) {
client, mux, _, teardown := setupTest()
defer teardown()

mux.HandleFunc("/bridgechains", func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
fmt.Fprint(writer,
`{
"meta": {
"count": 1,
"pageCount": 1,
"totalCount": 1,
"next": null,
"previous": null,
"self": "/api/bridgechains?page=1&limit=1",
"first": "/api/bridgechains?page=1&limit=1",
"last": "/api/bridgechains?page=1&limit=1"
},
"data": [
{
"bridgechainId": 1,
"businessId": 1,
"name": "dummyName",
"seedNodes": [
"1.1.1.1"
],
"genesisHash": "dummyGenesisHash",
"bridgechainRepository": "dummyBridgechainRepository"
}
]
}`)
})

query := &Pagination{Limit: 1}
responseStruct, response, err := client.Bridgechains.List(context.Background(), query)
testGeneralError(t, "Bridgechains.List", err)
testResponseUrl(t, "Bridgechains.List", response, "/api/bridgechains")
testResponseStruct(t, "Bridgechains.List", responseStruct, &Bridgechains{
Meta: Meta{
Count: 1,
PageCount: 1,
TotalCount: 1,
Next: "",
Previous: "",
Self: "/api/bridgechains?page=1&limit=1",
First: "/api/bridgechains?page=1&limit=1",
Last: "/api/bridgechains?page=1&limit=1",
},
Data: []Bridgechain{{
BridgechainId: 1,
BusinessId: 1,
Name: "dummyName",
SeedNodes: []string{
"1.1.1.1",
},
GenesisHash: "dummyGenesisHash",
BridgechainRepository: "dummyBridgechainRepository",
}},
})
}

// Get a bridgechain by the given id
func TestBridgechainsService_Get(t *testing.T) {
client, mux, _, teardown := setupTest()
defer teardown()

mux.HandleFunc("/bridgechains/1", func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
fmt.Fprint(writer,
`{
"data": {
"bridgechainId": 1,
"businessId": 1,
"name": "dummyName",
"seedNodes": [
"1.1.1.1"
],
"genesisHash": "dummyGenesisHash",
"bridgechainRepository": "dummyBridgechainRepository"
}
}`)
})

responseStruct, response, err := client.Bridgechains.Get(context.Background(), 1)
testGeneralError(t, "Bridgechains.Get", err)
testResponseUrl(t, "Bridgechains.Get", response, "/bridgechains/1")
testResponseStruct(t, "Bridgechains.Get", responseStruct, &GetBridgechain{
Data: Bridgechain{
BridgechainId: 1,
BusinessId: 1,
Name: "dummyName",
SeedNodes: []string{
"1.1.1.1",
},
GenesisHash: "dummyGenesisHash",
BridgechainRepository: "dummyBridgechainRepository",
},
})
}

// Filter all bridgechains by the given criteria.
func TestBridgechainsService_Search(t *testing.T) {
client, mux, _, teardown := setupTest()
defer teardown()

mux.HandleFunc("/bridgechains/search", func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "POST")
fmt.Fprint(writer,
`{
"meta": {
"count": 1,
"pageCount": 1,
"totalCount": 1,
"next": null,
"previous": null,
"self": "/api/bridgechains/search?page=1&limit=1",
"first": "/api/bridgechains/search?page=1&limit=1",
"last": "/api/bridgechains/search?page=1&limit=1"
},
"data": [
{
"bridgechainId": 1,
"businessId": 1,
"name": "dummyName",
"seedNodes": [
"1.1.1.1"
],
"genesisHash": "dummyGenesisHash",
"bridgechainRepository": "dummyBridgechainRepository"
}
]
}`)
})

query := &Pagination{Limit: 1}
body := &BridgechainsSearchRequest{BridgechainId: 1}
responseStruct, response, err := client.Bridgechains.Search(context.Background(), query, body)
testGeneralError(t, "Bridgechains.Search", err)
testResponseUrl(t, "Bridgechains.Search", response, "/api/bridgechains/search")
testResponseStruct(t, "Bridgechains.Search", responseStruct, &Bridgechains{
Meta: Meta{
Count: 1,
PageCount: 1,
TotalCount: 1,
Next: "",
Previous: "",
Self: "/api/bridgechains/search?page=1&limit=1",
First: "/api/bridgechains/search?page=1&limit=1",
Last: "/api/bridgechains/search?page=1&limit=1",
},
Data: []Bridgechain{{
BridgechainId: 1,
BusinessId: 1,
Name: "dummyName",
SeedNodes: []string{
"1.1.1.1",
},
GenesisHash: "dummyGenesisHash",
BridgechainRepository: "dummyBridgechainRepository",
}},
})
}
70 changes: 70 additions & 0 deletions client/businesses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// This file is part of Ark Go Client.
//
// (c) Ark Ecosystem <info@ark.io>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

package client

import (
"context"
"fmt"
"net/http"
)

// BusinessesService handles communication with the businesses related
// methods of the Ark Core API - Version 2.
type BusinessesService Service

// Get all businesses.
func (s *BusinessesService) List(ctx context.Context, query *Pagination) (*Businesses, *http.Response, error) {
var responseStruct *Businesses
resp, err := s.client.SendRequest(ctx, "GET", "businesses", query, nil, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Get a business by the given id.
func (s *BusinessesService) Get(ctx context.Context, id uint16) (*GetBusiness, *http.Response, error) {
uri := fmt.Sprintf("businesses/%v", id)

var responseStruct *GetBusiness
resp, err := s.client.SendRequest(ctx, "GET", uri, nil, nil, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Get all bridgechains by the given business.
func (s *BusinessesService) Bridgechains(ctx context.Context, id uint16, query *Pagination) (*GetBusinessBridgechains, *http.Response, error) {
uri := fmt.Sprintf("businesses/%v/bridgechains", id)

var responseStruct *GetBusinessBridgechains
resp, err := s.client.SendRequest(ctx, "GET", uri, query, nil, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Filter all businesses by the given criteria.
func (s *BusinessesService) Search(ctx context.Context, query *Pagination, body *BusinessesSearchRequest) (*Businesses, *http.Response, error) {
var responseStruct *Businesses
resp, err := s.client.SendRequest(ctx, "POST", "businesses/search", query, body, &responseStruct)

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}
16 changes: 16 additions & 0 deletions client/businesses_requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file is part of Ark Go Client.
//
// (c) Ark Ecosystem <info@ark.io>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

package client

type BusinessesSearchRequest struct {
BusinessId uint16 `json:"businessId,omitempty"`
Name string `json:"name,omitempty"`
Website string `json:"website,omitempty"`
Vat string `json:"vat,omitempty"`
Repository string `json:"repository,omitempty"`
}
Loading