Skip to content

Commit

Permalink
[webhooks] prepare command for webhooks management
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Oct 28, 2024
1 parent a97051e commit 984ac22
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 37 deletions.
25 changes: 25 additions & 0 deletions internal/commands/webhooks/delete.go
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
package webhooks

import (
"github.com/android-sms-gateway/cli/internal/core/codes"
"github.com/urfave/cli/v2"
)

var delete = &cli.Command{
Category: "Webhooks",
Name: "delete",
Aliases: []string{"d"},
Usage: "Delete webhook",
Args: true,
ArgsUsage: "ID",
Action: func(c *cli.Context) error {
id := c.Args().Get(0)
if id == "" {
return cli.Exit("ID is empty", codes.ParamsError)
}

// client := metadata.GetClient(c.App.Metadata)
// renderer := metadata.GetRenderer(c.App.Metadata)

return cli.Exit("Not implemented", codes.ParamsError)
},
}
18 changes: 18 additions & 0 deletions internal/commands/webhooks/list.go
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
package webhooks

import (
"github.com/android-sms-gateway/cli/internal/core/codes"
"github.com/urfave/cli/v2"
)

var list = &cli.Command{
Category: "Webhooks",
Name: "list",
Aliases: []string{"l", "ls"},
Usage: "List webhooks",
Action: func(c *cli.Context) error {
// client := metadata.GetClient(c.App.Metadata)
// renderer := metadata.GetRenderer(c.App.Metadata)

return cli.Exit("Not implemented", codes.ParamsError)
},
}
51 changes: 51 additions & 0 deletions internal/commands/webhooks/register.go
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
package webhooks

import (
"github.com/android-sms-gateway/cli/internal/core/codes"
"github.com/android-sms-gateway/client-go/smsgateway"
"github.com/urfave/cli/v2"
)

var register = &cli.Command{
Category: "Webhooks",
Name: "register",
Aliases: []string{"r"},
ArgsUsage: "URL",
Usage: "Register webhook",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "ID",
Required: false,
},
&cli.StringFlag{
Name: "event",
Aliases: []string{"e"},
Usage: "Event",
Required: true,
Action: func(c *cli.Context, event string) error {
if !smsgateway.IsValidWebhookEvent(event) {
return cli.Exit("Invalid event", codes.ParamsError)
}

return nil
},
},
},
Action: func(c *cli.Context) error {
url := c.Args().Get(0)
if url == "" {
return cli.Exit("URL is empty", codes.ParamsError)
}

// client := metadata.GetClient(c.App.Metadata)
// renderer := metadata.GetRenderer(c.App.Metadata)

// req := smsgateway.Webhook{
// ID: c.String("id"),
// URL: url,
// Event: c.String("event"),
// }

return cli.Exit("Not implemented", codes.ParamsError)
},
}
44 changes: 7 additions & 37 deletions internal/commands/webhooks/webhooks.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,19 @@
package webhooks

import (
"log"

"github.com/urfave/cli/v2"
)

var Commands = []*cli.Command{
{
Name: "webhook",
Description: "Manage webhooks",
Aliases: []string{"wh"},
Category: "Webhooks",
Name: "webhooks",
Aliases: []string{"w", "wh"},
Usage: "Manage webhooks",
Subcommands: []*cli.Command{
{
Name: "register",
Aliases: []string{"r"},
Args: true,
ArgsUsage: "URL",
Usage: "Register webhook",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "ID",
Required: false,
},
&cli.StringFlag{
Name: "event",
Aliases: []string{"e"},
Usage: "Event",
Required: true,
},
},
Action: func(c *cli.Context) error {

u := c.Args().Get(0)
if u == "" {
return cli.Exit("URL is empty", 1)
}

id := c.String("id")
log.Printf("Registering webhook: %s with ID: %s", u, id)

return nil
},
},
register,
delete,
list,
},
},
}

0 comments on commit 984ac22

Please sign in to comment.