-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webhooks] prepare command for webhooks management
- Loading branch information
Showing
4 changed files
with
101 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
} |