Skip to content

Commit 697abc2

Browse files
feat: regenerate CLI from OpenAPI spec
1 parent c8b286c commit 697abc2

12 files changed

Lines changed: 1481 additions & 0 deletions

client/client.gen.go

Lines changed: 1196 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/reach/campaigns/campaigns.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package campaigns
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var GroupCmd = &cobra.Command{
8+
Use: "campaigns",
9+
Short: "Campaigns commands",
10+
}
11+
12+
func init() {
13+
GroupCmd.AddCommand(GetCmd)
14+
GroupCmd.AddCommand(ListCmd)
15+
GroupCmd.AddCommand(PerformanceCmd)
16+
}

cmd/reach/campaigns/get.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package campaigns
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var GetCmd = &cobra.Command{
13+
Use: "get <profile-uuid> <campaign-uuid>",
14+
Short: "Get campaign details",
15+
Long: "Get a single campaign with its sender, subject, template reference, targeting and delivery\nprogress.\n\nThis describes how the campaign was set up and how far it has got. For opens, clicks and\nunsubscribes use the campaign statistics endpoint.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().ReachGetCampaignDetailsV1WithResponse(context.TODO(), args[0], args[1])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}

cmd/reach/campaigns/list.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package campaigns
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/hostinger/api-cli/utils"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var ListCmd = &cobra.Command{
15+
Use: "list <profile-uuid>",
16+
Short: "List campaigns",
17+
Long: "Get a paginated list of the campaigns in a profile.\n\nEach campaign carries its headline engagement rates. Filter by status to find drafts,\nscheduled, sending or sent campaigns, keeping in mind that a fully sent campaign has the\nstatus `publish`. By default only regular campaigns are returned - pass `type` to get the\nemails sent by automations or the double opt-in confirmations instead.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
utils.EnumCheck(cmd, "status", []string{"draft", "scheduled", "sending", "publish", "failed"})
21+
utils.EnumCheck(cmd, "type", []string{"campaign", "automation", "double_opt_in"})
22+
utils.EnumCheck(cmd, "sort-direction", []string{"asc", "desc"})
23+
r, err := api.Request().ReachListCampaignsV1WithResponse(context.TODO(), args[0], listParams(cmd))
24+
if err != nil {
25+
log.Fatal(err)
26+
}
27+
28+
output.Format(cmd, r.Body, r.StatusCode())
29+
},
30+
}
31+
32+
func init() {
33+
ListCmd.Flags().StringP("status", "", "", "Filter campaigns by status.\n\nA fully sent campaign has the status `publish`. There is no `sent` status, and campaigns can\nbe neither paused nor archived. (one of: draft, scheduled, sending, publish, failed)")
34+
ListCmd.Flags().StringP("type", "", "campaign", "Filter campaigns by type.\n\nDefaults to `campaign`, which leaves out the emails sent by automations and the double\nopt-in confirmations. (one of: campaign, automation, double_opt_in)")
35+
ListCmd.Flags().StringP("sort-direction", "", "", "Order campaigns by creation date. Newest first unless set to `asc`. (one of: asc, desc)")
36+
ListCmd.Flags().IntP("page", "", 0, "Page number")
37+
ListCmd.Flags().IntP("per-page", "", 25, "Number of items per page")
38+
}
39+
40+
func listParams(cmd *cobra.Command) *client.ReachListCampaignsV1Params {
41+
params := &client.ReachListCampaignsV1Params{}
42+
if cmd.Flags().Changed("status") {
43+
v, _ := cmd.Flags().GetString("status")
44+
e := client.ReachListCampaignsV1ParamsStatus(v)
45+
params.Status = &e
46+
}
47+
if cmd.Flags().Changed("type") {
48+
v, _ := cmd.Flags().GetString("type")
49+
e := client.ReachListCampaignsV1ParamsType(v)
50+
params.Type = &e
51+
}
52+
if cmd.Flags().Changed("sort-direction") {
53+
v, _ := cmd.Flags().GetString("sort-direction")
54+
e := client.ReachListCampaignsV1ParamsSortDirection(v)
55+
params.SortDirection = &e
56+
}
57+
if cmd.Flags().Changed("page") {
58+
v, _ := cmd.Flags().GetInt("page")
59+
params.Page = &v
60+
}
61+
if cmd.Flags().Changed("per-page") {
62+
v, _ := cmd.Flags().GetInt("per-page")
63+
params.PerPage = &v
64+
}
65+
return params
66+
}

cmd/reach/campaigns/performance.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package campaigns
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var PerformanceCmd = &cobra.Command{
13+
Use: "performance <profile-uuid> <campaign-uuid>",
14+
Short: "Get campaign performance",
15+
Long: "Get the performance of a campaign: delivery, opens, clicks and unsubscribes, with the\nmatching rates.\n\nEvery count is unique contacts rather than raw events, so a contact who opens the same email\nfive times is counted once.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().ReachGetCampaignPerformanceV1WithResponse(context.TODO(), args[0], args[1])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}

cmd/reach/reach.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package reach
22

33
import (
44
"github.com/hostinger/api-cli/cmd/reach/automations"
5+
"github.com/hostinger/api-cli/cmd/reach/campaigns"
56
"github.com/hostinger/api-cli/cmd/reach/contact_fields"
67
"github.com/hostinger/api-cli/cmd/reach/contacts"
78
"github.com/hostinger/api-cli/cmd/reach/profiles"
@@ -18,6 +19,7 @@ var GroupCmd = &cobra.Command{
1819

1920
func init() {
2021
GroupCmd.AddCommand(automations.GroupCmd)
22+
GroupCmd.AddCommand(campaigns.GroupCmd)
2123
GroupCmd.AddCommand(contact_fields.GroupCmd)
2224
GroupCmd.AddCommand(contacts.GroupCmd)
2325
GroupCmd.AddCommand(profiles.GroupCmd)

docs/hostinger_reach.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Reach commands
1919

2020
* [hostinger](hostinger.md) - Hostinger API Command Line Interface
2121
* [hostinger reach automations](hostinger_reach_automations.md) - Automations commands
22+
* [hostinger reach campaigns](hostinger_reach_campaigns.md) - Campaigns commands
2223
* [hostinger reach contact-fields](hostinger_reach_contact-fields.md) - Contact Fields commands
2324
* [hostinger reach contacts](hostinger_reach_contacts.md) - Contacts commands
2425
* [hostinger reach profiles](hostinger_reach_profiles.md) - Profiles commands

docs/hostinger_reach_campaigns.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## hostinger reach campaigns
2+
3+
Campaigns commands
4+
5+
### Options
6+
7+
```
8+
-h, --help help for campaigns
9+
```
10+
11+
### Options inherited from parent commands
12+
13+
```
14+
--config string Config file (default is $HOME/.hostinger.yaml)
15+
--format string Output format type (json|table|tree), default: table
16+
```
17+
18+
### SEE ALSO
19+
20+
* [hostinger reach](hostinger_reach.md) - Reach commands
21+
* [hostinger reach campaigns get](hostinger_reach_campaigns_get.md) - Get campaign details
22+
* [hostinger reach campaigns list](hostinger_reach_campaigns_list.md) - List campaigns
23+
* [hostinger reach campaigns performance](hostinger_reach_campaigns_performance.md) - Get campaign performance
24+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## hostinger reach campaigns get
2+
3+
Get campaign details
4+
5+
### Synopsis
6+
7+
Get a single campaign with its sender, subject, template reference, targeting and delivery
8+
progress.
9+
10+
This describes how the campaign was set up and how far it has got. For opens, clicks and
11+
unsubscribes use the campaign statistics endpoint.
12+
13+
```
14+
hostinger reach campaigns get <profile-uuid> <campaign-uuid> [flags]
15+
```
16+
17+
### Options
18+
19+
```
20+
-h, --help help for get
21+
```
22+
23+
### Options inherited from parent commands
24+
25+
```
26+
--config string Config file (default is $HOME/.hostinger.yaml)
27+
--format string Output format type (json|table|tree), default: table
28+
```
29+
30+
### SEE ALSO
31+
32+
* [hostinger reach campaigns](hostinger_reach_campaigns.md) - Campaigns commands
33+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## hostinger reach campaigns list
2+
3+
List campaigns
4+
5+
### Synopsis
6+
7+
Get a paginated list of the campaigns in a profile.
8+
9+
Each campaign carries its headline engagement rates. Filter by status to find drafts,
10+
scheduled, sending or sent campaigns, keeping in mind that a fully sent campaign has the
11+
status `publish`. By default only regular campaigns are returned - pass `type` to get the
12+
emails sent by automations or the double opt-in confirmations instead.
13+
14+
```
15+
hostinger reach campaigns list <profile-uuid> [flags]
16+
```
17+
18+
### Options
19+
20+
```
21+
-h, --help help for list
22+
--page int Page number
23+
--per-page int Number of items per page (default 25)
24+
--sort-direction asc Order campaigns by creation date. Newest first unless set to asc. (one of: asc, desc)
25+
--status publish Filter campaigns by status.
26+
27+
A fully sent campaign has the status publish. There is no `sent` status, and campaigns can
28+
be neither paused nor archived. (one of: draft, scheduled, sending, publish, failed)
29+
--type campaign Filter campaigns by type.
30+
31+
Defaults to campaign, which leaves out the emails sent by automations and the double
32+
opt-in confirmations. (one of: campaign, automation, double_opt_in) (default "campaign")
33+
```
34+
35+
### Options inherited from parent commands
36+
37+
```
38+
--config string Config file (default is $HOME/.hostinger.yaml)
39+
--format string Output format type (json|table|tree), default: table
40+
```
41+
42+
### SEE ALSO
43+
44+
* [hostinger reach campaigns](hostinger_reach_campaigns.md) - Campaigns commands
45+

0 commit comments

Comments
 (0)