Skip to content

Commit

Permalink
Added support for User-Agent (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayalex authored May 10, 2018
1 parent d81b3b2 commit dcb9f43
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties

# VSCode
.vscode
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ branches:

install:
- go get -v -t ./...

script:
- go test ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ device, _ := sdk.NewDevice(deviceID, deviceToken)
You can also customize behind-the-scenes functionality, in this case - HTTP and MQTT clients, by optionally providing endpoints for them. By default these are securely connecting to Maker:

```go
device, _ := sdk.NewDevice("<DEVICE_ID>", "<DEVICE_TOKEN>",
device, _ := sdk.NewDevice("<DEVICE_ID>", "<DEVICE_TOKEN>",
sdk.WithHTTP("https://api.allthingstalk.io"),
sdk.WithMQTT("ssl://api.allthingstalk.io:8883"))
```
Expand Down
14 changes: 12 additions & 2 deletions http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ package sdk
import (
"errors"
"fmt"
"github.com/dghubble/sling"
"net/http"

"github.com/dghubble/sling"
)

// HTTP Errors
Expand All @@ -35,6 +36,12 @@ var (
ErrCountNotFetchState = errors.New("Count not obtain current Asset state")
)

// Constants
const (
// UA identifies the SDK
UA = "ATTalk-GoSDK/1.0.1"
)

type httpClient struct {
AssetService *assetService
}
Expand Down Expand Up @@ -64,7 +71,10 @@ func newAssetService(httpClient *http.Client, device *Device) *assetService {
DEBUG.Printf("[HTTP] Using API endpoint: %s", apiEndpoint)

return &assetService{
sling: sling.New().Client(httpClient).Base(apiEndpoint),
sling: sling.New().
Client(httpClient).
Base(apiEndpoint).
Set("User-Agent", UA),
}
}

Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (f optionFunc) apply(device *Device) {
f(device)
}

const httpEndpoint string = "http://api.allthingstalk.io"
const httpEndpoint string = "https://api.allthingstalk.io"
const mqttEndpoint string = "ssl://api.allthingstalk.io:8883"

// NewOptions creates default options.
Expand Down

0 comments on commit dcb9f43

Please sign in to comment.