From 9789d6a9d3f2ba94ecae5b9381927bdca08d211c Mon Sep 17 00:00:00 2001 From: Nathaniel Niosco Date: Sun, 22 Sep 2019 13:48:27 -0700 Subject: [PATCH 1/4] read method returns two arguments --- read.go | 6 +++--- read_test.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/read.go b/read.go index 37a8452..51ec574 100644 --- a/read.go +++ b/read.go @@ -4,14 +4,14 @@ import ( "encoding/json" ) -func readStream(data []byte) map[string]interface{} { +func readStream(data []byte) (map[string]interface{}, error) { 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 nil, err } - return d + return d, nil } diff --git a/read_test.go b/read_test.go index 78f8bf7..05cfda9 100644 --- a/read_test.go +++ b/read_test.go @@ -38,7 +38,11 @@ func Test_Read(t *testing.T) { panic(err) } - testRes := readStream(td) + testRes, testResErr := readStream(td) + + if testResErr != nil { + panic(testResErr) + } assert.Equal(t, testData, testRes) } From 3a0097a0018bfe63daf5a2c1819192c0cc3fe3c7 Mon Sep 17 00:00:00 2001 From: Nathaniel Niosco Date: Sun, 22 Sep 2019 13:53:01 -0700 Subject: [PATCH 2/4] return results as byte array --- client.go | 55 ++++++++++++++++----------- client_test.go | 32 ++++++++-------- error.go | 6 ++- error_test.go | 2 +- request_test.go | 45 ++++++++++++++++------- users.go | 98 +++++++++++++++++++++++++++---------------------- users_test.go | 68 +++++++++++++++++----------------- 7 files changed, 174 insertions(+), 132 deletions(-) diff --git a/client.go b/client.go index 5969152..8f7a85a 100644 --- a/client.go +++ b/client.go @@ -96,7 +96,7 @@ type ( /********** METHODS **********/ -func (c *Client) do(method, url, data string, queryParams []string) (map[string]interface{}, error) { +func (c *Client) do(method, url, data string, queryParams []string) ([]byte, error) { var body []byte var err error @@ -114,7 +114,7 @@ func (c *Client) do(method, url, data string, queryParams []string) (map[string] body, err = c.request.Delete(url) } - return readStream(body), err + return body, err } /********** CLIENT **********/ @@ -151,7 +151,7 @@ func New(clientID, clientSecret, fingerprint, ipAddress string, modes ...bool) * /********** AUTHENTICATION **********/ // GetPublicKey returns a public key as a token representing client credentials -func (c *Client) GetPublicKey(scope ...string) (map[string]interface{}, error) { +func (c *Client) GetPublicKey(scope ...string) ([]byte, error) { log.info("========== GET PUBLIC KEY ==========") url := buildURL(path["client"]) defaultScope := "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS" @@ -169,7 +169,7 @@ func (c *Client) GetPublicKey(scope ...string) (map[string]interface{}, error) { /********** NODE **********/ // GetNodes returns all of the nodes -func (c *Client) GetNodes(queryParams ...string) (map[string]interface{}, error) { +func (c *Client) GetNodes(queryParams ...string) ([]byte, error) { log.info("========== GET CLIENT NODES ==========") url := buildURL(path["nodes"]) @@ -177,7 +177,7 @@ func (c *Client) GetNodes(queryParams ...string) (map[string]interface{}, error) } // GetTradeMarketData returns data on a stock based on its ticker symbol -func (c *Client) GetTradeMarketData(tickerSymbol string) (map[string]interface{}, error) { +func (c *Client) GetTradeMarketData(tickerSymbol string) ([]byte, error) { log.info("========== GET TRADE MARKET DATA ==========") url := buildURL(path["nodes"], "trade-market-watch") @@ -189,7 +189,7 @@ func (c *Client) GetTradeMarketData(tickerSymbol string) (map[string]interface{} /********** OTHER **********/ // GetCryptoMarketData returns market data for cryptocurrencies -func (c *Client) GetCryptoMarketData() (map[string]interface{}, error) { +func (c *Client) GetCryptoMarketData() ([]byte, error) { log.info("========== GET CRYPTO MARKET DATA ==========") url := buildURL(path["nodes"], "crypto-market-watch") @@ -197,7 +197,7 @@ func (c *Client) GetCryptoMarketData() (map[string]interface{}, error) { } // GetCryptoQuotes returns all of the quotes for crypto currencies -func (c *Client) GetCryptoQuotes(queryParams ...string) (map[string]interface{}, error) { +func (c *Client) GetCryptoQuotes(queryParams ...string) ([]byte, error) { log.info("========== GET CRYPTO QUOTES ==========") url := buildURL(path["nodes"], "crypto-quotes") @@ -205,7 +205,7 @@ func (c *Client) GetCryptoQuotes(queryParams ...string) (map[string]interface{}, } // GetInstitutions returns a list of all available banking institutions -func (c *Client) GetInstitutions() (map[string]interface{}, error) { +func (c *Client) GetInstitutions() ([]byte, error) { log.info("========== GET INSTITUTIONS ==========") url := buildURL(path["institutions"]) @@ -213,7 +213,7 @@ func (c *Client) GetInstitutions() (map[string]interface{}, error) { } // LocateATMs returns a list of nearby ATMs -func (c *Client) LocateATMs(queryParams ...string) (map[string]interface{}, error) { +func (c *Client) LocateATMs(queryParams ...string) ([]byte, error) { log.info("========== LOCATE ATMS ==========") url := buildURL(path["nodes"], "atms") @@ -221,7 +221,7 @@ func (c *Client) LocateATMs(queryParams ...string) (map[string]interface{}, erro } // VerifyAddress checks if an address if valid -func (c *Client) VerifyAddress(data string) (map[string]interface{}, error) { +func (c *Client) VerifyAddress(data string) ([]byte, error) { log.info("========== VERIFY ADDRESS ==========") url := buildURL("address-verification") @@ -229,7 +229,7 @@ func (c *Client) VerifyAddress(data string) (map[string]interface{}, error) { } // VerifyRoutingNumber checks and returns the bank details of a routing number -func (c *Client) VerifyRoutingNumber(data string) (map[string]interface{}, error) { +func (c *Client) VerifyRoutingNumber(data string) ([]byte, error) { log.info("========== VERIFY ROUTING NUMBER ==========") url := buildURL("routing-number-verification") @@ -239,7 +239,7 @@ func (c *Client) VerifyRoutingNumber(data string) (map[string]interface{}, error /********** SUBSCRIPTION **********/ // GetSubscriptions returns all of the nodes associated with a user -func (c *Client) GetSubscriptions(queryParams ...string) (map[string]interface{}, error) { +func (c *Client) GetSubscriptions(queryParams ...string) ([]byte, error) { log.info("========== GET SUBSCRIPTIONS ==========") url := buildURL(path["subscriptions"]) @@ -247,7 +247,7 @@ func (c *Client) GetSubscriptions(queryParams ...string) (map[string]interface{} } // GetSubscription returns a single subscription -func (c *Client) GetSubscription(subscriptionID string) (map[string]interface{}, error) { +func (c *Client) GetSubscription(subscriptionID string) ([]byte, error) { log.info("========== GET SUBSCRIPTION ==========") url := buildURL(path["subscriptions"], subscriptionID) @@ -255,7 +255,7 @@ func (c *Client) GetSubscription(subscriptionID string) (map[string]interface{}, } // CreateSubscription creates a subscription and returns the subscription data -func (c *Client) CreateSubscription(data string, idempotencyKey ...string) (map[string]interface{}, error) { +func (c *Client) CreateSubscription(data string, idempotencyKey ...string) ([]byte, error) { log.info("========== CREATE SUBSCRIPTION ==========") url := buildURL(path["subscriptions"]) @@ -263,7 +263,7 @@ func (c *Client) CreateSubscription(data string, idempotencyKey ...string) (map[ } // UpdateSubscription updates an existing subscription -func (c *Client) UpdateSubscription(subscriptionID string, data string) (map[string]interface{}, error) { +func (c *Client) UpdateSubscription(subscriptionID string, data string) ([]byte, error) { log.info("========== UPDATE SUBSCRIPTION ==========") url := buildURL(path["subscriptions"], subscriptionID) @@ -271,7 +271,7 @@ func (c *Client) UpdateSubscription(subscriptionID string, data string) (map[str } // GetWebhookLogs returns all of the webhooks sent to a specific client -func (c *Client) GetWebhookLogs() (map[string]interface{}, error) { +func (c *Client) GetWebhookLogs() ([]byte, error) { log.info("========== GET WEBHOOK LOGS ==========") url := buildURL(path["subscriptions"], "logs") @@ -281,7 +281,7 @@ func (c *Client) GetWebhookLogs() (map[string]interface{}, error) { /********** TRANSACTION **********/ // GetTransactions returns all client transactions -func (c *Client) GetTransactions(queryParams ...string) (map[string]interface{}, error) { +func (c *Client) GetTransactions(queryParams ...string) ([]byte, error) { log.info("========== GET CLIENT TRANSACTIONS ==========") url := buildURL(path["transactions"]) @@ -291,7 +291,7 @@ func (c *Client) GetTransactions(queryParams ...string) (map[string]interface{}, /********** USER **********/ // GetUsers returns a list of users -func (c *Client) GetUsers(queryParams ...string) (map[string]interface{}, error) { +func (c *Client) GetUsers(queryParams ...string) ([]byte, error) { log.info("========== GET CLIENT USERS ==========") url := buildURL(path["users"]) @@ -303,10 +303,15 @@ func (c *Client) GetUser(userID, fingerprint, ipAddress string, queryParams ...s log.info("========== GET USER ==========") url := buildURL(path["users"], userID) res, err := c.do("GET", url, "", queryParams) + response, resErr := readStream(res) + + if resErr != nil { + return nil, resErr + } var user User - mapstructure.Decode(res, &user) - user.Response = res + mapstructure.Decode(response, &user) + user.Response = response request := Request{ clientID: c.ClientID, clientSecret: c.ClientSecret, @@ -331,8 +336,14 @@ func (c *Client) CreateUser(data, fingerprint, ipAddress string, idempotencyKey url := buildURL(path["users"]) res, err := user.do("POST", url, data, idempotencyKey) - mapstructure.Decode(res, &user) - user.Response = res + response, resErr := readStream(res) + + if resErr != nil { + return nil, resErr + } + + mapstructure.Decode(response, &user) + user.Response = response return &user, err } diff --git a/client_test.go b/client_test.go index e5a817a..574d5db 100644 --- a/client_test.go +++ b/client_test.go @@ -64,7 +64,7 @@ func Test_GetPublicKey(t *testing.T) { testRes, err := testClient.GetPublicKey() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } /********** NODE **********/ @@ -77,7 +77,7 @@ func Test_GetClientNodes(t *testing.T) { testRes, err := testClient.GetNodes() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_GetTradeMarketData(t *testing.T) { @@ -88,7 +88,7 @@ func Test_GetTradeMarketData(t *testing.T) { testRes, err := testClient.GetTradeMarketData("") assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } /********** OTHER **********/ @@ -101,7 +101,7 @@ func Test_GetCryptoMarketData(t *testing.T) { testRes, err := testClient.GetCryptoMarketData() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_GetCryptoQuotes(t *testing.T) { @@ -112,7 +112,7 @@ func Test_GetCryptoQuotes(t *testing.T) { testRes, err := testClient.GetCryptoQuotes() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_GetInstitutions(t *testing.T) { @@ -123,7 +123,7 @@ func Test_GetInstitutions(t *testing.T) { testRes, err := testClient.GetInstitutions() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_LocateATMs(t *testing.T) { @@ -134,7 +134,7 @@ func Test_LocateATMs(t *testing.T) { testRes, err := testClient.LocateATMs() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_VerifyAddress(t *testing.T) { @@ -144,7 +144,7 @@ func Test_VerifyAddress(t *testing.T) { testRes, err := testClient.VerifyAddress("") assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_VerifyRoutingNumber(t *testing.T) { @@ -154,7 +154,7 @@ func Test_VerifyRoutingNumber(t *testing.T) { testRes, err := testClient.VerifyRoutingNumber("") assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } /********** SUBSCRIPTION **********/ @@ -167,7 +167,7 @@ func Test_GetSubscriptions(t *testing.T) { testRes, err := testClient.GetSubscriptions() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_GetSubscription(t *testing.T) { @@ -178,7 +178,7 @@ func Test_GetSubscription(t *testing.T) { testRes, err := testClient.GetSubscription("") assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_CreateSubscription(t *testing.T) { @@ -189,7 +189,7 @@ func Test_CreateSubscription(t *testing.T) { testRes, err := testClient.CreateSubscription("") assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_UpdateSubscription(t *testing.T) { @@ -200,7 +200,7 @@ func Test_UpdateSubscription(t *testing.T) { testRes, err := testClient.CreateSubscription("") assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_GetWebhookLogs(t *testing.T) { @@ -211,7 +211,7 @@ func Test_GetWebhookLogs(t *testing.T) { testRes, err := testClient.GetWebhookLogs() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } /********** TRANSACTION **********/ @@ -223,7 +223,7 @@ func Test_GetClientTransactions(t *testing.T) { testRes, err := testClient.GetTransactions() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } /********** USER **********/ @@ -236,7 +236,7 @@ func Test_GetUsers(t *testing.T) { testRes, err := testClient.GetUsers() assert.NoError(err) - assert.Equal(testRes, mockClientResponse) + assert.NotNil(testRes) } func Test_GetUser(t *testing.T) { diff --git a/error.go b/error.go index 85dd151..2fcc1fc 100644 --- a/error.go +++ b/error.go @@ -206,7 +206,11 @@ func handleAPIError(errorCode, httpCode, message string) error { } func handleHTTPError(d []byte) error { - data := readStream(d) + data, err := readStream(d) + + if err != nil { + return err + } errCode := data["error_code"].(string) httpCode := data["http_code"].(string) diff --git a/error_test.go b/error_test.go index d6c9b2f..92ee9a8 100644 --- a/error_test.go +++ b/error_test.go @@ -35,7 +35,7 @@ func Test_HandleHTTPError(t *testing.T) { httpCode := errData["http_code"].(string) errCode := errData["error_code"].(string) msg := errData["error"].(map[string]interface{})["en"].(string) - responseMsg := "HTTP_CODE " + httpCode + " ERROR_CODE " + errCode + "\n" + msg + responseMsg := "http_code " + httpCode + " error_code " + errCode + " " + msg // error message should be an error and print error code plus original API message assert.EqualError(testErr, responseMsg) diff --git a/request_test.go b/request_test.go index 42b6b60..fe8c62d 100644 --- a/request_test.go +++ b/request_test.go @@ -59,37 +59,54 @@ func Test_Post(t *testing.T) { testData := requestData["POST"].(map[string]interface{})["data"] - jsonData, jsonErr := json.Marshal(testData) + jsonData, err := json.Marshal(testData) + + if err != nil { + t.Error(err) + } + + userRes, err := testReq.Get(buildURL(path["users"], "/5bec6ebebaabfc00ab168fa0"), nil) + + if err != nil { + t.Error(err) + } + + res, err := readStream(userRes) - if jsonErr != nil { - t.Error(jsonErr) + if err != nil { + t.Error(err) } - userRes, userErr := testReq.Get(buildURL(path["users"], "/5bec6ebebaabfc00ab168fa0"), nil) + authRes, err := testReq.Post(buildURL(path["auth"], "/5bec6ebebaabfc00ab168fa0"), `{ "refresh_token": "`+res["refresh_token"].(string)+`" }`, nil) - if userErr != nil { - t.Error(userErr) + if err != nil { + t.Error(err) } - rt := readStream(userRes)["refresh_token"].(string) - authRes, authErr := testReq.Post(buildURL(path["auth"], "/5bec6ebebaabfc00ab168fa0"), `{ "refresh_token": "`+rt+`" }`, nil) + authResponse, err := readStream(authRes) - if authErr != nil { - t.Error(authErr) + if err != nil { + t.Error(err) } - authKey = readStream(authRes)["oauth_key"].(string) + authKey = authResponse["oauth_key"].(string) testReq.authKey = authKey - res, err := testReq.Post(buildURL(path["users"], "/5bec6ebebaabfc00ab168fa0/nodes"), string(jsonData), nil) + postRes, err := testReq.Post(buildURL(path["users"], "/5bec6ebebaabfc00ab168fa0/nodes"), string(jsonData), nil) + + if err != nil { + t.Error(err) + } + + postResponse, err := readStream(postRes) if err != nil { t.Error(err) } - testID = readStream(res)["nodes"].([]interface{})[0].(map[string]interface{})["_id"].(string) + testID = postResponse["nodes"].([]interface{})[0].(map[string]interface{})["_id"].(string) - assert.NotNil(string(res)) + assert.NotNil(string(postRes)) } func Test_Patch(t *testing.T) { diff --git a/users.go b/users.go index 0547cb0..aeb00af 100644 --- a/users.go +++ b/users.go @@ -30,7 +30,7 @@ type ( /********** METHODS **********/ -func (u *User) do(method, url, data string, params []string) (map[string]interface{}, error) { +func (u *User) do(method, url, data string, params []string) ([]byte, error) { var response []byte var err error @@ -50,7 +50,7 @@ func (u *User) do(method, url, data string, params []string) (map[string]interfa switch err.(type) { case *ActionPending: - return readStream(response), err + return response, err case *UnauthorizedAction: res, authErr := u.Authenticate(`{ "refresh_token": "`+u.RefreshToken+`" }`, u.request.fingerprint, u.request.ipAddress) @@ -80,7 +80,7 @@ func (u *User) do(method, url, data string, params []string) (map[string]interfa // return u.do(method, url, data, params) } - return readStream(response), err + return response, err } /********** AUTHENTICATION **********/ @@ -88,41 +88,51 @@ func (u *User) do(method, url, data string, params []string) (map[string]interfa // Authenticate returns an oauth key and sets it to the user object // If the refresh token is expired the API will automatically send a new one // Capture refresh token every time -func (u *User) Authenticate(data, fingerprint, ipAddress string) (map[string]interface{}, error) { +func (u *User) Authenticate(data, fingerprint, ipAddress string) ([]byte, error) { log.info("========== AUTHENTICATE ==========") url := buildURL(path["auth"], u.UserID) u.request.updateRequest(u.request.clientID, u.request.clientSecret, fingerprint, ipAddress) res, err := u.do("POST", url, data, nil) + response, resErr := readStream(res) - if res["refresh_token"] != nil { - u.RefreshToken = res["refresh_token"].(string) + if resErr != nil { + return nil, resErr } - if res["oauth_key"] != nil { - u.AuthKey = res["oauth_key"].(string) - u.request.authKey = res["oauth_key"].(string) + if response["refresh_token"] != nil { + u.RefreshToken = response["refresh_token"].(string) + } + + if response["oauth_key"] != nil { + u.AuthKey = response["oauth_key"].(string) + u.request.authKey = response["oauth_key"].(string) } return res, err } // GetRefreshToken performs a GET request and returns a new refresh token -func (u *User) GetRefreshToken() (map[string]interface{}, error) { +func (u *User) GetRefreshToken() ([]byte, error) { log.info("========== GET REFRESH TOKEN ==========") url := buildURL(path["users"], u.UserID) res, err := u.do("GET", url, "", nil) + response, resErr := readStream(res) + + if resErr != nil { + return nil, resErr + } - if res["refresh_token"] != nil { - u.RefreshToken = res["refresh_token"].(string) + if response["refresh_token"] != nil { + u.RefreshToken = response["refresh_token"].(string) } return res, err } // RegisterFingerprint submits a new fingerprint and triggers the MFA flow -func (u *User) RegisterFingerprint(fp string) (map[string]interface{}, error) { +func (u *User) RegisterFingerprint(fp string) ([]byte, error) { log.info("========== REGISTER FINGERPRINT ==========") url := buildURL(path["auth"], u.UserID) @@ -136,7 +146,7 @@ func (u *User) RegisterFingerprint(fp string) (map[string]interface{}, error) { } // Select2FA sends the 2FA device selection to the API -func (u *User) Select2FA(device string) (map[string]interface{}, error) { +func (u *User) Select2FA(device string) ([]byte, error) { log.info("========== SELECT 2FA DEVICE ==========") url := buildURL(path["auth"], u.UserID) @@ -148,7 +158,7 @@ func (u *User) Select2FA(device string) (map[string]interface{}, error) { } // SubmitMFA submits the access token and mfa answer -func (u *User) SubmitMFA(data string) (map[string]interface{}, error) { +func (u *User) SubmitMFA(data string) ([]byte, error) { log.info("========== SUBMIT MFA RESPONSE ==========") url := buildURL(path["users"], u.UserID, path["nodes"]) @@ -156,7 +166,7 @@ func (u *User) SubmitMFA(data string) (map[string]interface{}, error) { } // VerifyPIN sends the requested pin to the API to complete the 2FA process -func (u *User) VerifyPIN(pin string) (map[string]interface{}, error) { +func (u *User) VerifyPIN(pin string) ([]byte, error) { log.info("========== VERIFY PIN ==========") url := buildURL(path["auth"], u.UserID) @@ -170,7 +180,7 @@ func (u *User) VerifyPIN(pin string) (map[string]interface{}, error) { /********** NODE **********/ // GetNodes returns all of the nodes associated with a user -func (u *User) GetNodes(queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetNodes(queryParams ...string) ([]byte, error) { log.info("========== GET USER NODES ==========") url := buildURL(path["users"], u.UserID, path["nodes"]) @@ -178,7 +188,7 @@ func (u *User) GetNodes(queryParams ...string) (map[string]interface{}, error) { } // GetNode returns a single node object -func (u *User) GetNode(nodeID string) (map[string]interface{}, error) { +func (u *User) GetNode(nodeID string) ([]byte, error) { log.info("========== GET NODE ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) @@ -188,7 +198,7 @@ func (u *User) GetNode(nodeID string) (map[string]interface{}, error) { } // CreateNode creates a node depending on the type of node specified -func (u *User) CreateNode(data string, idempotencyKey ...string) (map[string]interface{}, error) { +func (u *User) CreateNode(data string, idempotencyKey ...string) ([]byte, error) { log.info("========== CREATE NODE ==========") url := buildURL(path["users"], u.UserID, path["nodes"]) @@ -196,7 +206,7 @@ func (u *User) CreateNode(data string, idempotencyKey ...string) (map[string]int } // UpdateNode updates a node -func (u *User) UpdateNode(nodeID, data string) (map[string]interface{}, error) { +func (u *User) UpdateNode(nodeID, data string) ([]byte, error) { log.info("========== UPDATE NODE ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) @@ -204,7 +214,7 @@ func (u *User) UpdateNode(nodeID, data string) (map[string]interface{}, error) { } // DeleteNode deletes a node -func (u *User) DeleteNode(nodeID string) (map[string]interface{}, error) { +func (u *User) DeleteNode(nodeID string) ([]byte, error) { log.info("========== DELETE NODE ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) @@ -214,7 +224,7 @@ func (u *User) DeleteNode(nodeID string) (map[string]interface{}, error) { /********** NODE (OTHER) **********/ // VerifyMicroDeposit verifies micro-deposit amounts for a node -func (u *User) VerifyMicroDeposit(nodeID, data string) (map[string]interface{}, error) { +func (u *User) VerifyMicroDeposit(nodeID, data string) ([]byte, error) { log.info("========== VERIFY MICRO-DEPOSITS ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) @@ -222,7 +232,7 @@ func (u *User) VerifyMicroDeposit(nodeID, data string) (map[string]interface{}, } // ReinitiateMicroDeposits reinitiates micro-deposits for an ACH-US node with AC/RT -func (u *User) ReinitiateMicroDeposits(nodeID string) (map[string]interface{}, error) { +func (u *User) ReinitiateMicroDeposits(nodeID string) ([]byte, error) { log.info("========== RE-INITIATE MICRO-DEPOSITS ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) + "?resend_micro=YES" @@ -230,7 +240,7 @@ func (u *User) ReinitiateMicroDeposits(nodeID string) (map[string]interface{}, e } // ResetCardNode resets the debit card number, card cvv, and expiration date -func (u *User) ResetCardNode(nodeID string) (map[string]interface{}, error) { +func (u *User) ResetCardNode(nodeID string) ([]byte, error) { log.info("========== RESET CARD ==========)") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) + "?reset=YES" @@ -238,7 +248,7 @@ func (u *User) ResetCardNode(nodeID string) (map[string]interface{}, error) { } // ShipCardNode ships a physical debit card out to the user -func (u *User) ShipCardNode(nodeID, data string) (map[string]interface{}, error) { +func (u *User) ShipCardNode(nodeID, data string) ([]byte, error) { log.info("========== SHIP CARD ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) + "?ship=YES" @@ -246,7 +256,7 @@ func (u *User) ShipCardNode(nodeID, data string) (map[string]interface{}, error) } // GetApplePayToken generates tokenized info for Apple Wallet -func (u *User) GetApplePayToken(nodeID, data string) (map[string]interface{}, error) { +func (u *User) GetApplePayToken(nodeID, data string) ([]byte, error) { log.info("========== GET APPLE PAY TOKEN ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, "applepay") @@ -256,7 +266,7 @@ func (u *User) GetApplePayToken(nodeID, data string) (map[string]interface{}, er /********** STATEMENT **********/ // GetStatements gets all of the user statements -func (u *User) GetStatements(queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetStatements(queryParams ...string) ([]byte, error) { log.info("========== GET USER STATEMENTS ==========") url := buildURL(path["users"], u.UserID, path["statements"]) @@ -264,7 +274,7 @@ func (u *User) GetStatements(queryParams ...string) (map[string]interface{}, err } // GetNodeStatements gets all of the node statements -func (u *User) GetNodeStatements(nodeID string, queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetNodeStatements(nodeID string, queryParams ...string) ([]byte, error) { log.info("========== GET NODE STATEMENTS ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["statements"]) @@ -272,7 +282,7 @@ func (u *User) GetNodeStatements(nodeID string, queryParams ...string) (map[stri } // CreateNodeStatements creates ad-hoc statements for the specified node -func (u *User) CreateNodeStatements(nodeID, data string, idempotencyKey ...string) (map[string]interface{}, error) { +func (u *User) CreateNodeStatements(nodeID, data string, idempotencyKey ...string) ([]byte, error) { log.info("========== CREATE AD-HOC STATEMENT ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["statements"]) @@ -282,7 +292,7 @@ func (u *User) CreateNodeStatements(nodeID, data string, idempotencyKey ...strin /********** SUBNET **********/ // GetSubnets gets all subnets associated with a user -func (u *User) GetSubnets(queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetSubnets(queryParams ...string) ([]byte, error) { log.info("========== GET USER SUBNETS ==========") url := buildURL(path["users"], u.UserID, path["subnets"]) @@ -290,7 +300,7 @@ func (u *User) GetSubnets(queryParams ...string) (map[string]interface{}, error) } // GetNodeSubnets gets all subnets associated with a node -func (u *User) GetNodeSubnets(nodeID string, queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetNodeSubnets(nodeID string, queryParams ...string) ([]byte, error) { log.info("========== GET NODE SUBNETS ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["subnets"]) @@ -298,7 +308,7 @@ func (u *User) GetNodeSubnets(nodeID string, queryParams ...string) (map[string] } // GetSubnet gets a single subnet object -func (u *User) GetSubnet(nodeID, subnetID string) (map[string]interface{}, error) { +func (u *User) GetSubnet(nodeID, subnetID string) ([]byte, error) { log.info("========== GET SUBNET ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["subnets"], subnetID) @@ -306,7 +316,7 @@ func (u *User) GetSubnet(nodeID, subnetID string) (map[string]interface{}, error } // CreateSubnet creates a subnet object -func (u *User) CreateSubnet(nodeID, data string, idempotencyKey ...string) (map[string]interface{}, error) { +func (u *User) CreateSubnet(nodeID, data string, idempotencyKey ...string) ([]byte, error) { log.info("========== CREATE SUBNET ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["subnets"]) @@ -314,7 +324,7 @@ func (u *User) CreateSubnet(nodeID, data string, idempotencyKey ...string) (map[ } // UpdateSubnet updates a subnet object -func (u *User) UpdateSubnet(nodeID, subnetID, data string) (map[string]interface{}, error) { +func (u *User) UpdateSubnet(nodeID, subnetID, data string) ([]byte, error) { log.info("========== UPDATE SUBNET ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["subnets"], subnetID) @@ -322,7 +332,7 @@ func (u *User) UpdateSubnet(nodeID, subnetID, data string) (map[string]interface } // ShipCard ships a physical debit card out to the user -func (u *User) ShipCard(nodeID, subnetID, data string) (map[string]interface{}, error) { +func (u *User) ShipCard(nodeID, subnetID, data string) ([]byte, error) { log.info("========== SHIP CARD SUBNET ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["subnets"], subnetID, "ship") @@ -332,7 +342,7 @@ func (u *User) ShipCard(nodeID, subnetID, data string) (map[string]interface{}, /********** TRANSACTION **********/ // GetTransactions returns transactions associated with a user -func (u *User) GetTransactions(queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetTransactions(queryParams ...string) ([]byte, error) { log.info("========== GET USER TRANSACTIONS ==========") url := buildURL(path["users"], u.UserID, path["transactions"]) @@ -340,7 +350,7 @@ func (u *User) GetTransactions(queryParams ...string) (map[string]interface{}, e } // GetNodeTransactions returns transactions associated with a node -func (u *User) GetNodeTransactions(nodeID string, queryParams ...string) (map[string]interface{}, error) { +func (u *User) GetNodeTransactions(nodeID string, queryParams ...string) ([]byte, error) { log.info("========== GET NODE TRANSACTIONS ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["transactions"]) @@ -348,7 +358,7 @@ func (u *User) GetNodeTransactions(nodeID string, queryParams ...string) (map[st } // GetTransaction returns a specific transaction associated with a node -func (u *User) GetTransaction(nodeID, transactionID string) (map[string]interface{}, error) { +func (u *User) GetTransaction(nodeID, transactionID string) ([]byte, error) { log.info("========== GET TRANSACTION ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["transactions"], transactionID) @@ -356,7 +366,7 @@ func (u *User) GetTransaction(nodeID, transactionID string) (map[string]interfac } // CreateTransaction creates a transaction for the specified node -func (u *User) CreateTransaction(nodeID, data string, idempotencyKey ...string) (map[string]interface{}, error) { +func (u *User) CreateTransaction(nodeID, data string, idempotencyKey ...string) ([]byte, error) { log.info("========== CREATE TRANSACTION ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["transactions"]) @@ -364,7 +374,7 @@ func (u *User) CreateTransaction(nodeID, data string, idempotencyKey ...string) } // CancelTransaction deletes/cancels a transaction -func (u *User) CancelTransaction(nodeID, transactionID string) (map[string]interface{}, error) { +func (u *User) CancelTransaction(nodeID, transactionID string) ([]byte, error) { log.info("========== CANCEL TRANSACTION ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["transactions"], transactionID) @@ -372,7 +382,7 @@ func (u *User) CancelTransaction(nodeID, transactionID string) (map[string]inter } // CommentOnTransactionStatus adds comment to the transaction status -func (u *User) CommentOnTransactionStatus(nodeID, transactionID, data string, idempotencyKey ...string) (map[string]interface{}, error) { +func (u *User) CommentOnTransactionStatus(nodeID, transactionID, data string, idempotencyKey ...string) ([]byte, error) { log.info("========== COMMENT ON TRANSACTION STATUS ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["transactions"], transactionID) @@ -380,7 +390,7 @@ func (u *User) CommentOnTransactionStatus(nodeID, transactionID, data string, id } // DisputeTransaction disputes a transaction for a user -func (u *User) DisputeTransaction(nodeID, transactionID, data string) (map[string]interface{}, error) { +func (u *User) DisputeTransaction(nodeID, transactionID, data string) ([]byte, error) { log.info("========== DISPUTE TRANSACTION ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID, path["transactions"], transactionID, "dispute") @@ -388,7 +398,7 @@ func (u *User) DisputeTransaction(nodeID, transactionID, data string) (map[strin } // CreateDummyTransaction triggers external dummy transactions on internal accounts -func (u *User) CreateDummyTransaction(nodeID string, queryParams ...string) (map[string]interface{}, error) { +func (u *User) CreateDummyTransaction(nodeID string, queryParams ...string) ([]byte, error) { log.info("========== CREATE DUMMY TRANSACTION ==========") url := buildURL(path["users"], u.UserID, path["nodes"], nodeID) + "/dummy-tran" @@ -410,7 +420,7 @@ func (u *User) Update(data string) (*User, error) { } // CreateUBO creates and uploads an Ultimate Beneficial Ownership (UBO) and REG GG form as a physical document under the Business’s base document -func (u *User) CreateUBO(data string) (map[string]interface{}, error) { +func (u *User) CreateUBO(data string) ([]byte, error) { log.info("========== CREATE UBO ==========") url := buildURL(path["users"], u.UserID, "ubo") diff --git a/users_test.go b/users_test.go index c6017b2..4ad2259 100644 --- a/users_test.go +++ b/users_test.go @@ -60,7 +60,7 @@ func Test_Authenticate(t *testing.T) { testRes, err := testUser.Authenticate("", "", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetRefreshToken(t *testing.T) { @@ -71,7 +71,7 @@ func Test_GetRefreshToken(t *testing.T) { testRes, err := testUser.GetRefreshToken() assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_RegisterFingerprint(t *testing.T) { @@ -82,7 +82,7 @@ func Test_RegisterFingerprint(t *testing.T) { testRes, err := testUser.RegisterFingerprint("TEST_FINGERPRINT") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_Select2FA(t *testing.T) { @@ -93,7 +93,7 @@ func Test_Select2FA(t *testing.T) { testRes, err := testUser.Select2FA("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_SubmitMFA(t *testing.T) { @@ -104,7 +104,7 @@ func Test_SubmitMFA(t *testing.T) { testRes, err := testUser.SubmitMFA("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_VerifyPIN(t *testing.T) { @@ -115,7 +115,7 @@ func Test_VerifyPIN(t *testing.T) { testRes, err := testUser.VerifyPIN("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } /********** NODE **********/ @@ -128,7 +128,7 @@ func Test_GetNodes(t *testing.T) { testRes, err := testUser.GetNodes() assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetNode(t *testing.T) { @@ -139,7 +139,7 @@ func Test_GetNode(t *testing.T) { testRes, err := testUser.GetNode("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_CreateNode(t *testing.T) { @@ -150,7 +150,7 @@ func Test_CreateNode(t *testing.T) { testRes, err := testUser.CreateNode("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_UpdateNode(t *testing.T) { @@ -161,7 +161,7 @@ func Test_UpdateNode(t *testing.T) { testRes, err := testUser.UpdateNode("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } // should delete node created in previous test? @@ -173,7 +173,7 @@ func Test_DeleteNode(t *testing.T) { testRes, err := testUser.DeleteNode("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } /********** NODE (OTHER) **********/ @@ -186,7 +186,7 @@ func Test_VerifyMicroDeposit(t *testing.T) { testRes, err := testUser.VerifyMicroDeposit("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_ReinitiateMicroDeposits(t *testing.T) { @@ -197,7 +197,7 @@ func Test_ReinitiateMicroDeposits(t *testing.T) { testRes, err := testUser.ReinitiateMicroDeposits("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_ResetCardNode(t *testing.T) { @@ -208,7 +208,7 @@ func Test_ResetCardNode(t *testing.T) { testRes, err := testUser.ResetCardNode("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_ShipCardNode(t *testing.T) { @@ -219,7 +219,7 @@ func Test_ShipCardNode(t *testing.T) { testRes, err := testUser.ShipCardNode("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetApplePayToken(t *testing.T) { @@ -230,7 +230,7 @@ func Test_GetApplePayToken(t *testing.T) { testRes, err := testUser.GetApplePayToken("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } /********** STATEMENT **********/ @@ -243,7 +243,7 @@ func Test_GetStatements(t *testing.T) { testRes, err := testUser.GetStatements("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetNodeStatements(t *testing.T) { @@ -254,7 +254,7 @@ func Test_GetNodeStatements(t *testing.T) { testRes, err := testUser.GetNodeStatements("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_CreateNodeStatements(t *testing.T) { @@ -265,7 +265,7 @@ func Test_CreateNodeStatements(t *testing.T) { testRes, err := testUser.CreateNodeStatements("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } /********** SUBNET **********/ @@ -278,7 +278,7 @@ func Test_GetSubnets(t *testing.T) { testRes, err := testUser.GetSubnets() assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetNodeSubnets(t *testing.T) { @@ -289,7 +289,7 @@ func Test_GetNodeSubnets(t *testing.T) { testRes, err := testUser.GetNodeSubnets("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetSubnet(t *testing.T) { @@ -300,7 +300,7 @@ func Test_GetSubnet(t *testing.T) { testRes, err := testUser.GetSubnet("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_CreateSubnet(t *testing.T) { @@ -311,7 +311,7 @@ func Test_CreateSubnet(t *testing.T) { testRes, err := testUser.CreateSubnet("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_UpdateSubnet(t *testing.T) { @@ -322,7 +322,7 @@ func Test_UpdateSubnet(t *testing.T) { testRes, err := testUser.UpdateSubnet("", "", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_ShipCard(t *testing.T) { @@ -332,7 +332,7 @@ func Test_ShipCard(t *testing.T) { testRes, err := testUser.ShipCard("", "", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } /********** TRANSACTION **********/ @@ -345,7 +345,7 @@ func Test_GetTransactions(t *testing.T) { testRes, err := testUser.GetTransactions("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetNodeTransactions(t *testing.T) { @@ -355,7 +355,7 @@ func Test_GetNodeTransactions(t *testing.T) { testRes, err := testUser.GetNodeTransactions("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_GetTransaction(t *testing.T) { @@ -366,7 +366,7 @@ func Test_GetTransaction(t *testing.T) { testRes, err := testUser.GetTransaction("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_CreateTransaction(t *testing.T) { @@ -377,7 +377,7 @@ func Test_CreateTransaction(t *testing.T) { testRes, err := testUser.CreateTransaction("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_CancelTransaction(t *testing.T) { @@ -388,7 +388,7 @@ func Test_CancelTransaction(t *testing.T) { testRes, err := testUser.CancelTransaction("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } @@ -400,7 +400,7 @@ func Test_CommentOnTransactionStatus(t *testing.T) { testRes, err := testUser.CommentOnTransactionStatus("", "", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_DisputeTransaction(t *testing.T) { @@ -411,7 +411,7 @@ func Test_DisputeTransaction(t *testing.T) { testRes, err := testUser.DisputeTransaction("", "", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } func Test_CreateDummyTransaction(t *testing.T) { @@ -422,7 +422,7 @@ func Test_CreateDummyTransaction(t *testing.T) { testRes, err := testUser.CreateDummyTransaction("", "") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } /********** USER **********/ @@ -450,5 +450,5 @@ func Test_CreateUBO(t *testing.T) { testRes, err := testUser.CreateUBO("") assert.NoError(err) - assert.Equal(testRes, mockUsersResponse) + assert.NotNil(testRes) } From 8d7b1020ab131c127f9227817ccb10119dbb3765 Mon Sep 17 00:00:00 2001 From: Nathaniel Niosco Date: Sun, 22 Sep 2019 14:06:22 -0700 Subject: [PATCH 3/4] module update --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7ef6d45..c97067e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/SynapseFI/SynapseGo +module github.com/SynapseFI/SynapseGo/v0.1.0 require ( github.com/davecgh/go-spew v1.1.1 // indirect From 0ebd7eb80866a3196d7dcc672f4b367218c975e3 Mon Sep 17 00:00:00 2001 From: Nathaniel Niosco Date: Sun, 22 Sep 2019 14:21:17 -0700 Subject: [PATCH 4/4] remove module update --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c97067e..7ef6d45 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/SynapseFI/SynapseGo/v0.1.0 +module github.com/SynapseFI/SynapseGo require ( github.com/davecgh/go-spew v1.1.1 // indirect