Skip to content

Commit

Permalink
Add ListHandOffTargets
Browse files Browse the repository at this point in the history
  • Loading branch information
nlathia committed Dec 12, 2024
1 parent a70d2f5 commit 0382dd5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions handoff_target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package client

type HandOffTarget struct {
// ID is your identifier of choice for this hand-off target. Can be anything consisting
// of letters, numbers, or any of the following characters: `_` `-` `+` `=`.
ID string `json:"id"`

// Name is the hand-off target’s name.
Name string `json:"name"`
}
4 changes: 3 additions & 1 deletion hand_off_target_upsert.go → handoff_target_upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ type UpsertHandOffTargetParams struct {
Name string `json:"name"`
}

// UpsertHandOffTarget inserts or updates a hand-off target
// UpsertHandOffTarget inserts or updates a hand-off target.
//
// Note: requires a `Management` API key.
func (c *Client) UpsertHandOffTarget(ctx context.Context, p *UpsertHandOffTargetParams) error {
rsp, err := c.makeRequest(ctx, http.MethodPost, "hand-off-targets", p)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions handoff_targets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package client

import (
"context"
"encoding/json"
"net/http"
)

type HandOffTargets struct {
Targets []*HandOffTarget `json:"targets"`
}

// ListHandOffTargets returns all of your hand off targets.
//
// Note: requires a `Management` API key.
func (c *Client) ListHandOffTargets(ctx context.Context) (*HandOffTargets, error) {
rsp, err := c.makeRequest(ctx, http.MethodGet, "hand-off-targets", nil)
if err != nil {
return nil, err
}
defer rsp.Body.Close()

if err := responseError(rsp); err != nil {
return nil, err
}

var targets HandOffTargets
if err := json.NewDecoder(rsp.Body).Decode(&targets); err != nil {
return nil, err
}
return &targets, nil
}

0 comments on commit 0382dd5

Please sign in to comment.