Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add installation argument to push command #83

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ to show the Bitcoin tracker on your Tidbyt:

```
pixlet render examples/bitcoin.star
pixlet push --api-token <YOUR API TOKEN> <YOUR DEVICE ID> examples/bitcoin.webp
pixlet push --api-token <YOUR API TOKEN> <YOUR DEVICE ID> examples/bitcoin.webp [Installation ID]
```

To get the ID and API key for a device, open the settings for the device in the Tidbyt app on your phone, and tap **Get API key**.
Expand Down
17 changes: 12 additions & 5 deletions push.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var (
)

type TidbytPushJSON struct {
DeviceID string `json:"deviceID"`
Image string `json:"image"`
DeviceID string `json:"deviceID"`
Image string `json:"image"`
InstallationID string `json:"installationID"`
}

func init() {
Expand All @@ -32,7 +33,7 @@ func init() {
}

var pushCmd = &cobra.Command{
Use: "push [device ID] [webp image]",
Use: "push [device ID] [webp image] [installationID]",
Short: "Pushes a webp image to a Tidbyt device",
Args: cobra.MinimumNArgs(2),
Run: push,
Expand All @@ -41,6 +42,11 @@ var pushCmd = &cobra.Command{
func push(cmd *cobra.Command, args []string) {
deviceID := args[0]
image := args[1]
installationID := ""

if len(args) == 3 {
installationID = args[2]
}

if apiToken == "" {
apiToken = os.Getenv(APITokenEnv)
Expand All @@ -59,8 +65,9 @@ func push(cmd *cobra.Command, args []string) {

payload, err := json.Marshal(
TidbytPushJSON{
DeviceID: deviceID,
Image: base64.StdEncoding.EncodeToString(imageData),
DeviceID: deviceID,
Image: base64.StdEncoding.EncodeToString(imageData),
InstallationID: installationID,
},
)
if err != nil {
Expand Down