f3sdk

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

Form3 Exercise

Installation

To install f3sdk package, you need to install Go (version 1.16+ is required) and setup your Go project first.

$ mkdir example
$ cd example
$ go mod init example.com

Then you can use the below Go command to install the latest version of f3sdk package.

$ go get -u github.com/clivern/f3sdk

Or the following for a specific version v0.1.0

go get -u github.com/clivern/f3sdk@v0.1.0

Import the package in your code.

import "github.com/clivern/f3sdk"

Please note that: the sdk is private so the above steps not applicable. You have to clone and define the local path in go.mod

Quick start

Here is an example showing how to fetch, delete and create accounts using the sdk. Please check example directory for the full example.

// Copyright 2021 Clivern. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.

package main

import (
	"context"
	"fmt"

	"github.com/clivern/f3sdk"
	"github.com/google/uuid"
)

func main() {
	id := uuid.New()

	accountClient := f3sdk.NewAccountClient(30, f3sdk.BaseURL)

	// Create Account
	data := &f3sdk.Data{
		Data: &f3sdk.AccountData{
			ID:             id.String(),
			OrganisationID: "eb0bd6f5-c3f5-44b2-b677-acd23cdde73c",
			Type:           "accounts",
			Attributes: &f3sdk.AccountAttributes{
				AccountNumber:           "41426819",
				AlternativeNames:        []string{"Sam Holder"},
				BankID:                  "400300",
				BankIDCode:              "GBDSC",
				BaseCurrency:            "GBP",
				Bic:                     "NWBKGB22",
				Iban:                    "GB11NWBK40030041426819",
				Name:                    []string{"Samantha Holder"},
				SecondaryIdentification: "A1B2C3D4",
				Country:                 "GB",
			},
		},
	}

	data, err := accountClient.CreateAccount(
		context.TODO(),
		data,
	)

	fmt.Println(err)          // nil
	fmt.Println(data.Data.ID) // id.String()

	// Fetch Account by UUID
	result, err := accountClient.FetchAccountByID(
		context.TODO(),
		id.String(),
	)

	fmt.Println(err)            // nil
	fmt.Println(result.Data.ID) // id.String()

	err = accountClient.DeleteAccountByID(
		context.TODO(),
		result.Data.ID,
		*result.Data.Version,
	)

	fmt.Println(err) // nil
}

Testing

To run unit test cases locally without docker

$ git clone git@github.com:Clivern/f3sdk.git
$ cd f3sdk
$ make install_revive
$ make ci

# To auto format the code
$ make format

# For all commands
$ make

In order to run test cases with docker and docker compose

# Install docker and docker compose on Ubuntu for example
$ apt-get update
$ apt-get install docker.io -y
$ systemctl enable docker

$ apt-get install docker-compose -y

# Clone the solution
$ git clone git@github.com:Clivern/f3sdk.git
$ cd f3sdk

# Run dependencies
$ docker-compose up -d accountapi postgresql vault

# Check if they are healthy
$ docker ps

# Then run sdk test cases
$ docker-compose run f3sdk

License

Copyright 2019-2021 Form3 Financial Cloud

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	// BaseURL Form3 API Base
	BaseURL = "https://api.form3.tech"
)

Variables

View Source
var (
	ErrResourceNotFound = errors.New("Specified resource does not exist")
	ErrVersionConflict  = errors.New("Specified version incorrect")
)

error modes

Functions

func ServerMock

func ServerMock(uri, response string, statusCode int, debug bool) *httptest.Server

ServerMock mocks http server for testing purposes

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

Account struct

func NewAccountClient

func NewAccountClient(timeout int, baseURL string) *Account

NewAccountClient creates an account client

func (*Account) CreateAccount

func (a *Account) CreateAccount(ctx context.Context, data *Data) (*Data, error)

CreateAccount creates a new account

func (*Account) DeleteAccountByID

func (a *Account) DeleteAccountByID(ctx context.Context, accountID string, version int64) error

DeleteAccountByID deletes an account by ID

func (*Account) FetchAccountByID

func (a *Account) FetchAccountByID(ctx context.Context, accountID string) (*Data, error)

FetchAccountByID gets an account by ID

type AccountAttributes

type AccountAttributes struct {
	AccountClassification   *string  `json:"account_classification,omitempty"`
	AccountMatchingOptOut   *bool    `json:"account_matching_opt_out,omitempty"`
	AccountNumber           string   `json:"account_number,omitempty"`
	AlternativeNames        []string `json:"alternative_names,omitempty"`
	BankID                  string   `json:"bank_id,omitempty"`
	BankIDCode              string   `json:"bank_id_code,omitempty"`
	BaseCurrency            string   `json:"base_currency,omitempty"`
	Bic                     string   `json:"bic,omitempty"`
	Country                 string   `json:"country,omitempty"`
	Iban                    string   `json:"iban,omitempty"`
	JointAccount            *bool    `json:"joint_account,omitempty"`
	Name                    []string `json:"name,omitempty"`
	SecondaryIdentification string   `json:"secondary_identification,omitempty"`
	Status                  *string  `json:"status,omitempty"`
	Switched                *bool    `json:"switched,omitempty"`
}

AccountAttributes type

type AccountData

type AccountData struct {
	Attributes     *AccountAttributes `json:"attributes,omitempty"`
	ID             string             `json:"id,omitempty"`
	OrganisationID string             `json:"organisation_id,omitempty"`
	Type           string             `json:"type,omitempty"`
	Version        *int64             `json:"version,omitempty"`
}

AccountData type

type Data

type Data struct {
	Data *AccountData `json:"data,omitempty"`
}

Data type

func (*Data) ConvertToJSON

func (d *Data) ConvertToJSON() (string, error)

ConvertToJSON convert object to json

func (*Data) LoadFromJSON

func (d *Data) LoadFromJSON(data []byte) error

LoadFromJSON update object from json

type HTTPClient

type HTTPClient struct {
	Timeout time.Duration
}

HTTPClient struct

func NewHTTPClient

func NewHTTPClient(timeout int) *HTTPClient

NewHTTPClient creates an instance of http client

func (*HTTPClient) BuildData

func (h *HTTPClient) BuildData(parameters map[string]string) string

BuildData build body data

func (*HTTPClient) Delete

func (h *HTTPClient) Delete(ctx context.Context, endpoint string, parameters, headers map[string]string) (*http.Response, error)

Delete http call

func (*HTTPClient) Get

func (h *HTTPClient) Get(ctx context.Context, endpoint string, parameters, headers map[string]string) (*http.Response, error)

Get http call

func (*HTTPClient) GetHeaderValue

func (h *HTTPClient) GetHeaderValue(response *http.Response, key string) string

GetHeaderValue get response header value

func (*HTTPClient) GetStatusCode

func (h *HTTPClient) GetStatusCode(response *http.Response) int

GetStatusCode response status code

func (*HTTPClient) Patch

func (h *HTTPClient) Patch(ctx context.Context, endpoint string, data string, parameters, headers map[string]string) (*http.Response, error)

Patch http call

func (*HTTPClient) Post

func (h *HTTPClient) Post(ctx context.Context, endpoint string, data string, parameters, headers map[string]string) (*http.Response, error)

Post http call

func (*HTTPClient) Put

func (h *HTTPClient) Put(ctx context.Context, endpoint string, data string, parameters, headers map[string]string) (*http.Response, error)

Put http call

func (*HTTPClient) ToString

func (h *HTTPClient) ToString(response *http.Response) (string, error)

ToString response body to string

type Output

type Output struct {
	Response   string              `json:"response,omitempty"`
	StatusCode int                 `json:"statusCode,omitempty"`
	Headers    map[string][]string `json:"headers,omitempty"`
	Method     string              `json:"method,omitempty"`
	RawQuery   string              `json:"rawQuery,omitempty"`
}

Output type

func (*Output) ConvertToJSON

func (o *Output) ConvertToJSON() (string, error)

ConvertToJSON convert object to json

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL