Repository: VictorAvelar/mollie-api-go
Pull request #2 (2019-08-25 21:34:47)

Fix typos and var reference errors


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f685e44..604d09c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,8 +13,13 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
 ### Deprecated
 - Nothing
 
+### Changed
+- ClientContext for Ctx in APIClient
+
 ### Fixed
-- Nothing
+- Missing types for MOLLIE env variables
+- Named variable reference on NewClient method
+- Typos and spelling errors on method's comments
 
 ### Removed
 - Nothing
diff --git a/README.md b/README.md
index b867180..fe75d8e 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
-# Mollie API Golang client
+# Mollie API Golang client 
+
+[![Build Status](https://travis-ci.org/VictorAvelar/mollie-api-go.svg?branch=master)](https://travis-ci.org/VictorAvelar/mollie-api-go)
 
 Accepting [iDEAL](https://www.mollie.com/payments/ideal/), [Apple Pay](https://www.mollie.com/payments/apple-pay), [Bancontact](https://www.mollie.com/payments/bancontact/), [SOFORT Banking](https://www.mollie.com/payments/sofort/), [Creditcard](https://www.mollie.com/payments/credit-card/), [SEPA Bank transfer](https://www.mollie.com/payments/bank-transfer/), [SEPA Direct debit](https://www.mollie.com/payments/direct-debit/), [PayPal](https://www.mollie.com/payments/paypal/), [Belfius Direct Net](https://www.mollie.com/payments/belfius/), [KBC/CBC](https://www.mollie.com/payments/kbc-cbc/), [paysafecard](https://www.mollie.com/payments/paysafecard/), [ING Home'Pay](https://www.mollie.com/payments/ing-homepay/), [Giftcards](https://www.mollie.com/payments/gift-cards/), [Giropay](https://www.mollie.com/payments/giropay/), [EPS](https://www.mollie.com/payments/eps/) and [Przelewy24](https://www.mollie.com/payments/przelewy24/) online payments without fixed monthly costs or any punishing registration procedures. Just use the Mollie API to receive payments directly on your website or easily refund transactions to your customers.
 
@@ -15,9 +17,9 @@ For leveraging [Mollie Connect](https://docs.mollie.com/oauth/overview) (advance
 ## Roadmap
 - [x] Project setup
 - [x] Base HTTP Client
-- [ ] Authentication
-    - [ ] API token
-    - [ ] Organization token
+- [x] Authentication
+    - [x] API token
+    - [x] Organization token
 - [ ] Payments
     - [ ] Recurring payments
     - [ ] Multicurrency payments
diff --git a/mollie/mollie.go b/mollie/mollie.go
index a2afb4e..a148971 100644
--- a/mollie/mollie.go
+++ b/mollie/mollie.go
@@ -10,14 +10,14 @@ import (
 	"strings"
 )
 
-// Mollie  constanst holding values to initialize the client and create requests.
+// Mollie  constants holding values to initialize the client and create requests.
 const (
 	BaseURL     string = "https://api.mollie.com"
 	APIVersion  string = "v2"
 	AuthHeader  string = "authorization"
 	TokenType   string = "Bearer"
-	APITokenEnv        = "MOLLIE_API_TOKEN"
-	OrgTokenEnv        = "MOLLIE_ORG_TOKEN"
+	APITokenEnv string = "MOLLIE_API_TOKEN"
+	OrgTokenEnv string = "MOLLIE_ORG_TOKEN"
 )
 
 var (
@@ -28,10 +28,10 @@ type httpClient interface {
 	Do(req *http.Request) (res *http.Response, err error)
 }
 
-//APIClient struct contains the httpClient plus information related to the
+//APIClient for Mollie API plus information related to the
 // different authentication methods provided by the API.
 type APIClient struct {
-	ClientContext     context.Context
+	Ctx               context.Context
 	HTTPClient        httpClient
 	BaseURL           *url.URL
 	APIKey            string
@@ -47,7 +47,7 @@ func (c *APIClient) WithAPIKey(k string) error {
 		return errEmptyAPIKey
 	}
 
-	c.APIKey = strings.Trim(k, " ")
+	c.APIKey = strings.TrimSpace(k)
 
 	return nil
 }
@@ -60,16 +60,13 @@ func (c *APIClient) WithOrganizationToken(t string) error {
 	if t == "" {
 		return errEmptyAPIKey
 	}
-
-	c.OrganizationToken = t
-
+	c.OrganizationToken = strings.TrimSpace(t)
 	return nil
 }
 
-//NewAPIRequest is a wrapper arount the http.NewRequest function.
+//NewAPIRequest is a wrapper around the http.NewRequest function.
 //It takes the same parameters plus a flag to indicate if the request needs
 //to have the authorization headers.
-//The http request method defaults to GET if no method is set.
 //For setting up the headers it takes a hierarchical approach, this meaning that
 //if set the APIClient.OrganizationToken will be used, if this value is empty then
 //it will attemp to use the APIClient.APIKey, and if this value is also empty it
@@ -83,9 +80,9 @@ func (c *APIClient) NewAPIRequest(m string, uri string, body io.Reader, auth boo
 	rel, _ := url.Parse(uri)
 
 	uri = c.BaseURL.ResolveReference(rel).String()
-	req, bErr := http.NewRequest(m, uri, body)
+	req, err = http.NewRequest(m, uri, body)
 	if err != nil {
-		return nil, bErr
+		return
 	}
 
 	req.Header.Add("accept", "application/json")
@@ -120,7 +117,6 @@ func NewClient(ctx context.Context, baseClient httpClient, uri string) (mollie *
 	if ctx == nil {
 		ctx = context.Background()
 	}
-
 	if baseClient == nil {
 		baseClient = http.DefaultClient
 	}
@@ -130,19 +126,16 @@ func NewClient(ctx context.Context, baseClient httpClient, uri string) (mollie *
 		return
 	}
 
-	c := &APIClient{
-		ClientContext: ctx,
-		HTTPClient:    baseClient,
-		BaseURL:       u,
+	mollie = &APIClient{
+		Ctx:        ctx,
+		HTTPClient: baseClient,
+		BaseURL:    u,
 	}
-
 	if tkn, ok := os.LookupEnv(APITokenEnv); ok {
-		c.APIKey = tkn
+		mollie.APIKey = tkn
 	}
-
 	if orgTkn, ok := os.LookupEnv(OrgTokenEnv); ok {
-		c.OrganizationToken = orgTkn
+		mollie.OrganizationToken = orgTkn
 	}
-
-	return c, nil
+	return
 }


Test patch:
diff --git a/mollie/mollie_test.go b/mollie/mollie_test.go
index 2305bec..7e34e2a 100644
--- a/mollie/mollie_test.go
+++ b/mollie/mollie_test.go
@@ -53,7 +53,7 @@ func TestNewClient(t *testing.T) {
 		t.Fail()
 	}
 	want := &APIClient{
-		ClientContext:     context.Background(),
+		Ctx:               context.Background(),
 		HTTPClient:        http.DefaultClient,
 		BaseURL:           u,
 		APIKey:            "",
@@ -115,7 +115,7 @@ func TestNewClient_WithEnvVars(t *testing.T) {
 		t.Fail()
 	}
 	want := &APIClient{
-		ClientContext:     context.Background(),
+		Ctx:               context.Background(),
 		HTTPClient:        http.DefaultClient,
 		BaseURL:           u,
 		APIKey:            "token_X12b31ggg23",