-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
338e439
commit a6d23c4
Showing
9 changed files
with
198 additions
and
54 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
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
Empty file.
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,21 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/quarksgroup/sms-client/sms" | ||
"github.com/quarksgroup/sms-client/sms/driver/fdi" | ||
"github.com/quarksgroup/sms-client/sms/transport/oauth2" | ||
) | ||
|
||
func provideClient() *sms.Client { | ||
client := fdi.NewDefault() | ||
client.Client = &http.Client{ | ||
Transport: &oauth2.Transport{ | ||
Scheme: oauth2.SchemeBearer, | ||
Source: oauth2.ContextTokenSource(), | ||
Base: http.DefaultTransport, | ||
}, | ||
} | ||
return client | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module github.com/rugwirobaker/sam | ||
module github.com/rugwirobaker/helmes | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/go-chi/chi v4.1.2+incompatible | ||
github.com/google/uuid v1.1.2 | ||
github.com/joho/godotenv v1.3.0 | ||
github.com/quarksgroup/sms-client v0.0.0-20200916024156-cec3c804e5f8 | ||
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect | ||
) |
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,13 +1,41 @@ | ||
github.com/go-chi/chi v1.0.0 h1:s/kv1cTXfivYjdKJdyUzNGyAWZ/2t7duW1gKn5ivu+c= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= | ||
github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= | ||
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k= | ||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= | ||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= | ||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= | ||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= | ||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= | ||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= | ||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/quarksgroup/sms-client v0.0.0-20200911144732-8cbf6e85ed3a h1:Prr/Ac/a0Xnu6DMB/Wpnci1YKqKtpcGjPRQiweKUiKY= | ||
github.com/quarksgroup/sms-client v0.0.0-20200911144732-8cbf6e85ed3a/go.mod h1:XcPDoSKQvB0PT2pXePS3pqVd7uCHTBhZ/zBdnSFBYOw= | ||
github.com/quarksgroup/sms-client v0.0.0-20200916024156-cec3c804e5f8 h1:AehGo7q3SYg9btSTVFPAUx0ToP3vWu1k6qccpHs+vzk= | ||
github.com/quarksgroup/sms-client v0.0.0-20200916024156-cec3c804e5f8/go.mod h1:XcPDoSKQvB0PT2pXePS3pqVd7uCHTBhZ/zBdnSFBYOw= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= | ||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA= | ||
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0= | ||
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,86 @@ | ||
package helmes | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
"github.com/quarksgroup/sms-client/sms" | ||
) | ||
|
||
// SMS ... | ||
type SMS struct { | ||
Payload string `json:"payload"` | ||
Recipient string `json:"recipient"` | ||
} | ||
|
||
// Report message queueing status | ||
type Report struct { | ||
ID string `json:"id"` | ||
Cost int64 `json:"cost"` | ||
} | ||
|
||
// Service defines the capabilties of helmes | ||
type Service interface { | ||
// Send an sms message and return it's | ||
Send(context.Context, *SMS) (*Report, error) | ||
|
||
//Version returns helmes's current running version | ||
Version(context.Context) (string, error) | ||
} | ||
|
||
type service struct { | ||
sender string | ||
callback string | ||
client *sms.Client | ||
token *sms.Token | ||
} | ||
|
||
// New instance of service | ||
func New(cli *sms.Client, id, secret, sender, callback string) (Service, error) { | ||
token, _, err := cli.Auth.Login(context.Background(), id, secret) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &service{ | ||
sender: sender, | ||
callback: callback, | ||
client: cli, | ||
token: token, | ||
}, nil | ||
} | ||
|
||
func (s *service) Send(ctx context.Context, message *SMS) (*Report, error) { | ||
token, _, err := s.client.Auth.Refresh(ctx, s.token, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ctx = context.WithValue(ctx, sms.TokenKey{}, &sms.Token{ | ||
Token: token.Token, | ||
Refresh: token.Refresh, | ||
}) | ||
|
||
in := sms.Message{ | ||
ID: uuid.New().String(), | ||
Body: message.Payload, | ||
Recipients: []string{message.Recipient}, | ||
Sender: s.sender, | ||
Report: s.callback, | ||
} | ||
|
||
report, _, err := s.client.Message.Send(ctx, in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return convertReport(report), nil | ||
} | ||
|
||
func (s *service) Version(ctx context.Context) (string, error) { | ||
return "v0.1.0", nil | ||
} | ||
|
||
func convertReport(report *sms.Report) *Report { | ||
return &Report{ | ||
ID: report.ID, | ||
Cost: report.Cost, | ||
} | ||
} |