Compare commits
No commits in common. "a7fab72a1e26dbf33aec6e51d42cf817773c8e7f" and "8e7ff7f39a0b475236b9d747a53896155cf25102" have entirely different histories.
a7fab72a1e
...
8e7ff7f39a
32
client.go
32
client.go
@ -13,12 +13,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const defaultUserAgent = "go-lifx"
|
||||
const UserAgent = "lume"
|
||||
|
||||
type (
|
||||
Client struct {
|
||||
accessToken string
|
||||
userAgent string
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
@ -71,37 +70,12 @@ var errorMap = map[int]error{
|
||||
523: errors.New("Something went wrong on LIFX's end"),
|
||||
}
|
||||
|
||||
func NewClient(accessToken string, options ...func(*Client)) *Client {
|
||||
var c *Client
|
||||
tr := &http.Transport{
|
||||
//TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
|
||||
}
|
||||
|
||||
c = &Client{
|
||||
accessToken: accessToken,
|
||||
Client: &http.Client{Transport: tr},
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
option(c)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func WithUserAgent(userAgent string) func(*Client) {
|
||||
return func(c *Client) {
|
||||
c.userAgent = userAgent
|
||||
}
|
||||
}
|
||||
|
||||
func NewClientWithUserAgent(accessToken string, userAgent string) *Client {
|
||||
func NewClient(accessToken string) *Client {
|
||||
tr := &http.Transport{
|
||||
//TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
|
||||
}
|
||||
return &Client{
|
||||
accessToken: accessToken,
|
||||
userAgent: userAgent,
|
||||
Client: &http.Client{Transport: tr},
|
||||
}
|
||||
}
|
||||
@ -161,7 +135,7 @@ func (c *Client) NewRequest(method, url string, body io.Reader) (req *http.Reque
|
||||
}
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.accessToken))
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
req.Header.Add("User-Agent", c.userAgent)
|
||||
req.Header.Add("User-Agent", UserAgent)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,6 @@ import (
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
const userAgent = "lume"
|
||||
|
||||
func init() {
|
||||
RegisterCommand("help", Command{
|
||||
Func: HelpCmd,
|
||||
@ -223,10 +221,7 @@ func Main(args []string) (int, error) {
|
||||
|
||||
command := args[1]
|
||||
|
||||
c := lifx.NewClient(
|
||||
config.AccessToken,
|
||||
lifx.WithUserAgent(userAgent),
|
||||
)
|
||||
c := lifx.NewClient(config.AccessToken)
|
||||
|
||||
cmdArgs := CmdArgs{
|
||||
Client: c,
|
||||
|
Loading…
Reference in New Issue
Block a user