Git Product home page Git Product logo

synapsego's Introduction

SynapseFI Go Library

status

Go-based API wrapper for Synapse REST API. This library handles the user authentication process. As long as the user's fingerprint is registered, further authentication is not necessary in the development flow.

Documentation

Main Docs API Reference

Installation

$ go get github.com/SynapseFI/SynapseGo

main.go

import github.com/SynapseFI/SynapseGo

Examples

Refer to examples and our API documentation for examples.

Testing

To run test-mock or test-api:

  1. Add your credentials to "client_credentials.sample.json" and rename it "client_credentials.json"

To run test-api:

  1. Open the file "request_test.go" and change the value of "var userID string" to a user that was generated on your platform

Functions that mock the Synapse API:

make test-mock

Other functions including (limited) API requests:

make test-api

synapsego's People

Contributors

ezquire avatar izhukovich avatar jamye avatar jerrysummer avatar mikeattanasio avatar nitharios avatar sheilf-synapse avatar thewalrusmaximus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

synapsego's Issues

Too many requests hit the API too quickly

Hi @nitharios ,

I'm actually trying to update documents of one of my user, but I'm stuck by an "Too many requests hit the API too quickly"

Here is my code:

// Get the user
user, err := client.GetUser(MYID, client.IP, client.Fingerprint)

// Create a request object to send (this is a struct for clearer mapping)
req := &request.UpdateUserRequest{}
...

// Marshaling the request
b, _ := json.Marshal(req)

// Updating the user
user, err = user.Update(string(b))
if err != nil {
    panic(err)
}

It always panic with the following error:

HTTP_CODE 429 ERROR_CODE 429 Too many requests hit the API too quickly.

Any idea of what can be the issue ?
I'm actually in sandbox, and the client has been set for dev mode (not prod)

Thanks in advance ! :)

client.GetPublicKey doesn't work

Running

client.GetPublicKey()

produces:

[Error] HTTP_CODE 404 ERROR_CODE 404
The endpoint requested does not exist. Please visit our API docs at https://docs.synapsefi.com to view all avaliable endpoints.

According to the docs, code etc. - this should work with the default scope ๐Ÿคทโ€โ™‚๏ธ

Responses should just be a []byte

Related to #7 Instead of using readStream to convert byte array into a map[string]interface, prefer just keeping the []byte such that clients can use json.Unmarshal into their own structs.

return readStream(response), err

get rid of:

SynapseGo/read.go

Lines 7 to 17 in 7a3e060

func readStream(data []byte) map[string]interface{} {
d := make(map[string]interface{})
err := json.Unmarshal(data, &d)
// if data is an empty stream this will cause an unmarshal error
if err != nil {
panic(err)
}
return d
}

*Request.updateRequest method is not updating the receiver instance

*Request.updateRequest method instead of updating the receiver instance is returning a new one. Besides being confusing, when this method is called from *User.Authenticate the Request holded by User is not getting updated with the new fingerprint and ipAddress.

I propose this solution #23

user.GetStatements stuck in authenticate loop

Successfully do client.GetUser(...) followed by user.GetStatements("limit=1&per_page=1")

The get statements call gets stuck in an authentication loop throwing invalid authentication credentials error then attempting to oauth the user with .Authenticate ... forever.

Please help!

Create Node with ACH-US login

Hey everyone,

I'm actually facing an issue trying to create a node using ACH-US login.
Here is the request i'm doing

	body := `{
		"type": "ACH-US",
		"info":{
			"bank_id":"synapse_good",
			"bank_pw":"test1234",
			"bank_name":"fake"
		}
	  }`
	node, err := user.CreateNode(body)

It fails with the following panic error

panic: interface conversion: interface {} is nil, not map[string]interface {} [recovered]
	panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 6 [running]:
testing.tRunner.func1(0xc0000d2200)
	C:/Go/src/testing/testing.go:792 +0x38e
panic(0x7dd880, 0xc000060f30)
	C:/Go/src/runtime/panic.go:513 +0x1c7
github.com/SynapseFI/SynapseGo.handleHTTPError(0xc000302000, 0x119, 0x600, 0x0, 0xc0002c8000)
	D:/dev/go/pkg/mod/github.com/!synapse!f!i/[email protected]/error.go:213 +0x22a
github.com/SynapseFI/SynapseGo.(*Request).Post(0xc0001e9c68, 0xc000342e10, 0x47, 0x85e386, 0x75, 0x0, 0x0, 0x0, 0x570000c00000edc0, 0x32, ...)
	D:/dev/go/pkg/mod/github.com/!synapse!f!i/[email protected]/request.go:88 +0x59d
github.com/SynapseFI/SynapseGo.(*User).do(0xc0001e9c20, 0x848339, 0x4, 0xc000342e10, 0x47, 0x85e386, 0x75, 0x0, 0x0, 0x0, ...)
	D:/dev/go/pkg/mod/github.com/!synapse!f!i/[email protected]/users.go:43 +0x654
github.com/SynapseFI/SynapseGo.(*User).do(0xc0001e9c20, 0x848339, 0x4, 0xc000342e10, 0x47, 0x85e386, 0x75, 0x0, 0x0, 0x0, ...)
	D:/dev/go/pkg/mod/github.com/!synapse!f!i/[email protected]/users.go:62 +0x530
github.com/SynapseFI/SynapseGo.(*User).CreateNode(0xc0001e9c20, 0x85e386, 0x75, 0x0, 0x0, 0x0, 0x0, 0x2f7, 0x501870)

It seems to come from the following part of error.go file:

func handleHTTPError(d []byte) error {
	data := readStream(d)

	errCode := data["error_code"].(string)
	httpCode := data["http_code"].(string)
	msg := data["error"].(map[string]interface{})["en"].(string)

	return handleAPIError(errCode, httpCode, msg)
}

I tried with a standard DEPOSIT-US, and it works.
Any idea? Maybe it is linked to "MFA" (I used sandbox values which doesn't require MFA, and it works)

@nitharios

Thanks in advance! :)

IncorrectValues error handling

Hi @nathanielniosco

I'm trying to add documents to a user. If a value is not well formatted (lets say Legal name) in the users.go file, do method, it will be blocked inside the switch case IncorrectValues with the following error

{
  "error": {
    "en": "Invalid field value supplied. Invalid name supplied. Please supply fullname."
  },
  "error_code": "400",
  "http_code": "409",
  "success": false
}

It loops trying to then GetRefreshToken(), Authenticate() until it reachs the API request limit rate. Maybe those kind of errors should be handled differently ?

Thanks in advance :)

Create and authenticate user

I want to create and authenticate user, I'm following documentation with this snippet:

client.CreateUser(body, "IP_ADDRESS", "FINGERPRINT")
u := client.GetUser(userID, "FINGERPRINT", "IP_ADDRESS")
u.Authenticate(body)

Which produces:

[Error] HTTP_CODE 400 ERROR_CODE 200
Invalid User IP.

Note, the error comes from the user.Authenticate

If I change the order of arguments passed to CreateUser and GetUser to:

client.CreateUser(body, "FINGERPRINT", "IP_ADDRESS")
u := client.GetUser(userID, "IP_ADDRESS", "FINGERPRINT")
u.Authenticate(body)

Things seams to be working correctly (oauth_key returned, no errors).

Things get more interesting, because the code for client states that both, createUser and GetUser should use the same order of arguments (FINGERPRINT, IP_ADDRESS): https://github.com/SynapseFI/SynapseGo/blob/development/client.go#L267

So, the bug is:

  1. The docs are misleading or
  2. Something's wrong with the code (I'd expect GetUser to fail if I provided incorrect FINGERPRINT or IP_ADDRESS)

Library should not panic

The library uses panic in cases where it can return an error. Suggest in cases where multiple errors be returned to return the first error.

SynapseGo/request.go

Lines 56 to 58 in 9d3ed7f

if len(errs) > 0 {
panic(errs)
}

SynapseGo/request.go

Lines 84 to 86 in 9d3ed7f

if len(errs) > 0 {
panic(errs)
}

SynapseGo/request.go

Lines 112 to 114 in 9d3ed7f

if len(errs) > 0 {
panic(errs)
}

SynapseGo/request.go

Lines 133 to 135 in 9d3ed7f

if len(errs) > 0 {
panic(errs)
}

In this case I'd return an error here... Even better suggestion is to make the Response just be a []byte so that clients can marshal into their own structs, and get rid of readStream entirely.

SynapseGo/read.go

Lines 11 to 14 in 7a3e060

// if data is an empty stream this will cause an unmarshal error
if err != nil {
panic(err)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.