Skip to content
Merged
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
29 changes: 19 additions & 10 deletions internal/commands/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func NewAPICmd() *cobra.Command {
Use: "api <verb> <path>",
Short: "Raw API access",
Long: "Make raw API requests to any Basecamp endpoint. Useful for operations not covered by dedicated commands.",
Example: ` basecamp api get /projects.json
basecamp api post /buckets/123/todolists/456/todos.json -d '{"content":"Buy milk"}'`,
}

cmd.AddCommand(
Expand All @@ -35,7 +37,10 @@ func newAPIGetCmd() *cobra.Command {
Use: "get <path>",
Short: "GET request to API",
Long: "Make a raw GET request to any Basecamp API endpoint.",
Args: cobra.ExactArgs(1),
Example: ` basecamp api get /projects.json
basecamp api get /buckets/123/todos/456.json
basecamp api get https://3.basecampapi.com/999/projects.json`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
app := appctx.FromContext(cmd.Context())
if err := ensureAccount(cmd, app); err != nil {
Expand Down Expand Up @@ -66,7 +71,9 @@ func newAPIPostCmd() *cobra.Command {
Use: "post <path>",
Short: "POST request to API",
Long: "Make a raw POST request to any Basecamp API endpoint.",
Args: cobra.ExactArgs(1),
Example: ` basecamp api post /buckets/123/todolists/456/todos.json -d '{"content":"Buy milk"}'
basecamp api post /buckets/123/message_boards/789/messages.json -d '{"subject":"Hello","content":"<p>World</p>"}'`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Show help when invoked with no data
if data == "" {
Expand Down Expand Up @@ -111,10 +118,11 @@ func newAPIPutCmd() *cobra.Command {
var data string

cmd := &cobra.Command{
Use: "put <path>",
Short: "PUT request to API",
Long: "Make a raw PUT request to any Basecamp API endpoint.",
Args: cobra.ExactArgs(1),
Use: "put <path>",
Short: "PUT request to API",
Long: "Make a raw PUT request to any Basecamp API endpoint.",
Example: ` basecamp api put /buckets/123/todos/456.json -d '{"content":"Updated todo"}'`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Show help when invoked with no data
if data == "" {
Expand Down Expand Up @@ -157,10 +165,11 @@ func newAPIPutCmd() *cobra.Command {

func newAPIDeleteCmd() *cobra.Command {
return &cobra.Command{
Use: "delete <path>",
Short: "DELETE request to API",
Long: "Make a raw DELETE request to any Basecamp API endpoint.",
Args: cobra.ExactArgs(1),
Use: "delete <path>",
Short: "DELETE request to API",
Long: "Make a raw DELETE request to any Basecamp API endpoint.",
Example: ` basecamp api delete /buckets/123/todos/456.json`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
app := appctx.FromContext(cmd.Context())
if err := ensureAccount(cmd, app); err != nil {
Expand Down
Loading