-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
923 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,10 @@ | |
This library provides convenient access to the eWarehousing Solutions API from applications written in the Go | ||
language. | ||
|
||
|
||
## Documentation | ||
|
||
https://api.docs.ewarehousing-solutions.com/ | ||
|
||
|
||
## Installation | ||
|
||
``` | ||
|
@@ -19,13 +17,20 @@ go get -u github.com/ewarehousing-solutions/ewhs-api-go | |
|
||
- Go 19+ | ||
|
||
|
||
## Usage | ||
|
||
```go | ||
... | ||
config := ewhs.NewConfig("username", "password", "wms_code", "customer_code") | ||
client, err := ewhs.NewClient(nil, config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
``` | ||
|
||
## Support | ||
|
||
[www.ewarehousing-solutions.nl](https://ewarehousing-solutions.nl/) — [email protected] | ||
|
||
## Credits | ||
|
||
# Support | ||
[www.ewarehousing-solutions.nl](https://ewarehousing-solutions.nl/) — [email protected] | ||
This package is heavily based on [https://github.com/VictorAvelar/mollie-api-go](VictorAvelar/mollie-api-go). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ewhs | ||
|
||
type AuthToken struct { | ||
Token string `json:"token,omitempty"` | ||
Iat int `json:"iat,omitempty"` | ||
Exp int `json:"exp,omitempty"` | ||
RefreshToken string `json:"refresh_token,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ewhs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/ewarehousing-solutions/ewhs-api-go/test/testdata" | ||
"github.com/stretchr/testify/suite" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
type authServiceSuite struct{ suite.Suite } | ||
|
||
func (as *authServiceSuite) TestAuthService_Authorize() { | ||
type args struct { | ||
ctx context.Context | ||
} | ||
cases := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
err error | ||
pre func() | ||
handler http.HandlerFunc | ||
}{ | ||
{ | ||
"authorize works as expected.", | ||
args{ | ||
context.Background(), | ||
}, | ||
false, | ||
nil, | ||
noPre, | ||
func(w http.ResponseWriter, r *http.Request) { | ||
testHeader(as.T(), r, CustomerCodeHeader, "test_customer") | ||
testHeader(as.T(), r, WmsCodeHeader, "test_wms") | ||
testMethod(as.T(), r, "POST") | ||
|
||
w.WriteHeader(http.StatusOK) | ||
_, _ = w.Write([]byte(testdata.CreateAuthTokenResponse)) | ||
}, | ||
}, | ||
{ | ||
"wrong login credentials gives an error.", | ||
args{ | ||
context.Background(), | ||
}, | ||
true, | ||
fmt.Errorf("401 - 401 Unauthorized"), | ||
noPre, | ||
unauthorizedHandler, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
setup() | ||
defer teardown() | ||
|
||
as.T().Run(c.name, func(t *testing.T) { | ||
c.pre() | ||
tMux.HandleFunc("/wms/auth/login/", c.handler) | ||
|
||
_, err := tClient.authorize(c.args.ctx) | ||
if c.wantErr { | ||
as.NotNil(err) | ||
as.EqualError(err, c.err.Error()) | ||
} else { | ||
as.Nil(err) | ||
as.NotNil(tClient.authToken) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthService(t *testing.T) { | ||
suite.Run(t, new(authServiceSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
package ewhs | ||
|
||
type Config struct { | ||
Username string | ||
Password string | ||
WmsCode string | ||
CustomerCode string | ||
} | ||
|
||
func NewConfig() *Config { | ||
return &Config{} | ||
func NewConfig(username string, password string, wmsCode string, customerCode string) *Config { | ||
return &Config{ | ||
Username: username, | ||
Password: password, | ||
WmsCode: wmsCode, | ||
CustomerCode: customerCode, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ewhs | ||
|
||
import "fmt" | ||
|
||
// BaseError contains the general error structure | ||
// returned by mollie. | ||
type BaseError struct { | ||
Status int `json:"status,omitempty"` | ||
Title string `json:"title,omitempty"` | ||
Detail string `json:"detail,omitempty"` | ||
} | ||
|
||
// Error interface compliance. | ||
func (be *BaseError) Error() string { | ||
//str := fmt.Sprintf("%d - %s: %s", be.Status, be.Title, be.Detail) | ||
str := fmt.Sprintf("%d - %s", be.Status, be.Title) | ||
|
||
return str | ||
} |
Oops, something went wrong.