-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxcommunitytweet.go
More file actions
182 lines (164 loc) · 7.95 KB
/
Copy pathxcommunitytweet.go
File metadata and controls
182 lines (164 loc) · 7.95 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// SPDX-FileCopyrightText: 2026 Xquik contributors
//
// SPDX-License-Identifier: Apache-2.0
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package xtwitterscraper
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/Xquik-dev/x-twitter-scraper-go/internal/apiquery"
"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/shared"
)
// X Community info, members, and tweets
//
// XCommunityTweetService 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 [NewXCommunityTweetService] method instead.
type XCommunityTweetService struct {
options []option.RequestOption
}
// NewXCommunityTweetService 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 NewXCommunityTweetService(opts ...option.RequestOption) (r XCommunityTweetService) {
r = XCommunityTweetService{}
r.options = opts
return
}
// One resumable page. Requires a Community ID and query.
func (r *XCommunityTweetService) List(ctx context.Context, query XCommunityTweetListParams, opts ...option.RequestOption) (res *shared.PaginatedTweets, err error) {
opts = slices.Concat(r.options, opts)
path := "x/communities/tweets"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Returns public tweets posted within one community.
func (r *XCommunityTweetService) ListByCommunity(ctx context.Context, id string, query XCommunityTweetListByCommunityParams, opts ...option.RequestOption) (res *shared.PaginatedTweets, err error) {
opts = slices.Concat(r.options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("x/communities/%s/tweets", url.PathEscape(id))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
type XCommunityTweetListParams struct {
// Numeric ID of the community whose posts to search
CommunityID string `query:"communityId" api:"required" json:"-"`
// Search query
Q string `query:"q" api:"required" json:"-"`
// Pagination cursor for community search
Cursor param.Opt[string] `query:"cursor,omitzero" json:"-"`
// Filter by language. Alias `lang` is accepted.
Language param.Opt[string] `query:"language,omitzero" json:"-"`
// Minimum likes. Aliases: minFaves, min_likes, min_faves.
MinLikes param.Opt[int64] `query:"minLikes,omitzero" json:"-"`
// Minimum replies threshold.
MinReplies param.Opt[int64] `query:"minReplies,omitzero" json:"-"`
// Minimum retweets threshold.
MinRetweets param.Opt[int64] `query:"minRetweets,omitzero" json:"-"`
// Minimum view count threshold.
MinViews param.Opt[int64] `query:"minViews,omitzero" json:"-"`
// Maximum page items (1-100, default 20). Source, filters, or credits can reduce
// results. Follow next_cursor while the response reports more pages. Deprecated
// limit and count aliases remain accepted.
PageSize param.Opt[int64] `query:"pageSize,omitzero" json:"-"`
// Start date in YYYY-MM-DD format.
SinceDate param.Opt[time.Time] `query:"sinceDate,omitzero" format:"date" json:"-"`
// End date in YYYY-MM-DD format.
UntilDate param.Opt[time.Time] `query:"untilDate,omitzero" format:"date" json:"-"`
// Only return tweets from verified authors.
VerifiedOnly param.Opt[bool] `query:"verifiedOnly,omitzero" json:"-"`
// Filter media. Aliases: has_video, has_media.
//
// Any of "images", "videos", "gifs", "media", "links", "none".
MediaType XCommunityTweetListParamsMediaType `query:"mediaType,omitzero" json:"-"`
// Sort order (Latest or Top)
//
// Any of "Latest", "Top".
QueryType XCommunityTweetListParamsQueryType `query:"queryType,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [XCommunityTweetListParams]'s query parameters as
// `url.Values`.
func (r XCommunityTweetListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter media. Aliases: has_video, has_media.
type XCommunityTweetListParamsMediaType string
const (
XCommunityTweetListParamsMediaTypeImages XCommunityTweetListParamsMediaType = "images"
XCommunityTweetListParamsMediaTypeVideos XCommunityTweetListParamsMediaType = "videos"
XCommunityTweetListParamsMediaTypeGifs XCommunityTweetListParamsMediaType = "gifs"
XCommunityTweetListParamsMediaTypeMedia XCommunityTweetListParamsMediaType = "media"
XCommunityTweetListParamsMediaTypeLinks XCommunityTweetListParamsMediaType = "links"
XCommunityTweetListParamsMediaTypeNone XCommunityTweetListParamsMediaType = "none"
)
// Sort order (Latest or Top)
type XCommunityTweetListParamsQueryType string
const (
XCommunityTweetListParamsQueryTypeLatest XCommunityTweetListParamsQueryType = "Latest"
XCommunityTweetListParamsQueryTypeTop XCommunityTweetListParamsQueryType = "Top"
)
type XCommunityTweetListByCommunityParams struct {
// Pagination cursor for collection results.
Cursor param.Opt[string] `query:"cursor,omitzero" json:"-"`
// Filter by language. Alias `lang` is accepted.
Language param.Opt[string] `query:"language,omitzero" json:"-"`
// Minimum likes. Aliases: minFaves, min_likes, min_faves.
MinLikes param.Opt[int64] `query:"minLikes,omitzero" json:"-"`
// Minimum replies threshold.
MinReplies param.Opt[int64] `query:"minReplies,omitzero" json:"-"`
// Minimum retweets threshold.
MinRetweets param.Opt[int64] `query:"minRetweets,omitzero" json:"-"`
// Minimum view count threshold.
MinViews param.Opt[int64] `query:"minViews,omitzero" json:"-"`
// Maximum page items (1-100, default 20). Source, filters, or credits can reduce
// results. Follow next_cursor while the response reports more pages. Deprecated
// limit and count aliases remain accepted.
PageSize param.Opt[int64] `query:"pageSize,omitzero" json:"-"`
// Start date in YYYY-MM-DD format.
SinceDate param.Opt[time.Time] `query:"sinceDate,omitzero" format:"date" json:"-"`
// End date in YYYY-MM-DD format.
UntilDate param.Opt[time.Time] `query:"untilDate,omitzero" format:"date" json:"-"`
// Only return tweets from verified authors.
VerifiedOnly param.Opt[bool] `query:"verifiedOnly,omitzero" json:"-"`
// Filter media. Aliases: has_video, has_media.
//
// Any of "images", "videos", "gifs", "media", "links", "none".
MediaType XCommunityTweetListByCommunityParamsMediaType `query:"mediaType,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [XCommunityTweetListByCommunityParams]'s query parameters as
// `url.Values`.
func (r XCommunityTweetListByCommunityParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter media. Aliases: has_video, has_media.
type XCommunityTweetListByCommunityParamsMediaType string
const (
XCommunityTweetListByCommunityParamsMediaTypeImages XCommunityTweetListByCommunityParamsMediaType = "images"
XCommunityTweetListByCommunityParamsMediaTypeVideos XCommunityTweetListByCommunityParamsMediaType = "videos"
XCommunityTweetListByCommunityParamsMediaTypeGifs XCommunityTweetListByCommunityParamsMediaType = "gifs"
XCommunityTweetListByCommunityParamsMediaTypeMedia XCommunityTweetListByCommunityParamsMediaType = "media"
XCommunityTweetListByCommunityParamsMediaTypeLinks XCommunityTweetListByCommunityParamsMediaType = "links"
XCommunityTweetListByCommunityParamsMediaTypeNone XCommunityTweetListByCommunityParamsMediaType = "none"
)