-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxuserfollow.go
More file actions
123 lines (108 loc) · 4.09 KB
/
xuserfollow.go
File metadata and controls
123 lines (108 loc) · 4.09 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package xtwitterscraper
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/Xquik-dev/x-twitter-scraper-go/internal/apijson"
"github.com/Xquik-dev/x-twitter-scraper-go/internal/requestconfig"
"github.com/Xquik-dev/x-twitter-scraper-go/option"
"github.com/Xquik-dev/x-twitter-scraper-go/packages/param"
"github.com/Xquik-dev/x-twitter-scraper-go/packages/respjson"
)
// X write actions (tweets, likes, follows, DMs)
//
// XUserFollowService contains methods and other services that help with
// interacting with the x-twitter-scraper 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 [NewXUserFollowService] method instead.
type XUserFollowService struct {
options []option.RequestOption
}
// NewXUserFollowService 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 NewXUserFollowService(opts ...option.RequestOption) (r XUserFollowService) {
r = XUserFollowService{}
r.options = opts
return
}
// Follow user
func (r *XUserFollowService) New(ctx context.Context, id string, body XUserFollowNewParams, opts ...option.RequestOption) (res *XUserFollowNewResponse, err error) {
opts = slices.Concat(r.options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("x/users/%s/follow", url.PathEscape(id))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Unfollow user
func (r *XUserFollowService) DeleteAll(ctx context.Context, id string, body XUserFollowDeleteAllParams, opts ...option.RequestOption) (res *XUserFollowDeleteAllResponse, err error) {
opts = slices.Concat(r.options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("x/users/%s/follow", url.PathEscape(id))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...)
return res, err
}
type XUserFollowNewResponse struct {
Success bool `json:"success" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r XUserFollowNewResponse) RawJSON() string { return r.JSON.raw }
func (r *XUserFollowNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type XUserFollowDeleteAllResponse struct {
Success bool `json:"success" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r XUserFollowDeleteAllResponse) RawJSON() string { return r.JSON.raw }
func (r *XUserFollowDeleteAllResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type XUserFollowNewParams struct {
// X account identifier (@username or account ID)
Account string `json:"account" api:"required"`
paramObj
}
func (r XUserFollowNewParams) MarshalJSON() (data []byte, err error) {
type shadow XUserFollowNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *XUserFollowNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type XUserFollowDeleteAllParams struct {
// X account identifier (@username or account ID)
Account string `json:"account" api:"required"`
paramObj
}
func (r XUserFollowDeleteAllParams) MarshalJSON() (data []byte, err error) {
type shadow XUserFollowDeleteAllParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *XUserFollowDeleteAllParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}