-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaccountcontact.go
More file actions
146 lines (130 loc) · 5.52 KB
/
accountcontact.go
File metadata and controls
146 lines (130 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package beeperdesktopapi
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/beeper/desktop-api-go/internal/apijson"
"github.com/beeper/desktop-api-go/internal/apiquery"
"github.com/beeper/desktop-api-go/internal/requestconfig"
"github.com/beeper/desktop-api-go/option"
"github.com/beeper/desktop-api-go/packages/pagination"
"github.com/beeper/desktop-api-go/packages/param"
"github.com/beeper/desktop-api-go/packages/respjson"
"github.com/beeper/desktop-api-go/shared"
)
// Manage contacts on a specific account
//
// AccountContactService contains methods and other services that help with
// interacting with the beeperdesktop API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewAccountContactService] method instead.
type AccountContactService struct {
Options []option.RequestOption
}
// NewAccountContactService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewAccountContactService(opts ...option.RequestOption) (r AccountContactService) {
r = AccountContactService{}
r.Options = opts
return
}
// List merged contacts for a specific account with cursor-based pagination.
func (r *AccountContactService) List(ctx context.Context, accountID string, query AccountContactListParams, opts ...option.RequestOption) (res *pagination.CursorSearch[shared.User], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if accountID == "" {
err = errors.New("missing required accountID parameter")
return
}
path := fmt.Sprintf("v1/accounts/%s/contacts/list", accountID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List merged contacts for a specific account with cursor-based pagination.
func (r *AccountContactService) ListAutoPaging(ctx context.Context, accountID string, query AccountContactListParams, opts ...option.RequestOption) *pagination.CursorSearchAutoPager[shared.User] {
return pagination.NewCursorSearchAutoPager(r.List(ctx, accountID, query, opts...))
}
// Search contacts on a specific account using merged account contacts, network
// search, and exact identifier lookup.
func (r *AccountContactService) Search(ctx context.Context, accountID string, query AccountContactSearchParams, opts ...option.RequestOption) (res *AccountContactSearchResponse, err error) {
opts = slices.Concat(r.Options, opts)
if accountID == "" {
err = errors.New("missing required accountID parameter")
return
}
path := fmt.Sprintf("v1/accounts/%s/contacts", accountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
type AccountContactSearchResponse struct {
Items []shared.User `json:"items" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Items respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AccountContactSearchResponse) RawJSON() string { return r.JSON.raw }
func (r *AccountContactSearchResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AccountContactListParams struct {
// Opaque pagination cursor; do not inspect. Use together with 'direction'.
Cursor param.Opt[string] `query:"cursor,omitzero" json:"-"`
// Maximum contacts to return per page.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Optional search query for blended contact lookup.
Query param.Opt[string] `query:"query,omitzero" json:"-"`
// Pagination direction used with 'cursor': 'before' fetches older results, 'after'
// fetches newer results. Defaults to 'before' when only 'cursor' is provided.
//
// Any of "after", "before".
Direction AccountContactListParamsDirection `query:"direction,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [AccountContactListParams]'s query parameters as
// `url.Values`.
func (r AccountContactListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Pagination direction used with 'cursor': 'before' fetches older results, 'after'
// fetches newer results. Defaults to 'before' when only 'cursor' is provided.
type AccountContactListParamsDirection string
const (
AccountContactListParamsDirectionAfter AccountContactListParamsDirection = "after"
AccountContactListParamsDirectionBefore AccountContactListParamsDirection = "before"
)
type AccountContactSearchParams struct {
// Text to search users by. Network-specific behavior.
Query string `query:"query" api:"required" json:"-"`
paramObj
}
// URLQuery serializes [AccountContactSearchParams]'s query parameters as
// `url.Values`.
func (r AccountContactSearchParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}