Skip to content

Commit be57cb9

Browse files
authored
feat: use the loops-go sdk, rm internal/api (#67)
1 parent f02088c commit be57cb9

49 files changed

Lines changed: 132 additions & 4244 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/api_key.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/loops-so/cli/internal/api"
6+
"github.com/loops-so/loops-go"
77
"github.com/loops-so/cli/internal/config"
88
"github.com/spf13/cobra"
99
)
1010

11-
func runAPIKey(cfg *config.Config) (*api.APIKeyResponse, error) {
11+
func runAPIKey(cfg *config.Config) (*loops.APIKeyResponse, error) {
1212
return newAPIClient(cfg).GetAPIKey()
1313
}
1414

cmd/api_key_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"reflect"
66
"testing"
77

8-
"github.com/loops-so/cli/internal/api"
8+
"github.com/loops-so/loops-go"
99
)
1010

1111
func TestRunAPIKey(t *testing.T) {
@@ -15,7 +15,7 @@ func TestRunAPIKey(t *testing.T) {
1515
if err != nil {
1616
t.Fatalf("unexpected error: %v", err)
1717
}
18-
want := &api.APIKeyResponse{TeamName: "Acme Corp"}
18+
want := &loops.APIKeyResponse{TeamName: "Acme Corp"}
1919
if !reflect.DeepEqual(result, want) {
2020
t.Errorf("got %+v, want %+v", result, want)
2121
}

cmd/auth_login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"strings"
88

9-
"github.com/loops-so/cli/internal/api"
9+
"github.com/loops-so/loops-go"
1010
"github.com/loops-so/cli/internal/config"
1111
"github.com/spf13/cobra"
1212
"golang.org/x/term"
@@ -54,7 +54,7 @@ var loginCmd = &cobra.Command{
5454
},
5555
}
5656

57-
func runAuthLogin(apiKey, name string, skipVerify bool) (*api.APIKeyResponse, error) {
57+
func runAuthLogin(apiKey, name string, skipVerify bool) (*loops.APIKeyResponse, error) {
5858
if name == "" {
5959
return nil, errors.New("a key name is required")
6060
}

cmd/auth_login_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"reflect"
66
"testing"
77

8-
"github.com/loops-so/cli/internal/api"
8+
"github.com/loops-so/loops-go"
99
)
1010

1111
func TestRunAuthLogin(t *testing.T) {
@@ -15,7 +15,7 @@ func TestRunAuthLogin(t *testing.T) {
1515
if err != nil {
1616
t.Fatalf("unexpected error: %v", err)
1717
}
18-
want := &api.APIKeyResponse{TeamName: "Acme"}
18+
want := &loops.APIKeyResponse{TeamName: "Acme"}
1919
if !reflect.DeepEqual(result, want) {
2020
t.Errorf("got %+v, want %+v", result, want)
2121
}

cmd/auth_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/loops-so/cli/internal/api"
7+
"github.com/loops-so/loops-go"
88
"github.com/loops-so/cli/internal/config"
99
"github.com/spf13/cobra"
1010
)
@@ -43,7 +43,7 @@ var statusCmd = &cobra.Command{
4343
},
4444
}
4545

46-
func runAuthStatus() (*config.Config, *api.APIKeyResponse, *config.PersistentConfig, error) {
46+
func runAuthStatus() (*config.Config, *loops.APIKeyResponse, *config.PersistentConfig, error) {
4747
cfg, err := loadConfig()
4848
if err != nil {
4949
return nil, nil, nil, err

cmd/campaigns.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/loops-so/cli/internal/api"
6+
"github.com/loops-so/loops-go"
77
"github.com/loops-so/cli/internal/config"
88
"github.com/spf13/cobra"
99
)
1010

11-
func runCampaignsGet(cfg *config.Config, id string) (*api.Campaign, error) {
11+
func runCampaignsGet(cfg *config.Config, id string) (*loops.Campaign, error) {
1212
return newAPIClient(cfg).GetCampaign(id)
1313
}
1414

15-
func runCampaignsList(cfg *config.Config, params api.PaginationParams) ([]api.CampaignListItem, error) {
15+
func runCampaignsList(cfg *config.Config, params loops.PaginationParams) ([]loops.CampaignListItem, error) {
1616
client := newAPIClient(cfg)
1717
if params.Cursor != "" {
1818
campaigns, _, err := client.ListCampaigns(params)
1919
return campaigns, err
2020
}
21-
return api.Paginate(func(cursor string) ([]api.CampaignListItem, *api.Pagination, error) {
22-
return client.ListCampaigns(api.PaginationParams{
21+
return loops.Paginate(func(cursor string) ([]loops.CampaignListItem, *loops.Pagination, error) {
22+
return client.ListCampaigns(loops.PaginationParams{
2323
PerPage: params.PerPage,
2424
Cursor: cursor,
2525
})
@@ -52,7 +52,7 @@ var campaignsListCmd = &cobra.Command{
5252

5353
if isJSONOutput() {
5454
if campaigns == nil {
55-
campaigns = []api.CampaignListItem{}
55+
campaigns = []loops.CampaignListItem{}
5656
}
5757
return printJSON(cmd.OutOrStdout(), campaigns)
5858
}
@@ -91,7 +91,7 @@ var campaignsListCmd = &cobra.Command{
9191
},
9292
}
9393

94-
func runCampaignsCreate(cfg *config.Config, req api.CreateCampaignRequest) (*api.CampaignCreateResponse, error) {
94+
func runCampaignsCreate(cfg *config.Config, req loops.CreateCampaignRequest) (*loops.CampaignCreateResponse, error) {
9595
return newAPIClient(cfg).CreateCampaign(req)
9696
}
9797

@@ -106,7 +106,7 @@ var campaignsCreateCmd = &cobra.Command{
106106
return err
107107
}
108108

109-
resp, err := runCampaignsCreate(cfg, api.CreateCampaignRequest{Name: name})
109+
resp, err := runCampaignsCreate(cfg, loops.CreateCampaignRequest{Name: name})
110110
if err != nil {
111111
return err
112112
}
@@ -120,7 +120,7 @@ var campaignsCreateCmd = &cobra.Command{
120120
},
121121
}
122122

123-
func runCampaignsUpdate(cfg *config.Config, id string, req api.UpdateCampaignRequest) (*api.Campaign, error) {
123+
func runCampaignsUpdate(cfg *config.Config, id string, req loops.UpdateCampaignRequest) (*loops.Campaign, error) {
124124
return newAPIClient(cfg).UpdateCampaign(id, req)
125125
}
126126

@@ -136,7 +136,7 @@ var campaignsUpdateCmd = &cobra.Command{
136136
return err
137137
}
138138

139-
c, err := runCampaignsUpdate(cfg, args[0], api.UpdateCampaignRequest{Name: name})
139+
c, err := runCampaignsUpdate(cfg, args[0], loops.UpdateCampaignRequest{Name: name})
140140
if err != nil {
141141
return err
142142
}

cmd/campaigns_create_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55
"testing"
66

7-
"github.com/loops-so/cli/internal/api"
7+
"github.com/loops-so/loops-go"
88
)
99

1010
func TestRunCampaignsCreate(t *testing.T) {
@@ -21,7 +21,7 @@ func TestRunCampaignsCreate(t *testing.T) {
2121

2222
t.Run("returns response on success", func(t *testing.T) {
2323
serveJSON(t, http.StatusCreated, body)
24-
resp, err := runCampaignsCreate(cfg(t), api.CreateCampaignRequest{Name: "Spring"})
24+
resp, err := runCampaignsCreate(cfg(t), loops.CreateCampaignRequest{Name: "Spring"})
2525
if err != nil {
2626
t.Fatalf("unexpected error: %v", err)
2727
}
@@ -38,7 +38,7 @@ func TestRunCampaignsCreate(t *testing.T) {
3838

3939
t.Run("returns error on non-201 response", func(t *testing.T) {
4040
serveJSON(t, http.StatusBadRequest, `{"success":false,"message":"name is required"}`)
41-
_, err := runCampaignsCreate(cfg(t), api.CreateCampaignRequest{})
41+
_, err := runCampaignsCreate(cfg(t), loops.CreateCampaignRequest{})
4242
if err == nil {
4343
t.Fatal("expected error, got nil")
4444
}

cmd/campaigns_list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"net/http"
55
"testing"
66

7-
"github.com/loops-so/cli/internal/api"
7+
"github.com/loops-so/loops-go"
88
)
99

1010
func TestRunCampaignsList(t *testing.T) {
1111
t.Run("returns campaigns", func(t *testing.T) {
1212
serveJSON(t, http.StatusOK, `{"pagination":{"nextCursor":""},"data":[{"campaignId":"cmp_1","emailMessageId":"em_1","name":"Spring","subject":"Hi","status":"Draft","createdAt":"2026-04-01","updatedAt":"2026-04-02"}]}`)
13-
campaigns, err := runCampaignsList(cfg(t), api.PaginationParams{})
13+
campaigns, err := runCampaignsList(cfg(t), loops.PaginationParams{})
1414
if err != nil {
1515
t.Fatalf("unexpected error: %v", err)
1616
}
@@ -27,7 +27,7 @@ func TestRunCampaignsList(t *testing.T) {
2727

2828
t.Run("returns error on api failure", func(t *testing.T) {
2929
serveJSON(t, http.StatusUnauthorized, `{"error":"unauthorized"}`)
30-
_, err := runCampaignsList(cfg(t), api.PaginationParams{})
30+
_, err := runCampaignsList(cfg(t), loops.PaginationParams{})
3131
if err == nil {
3232
t.Fatal("expected error, got nil")
3333
}

cmd/campaigns_update_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55
"testing"
66

7-
"github.com/loops-so/cli/internal/api"
7+
"github.com/loops-so/loops-go"
88
)
99

1010
func TestRunCampaignsUpdate(t *testing.T) {
@@ -20,7 +20,7 @@ func TestRunCampaignsUpdate(t *testing.T) {
2020

2121
t.Run("returns campaign on success", func(t *testing.T) {
2222
serveJSON(t, http.StatusOK, body)
23-
c, err := runCampaignsUpdate(cfg(t), "cmp_abc123", api.UpdateCampaignRequest{Name: "Renamed"})
23+
c, err := runCampaignsUpdate(cfg(t), "cmp_abc123", loops.UpdateCampaignRequest{Name: "Renamed"})
2424
if err != nil {
2525
t.Fatalf("unexpected error: %v", err)
2626
}
@@ -37,7 +37,7 @@ func TestRunCampaignsUpdate(t *testing.T) {
3737

3838
t.Run("returns error when not in draft", func(t *testing.T) {
3939
serveJSON(t, http.StatusConflict, `{"success":false,"message":"Campaign is not in draft status"}`)
40-
_, err := runCampaignsUpdate(cfg(t), "cmp_abc123", api.UpdateCampaignRequest{Name: "Renamed"})
40+
_, err := runCampaignsUpdate(cfg(t), "cmp_abc123", loops.UpdateCampaignRequest{Name: "Renamed"})
4141
if err == nil {
4242
t.Fatal("expected error, got nil")
4343
}

cmd/contact_properties.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/loops-so/cli/internal/api"
6+
"github.com/loops-so/loops-go"
77
"github.com/loops-so/cli/internal/config"
88
"github.com/spf13/cobra"
99
)
1010

11-
func runContactPropertiesList(cfg *config.Config, customOnly bool) ([]api.ContactProperty, error) {
11+
func runContactPropertiesList(cfg *config.Config, customOnly bool) ([]loops.ContactProperty, error) {
1212
return newAPIClient(cfg).ListContactProperties(customOnly)
1313
}
1414

@@ -43,7 +43,7 @@ var contactPropertiesListCmd = &cobra.Command{
4343

4444
if isJSONOutput() {
4545
if props == nil {
46-
props = []api.ContactProperty{}
46+
props = []loops.ContactProperty{}
4747
}
4848
return printJSON(cmd.OutOrStdout(), props)
4949
}

0 commit comments

Comments
 (0)