x-twitter-scraper 0.10.4 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +69 -29
- data/lib/x_twitter_scraper/client.rb +0 -13
- data/lib/x_twitter_scraper/file_part.rb +0 -3
- data/lib/x_twitter_scraper/internal/transport/base_client.rb +3 -211
- data/lib/x_twitter_scraper/internal/transport/pooled_net_requester.rb +2 -56
- data/lib/x_twitter_scraper/internal/type/array_of.rb +1 -77
- data/lib/x_twitter_scraper/internal/type/base_model.rb +3 -133
- data/lib/x_twitter_scraper/internal/type/base_page.rb +0 -13
- data/lib/x_twitter_scraper/internal/type/boolean.rb +0 -38
- data/lib/x_twitter_scraper/internal/type/converter.rb +0 -136
- data/lib/x_twitter_scraper/internal/type/enum.rb +1 -80
- data/lib/x_twitter_scraper/internal/type/file_input.rb +0 -39
- data/lib/x_twitter_scraper/internal/type/hash_of.rb +1 -77
- data/lib/x_twitter_scraper/internal/type/request_parameters.rb +0 -13
- data/lib/x_twitter_scraper/internal/type/union.rb +0 -101
- data/lib/x_twitter_scraper/internal/type/unknown.rb +0 -40
- data/lib/x_twitter_scraper/internal/util.rb +2 -307
- data/lib/x_twitter_scraper/models/account_retrieve_response.rb +0 -3
- data/lib/x_twitter_scraper/models/compose_create_params.rb +0 -4
- data/lib/x_twitter_scraper/models/compose_create_response.rb +0 -4
- data/lib/x_twitter_scraper/models/credit_retrieve_balance_response.rb +0 -3
- data/lib/x_twitter_scraper/models/credit_topup_balance_response.rb +0 -3
- data/lib/x_twitter_scraper/models/draft_list_params.rb +0 -3
- data/lib/x_twitter_scraper/models/draw_export_params.rb +0 -3
- data/lib/x_twitter_scraper/models/draw_list_params.rb +0 -3
- data/lib/x_twitter_scraper/models/draw_run_response.rb +0 -3
- data/lib/x_twitter_scraper/models/embedded_tweet.rb +0 -3
- data/lib/x_twitter_scraper/models/event.rb +0 -3
- data/lib/x_twitter_scraper/models/event_list_params.rb +0 -3
- data/lib/x_twitter_scraper/models/extraction_estimate_cost_params.rb +0 -3
- data/lib/x_twitter_scraper/models/extraction_list_params.rb +0 -3
- data/lib/x_twitter_scraper/models/extraction_run_params.rb +0 -3
- data/lib/x_twitter_scraper/models/guest_wallet_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/guest_wallet_retrieve_status_response.rb +0 -3
- data/lib/x_twitter_scraper/models/guest_wallet_topup_response.rb +0 -3
- data/lib/x_twitter_scraper/models/radar_item.rb +0 -3
- data/lib/x_twitter_scraper/models/radar_retrieve_trending_topics_params.rb +0 -3
- data/lib/x_twitter_scraper/models/search_tweet.rb +0 -3
- data/lib/x_twitter_scraper/models/trend_list_params.rb +0 -3
- data/lib/x_twitter_scraper/models/webhook.rb +0 -3
- data/lib/x_twitter_scraper/models/x/communities/join_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/communities/join_delete_all_response.rb +0 -4
- data/lib/x_twitter_scraper/models/x/communities/tweet_list_by_community_params.rb +0 -4
- data/lib/x_twitter_scraper/models/x/communities/tweet_list_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/community_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/community_delete_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/community_retrieve_members_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/community_retrieve_moderators_params.rb +0 -4
- data/lib/x_twitter_scraper/models/x/community_retrieve_search_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/dm_retrieve_history_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/dm_retrieve_history_response.rb +0 -4
- data/lib/x_twitter_scraper/models/x/dm_send_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/list_retrieve_followers_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/list_retrieve_members_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/list_retrieve_tweets_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/media_upload_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/profile_update_avatar_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/profile_update_banner_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/profile_update_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_create_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_delete_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_detail.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_get_favoriters_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_get_quotes_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_get_replies_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_get_retweeters_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_get_thread_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_retrieve_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweet_search_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweets/like_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweets/like_delete_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweets/retweet_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/tweets/retweet_delete_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_remove_follower_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_batch_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_batch_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_followers_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_followers_you_know_params.rb +0 -4
- data/lib/x_twitter_scraper/models/x/user_retrieve_following_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_likes_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_media_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_mentions_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_replies_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_search_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_tweets_params.rb +0 -3
- data/lib/x_twitter_scraper/models/x/user_retrieve_verified_followers_params.rb +0 -4
- data/lib/x_twitter_scraper/models/x/users/follow_create_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/users/follow_delete_all_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/write_action_retrieve_response.rb +0 -3
- data/lib/x_twitter_scraper/models/x/x_account.rb +0 -3
- data/lib/x_twitter_scraper/models/x_get_article_response.rb +0 -4
- data/lib/x_twitter_scraper/request_options.rb +0 -2
- data/lib/x_twitter_scraper/resources/drafts.rb +0 -3
- data/lib/x_twitter_scraper/resources/draws.rb +0 -6
- data/lib/x_twitter_scraper/resources/events.rb +0 -3
- data/lib/x_twitter_scraper/resources/extractions.rb +0 -9
- data/lib/x_twitter_scraper/resources/guest_wallets.rb +0 -6
- data/lib/x_twitter_scraper/resources/monitors/keywords.rb +1 -1
- data/lib/x_twitter_scraper/resources/monitors.rb +1 -1
- data/lib/x_twitter_scraper/resources/radar.rb +0 -3
- data/lib/x_twitter_scraper/resources/support/tickets.rb +0 -6
- data/lib/x_twitter_scraper/resources/trends.rb +0 -3
- data/lib/x_twitter_scraper/resources/x/communities/join.rb +0 -6
- data/lib/x_twitter_scraper/resources/x/communities/tweets.rb +0 -7
- data/lib/x_twitter_scraper/resources/x/communities.rb +0 -16
- data/lib/x_twitter_scraper/resources/x/dm.rb +0 -6
- data/lib/x_twitter_scraper/resources/x/lists.rb +0 -9
- data/lib/x_twitter_scraper/resources/x/media.rb +0 -3
- data/lib/x_twitter_scraper/resources/x/profile.rb +0 -9
- data/lib/x_twitter_scraper/resources/x/tweets/like.rb +0 -6
- data/lib/x_twitter_scraper/resources/x/tweets/retweet.rb +0 -6
- data/lib/x_twitter_scraper/resources/x/tweets.rb +0 -24
- data/lib/x_twitter_scraper/resources/x/users/follow.rb +0 -6
- data/lib/x_twitter_scraper/resources/x/users.rb +0 -38
- data/lib/x_twitter_scraper/resources/x.rb +0 -3
- data/lib/x_twitter_scraper/version.rb +1 -1
- data/lib/x_twitter_scraper.rb +0 -5
- data/rbi/x_twitter_scraper/client.rbi +0 -4
- data/rbi/x_twitter_scraper/file_part.rbi +0 -1
- data/rbi/x_twitter_scraper/internal/transport/base_client.rbi +0 -19
- data/rbi/x_twitter_scraper/internal/transport/pooled_net_requester.rbi +0 -9
- data/rbi/x_twitter_scraper/internal/type/array_of.rbi +0 -10
- data/rbi/x_twitter_scraper/internal/type/base_model.rbi +0 -47
- data/rbi/x_twitter_scraper/internal/type/base_page.rbi +0 -4
- data/rbi/x_twitter_scraper/internal/type/boolean.rbi +0 -8
- data/rbi/x_twitter_scraper/internal/type/converter.rbi +0 -36
- data/rbi/x_twitter_scraper/internal/type/enum.rbi +0 -20
- data/rbi/x_twitter_scraper/internal/type/file_input.rbi +0 -10
- data/rbi/x_twitter_scraper/internal/type/hash_of.rbi +0 -10
- data/rbi/x_twitter_scraper/internal/type/request_parameters.rbi +0 -4
- data/rbi/x_twitter_scraper/internal/type/union.rbi +0 -18
- data/rbi/x_twitter_scraper/internal/type/unknown.rbi +0 -8
- data/rbi/x_twitter_scraper/internal/util.rbi +0 -75
- data/rbi/x_twitter_scraper/internal.rbi +0 -2
- data/rbi/x_twitter_scraper/request_options.rbi +0 -1
- data/rbi/x_twitter_scraper/resources/monitors/keywords.rbi +1 -1
- data/rbi/x_twitter_scraper/resources/monitors.rbi +1 -1
- data/sig/x_twitter_scraper/internal/transport/base_client.rbs +0 -1
- metadata +13 -5
|
@@ -7,23 +7,14 @@
|
|
|
7
7
|
module XTwitterScraper
|
|
8
8
|
module Internal
|
|
9
9
|
module Transport
|
|
10
|
-
# @api private
|
|
11
10
|
class PooledNetRequester
|
|
12
11
|
extend XTwitterScraper::Internal::Util::SorbetRuntimeSupport
|
|
13
12
|
|
|
14
|
-
# from the golang stdlib
|
|
15
|
-
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
|
|
16
13
|
KEEP_ALIVE_TIMEOUT = 30
|
|
17
14
|
|
|
18
15
|
DEFAULT_MAX_CONNECTIONS = [Etc.nprocessors, 99].max
|
|
19
16
|
|
|
20
17
|
class << self
|
|
21
|
-
# @api private
|
|
22
|
-
#
|
|
23
|
-
# @param cert_store [OpenSSL::X509::Store]
|
|
24
|
-
# @param url [URI::Generic]
|
|
25
|
-
#
|
|
26
|
-
# @return [Net::HTTP]
|
|
27
18
|
def connect(cert_store:, url:)
|
|
28
19
|
port =
|
|
29
20
|
case [url.port, url.scheme]
|
|
@@ -43,36 +34,18 @@ module XTwitterScraper
|
|
|
43
34
|
end
|
|
44
35
|
end
|
|
45
36
|
|
|
46
|
-
# @api private
|
|
47
|
-
#
|
|
48
|
-
# @param conn [Net::HTTP]
|
|
49
|
-
# @param deadline [Float]
|
|
50
37
|
def calibrate_socket_timeout(conn, deadline)
|
|
51
38
|
timeout = deadline - XTwitterScraper::Internal::Util.monotonic_secs
|
|
52
39
|
conn.open_timeout = conn.read_timeout = conn.write_timeout = conn.continue_timeout = timeout
|
|
53
40
|
end
|
|
54
41
|
|
|
55
|
-
# @api private
|
|
56
|
-
#
|
|
57
|
-
# @param request [Hash{Symbol=>Object}] .
|
|
58
|
-
#
|
|
59
|
-
# @option request [Symbol] :method
|
|
60
|
-
#
|
|
61
|
-
# @option request [URI::Generic] :url
|
|
62
|
-
#
|
|
63
|
-
# @option request [Hash{String=>String}] :headers
|
|
64
|
-
#
|
|
65
|
-
# @param blk [Proc]
|
|
66
|
-
#
|
|
67
|
-
# @yieldparam [String]
|
|
68
|
-
# @return [Array(Net::HTTPGenericRequest, Proc)]
|
|
69
42
|
def build_request(request, &blk)
|
|
70
43
|
method, url, headers, body = request.fetch_values(:method, :url, :headers, :body)
|
|
71
44
|
req = Net::HTTPGenericRequest.new(
|
|
72
45
|
method.to_s.upcase,
|
|
73
46
|
!body.nil?,
|
|
74
47
|
method != :head,
|
|
75
|
-
URI(url.to_s)
|
|
48
|
+
URI(url.to_s)
|
|
76
49
|
)
|
|
77
50
|
|
|
78
51
|
headers.each { req[_1] = _2 }
|
|
@@ -95,14 +68,6 @@ module XTwitterScraper
|
|
|
95
68
|
end
|
|
96
69
|
end
|
|
97
70
|
|
|
98
|
-
# @api private
|
|
99
|
-
#
|
|
100
|
-
# @param url [URI::Generic]
|
|
101
|
-
# @param deadline [Float]
|
|
102
|
-
# @param blk [Proc]
|
|
103
|
-
#
|
|
104
|
-
# @raise [Timeout::Error]
|
|
105
|
-
# @yieldparam [Net::HTTP]
|
|
106
71
|
private def with_pool(url, deadline:, &blk)
|
|
107
72
|
origin = XTwitterScraper::Internal::Util.uri_origin(url)
|
|
108
73
|
timeout = deadline - XTwitterScraper::Internal::Util.monotonic_secs
|
|
@@ -116,28 +81,13 @@ module XTwitterScraper
|
|
|
116
81
|
pool.with(timeout: timeout, &blk)
|
|
117
82
|
end
|
|
118
83
|
|
|
119
|
-
# @api private
|
|
120
|
-
#
|
|
121
|
-
# @param request [Hash{Symbol=>Object}] .
|
|
122
|
-
#
|
|
123
|
-
# @option request [Symbol] :method
|
|
124
|
-
#
|
|
125
|
-
# @option request [URI::Generic] :url
|
|
126
|
-
#
|
|
127
|
-
# @option request [Hash{String=>String}] :headers
|
|
128
|
-
#
|
|
129
|
-
# @option request [Object] :body
|
|
130
|
-
#
|
|
131
|
-
# @option request [Float] :deadline
|
|
132
|
-
#
|
|
133
|
-
# @return [Array(Integer, Net::HTTPResponse, Enumerable<String>)]
|
|
134
84
|
def execute(request)
|
|
135
85
|
url, deadline = request.fetch_values(:url, :deadline)
|
|
136
86
|
|
|
137
87
|
req = nil
|
|
138
88
|
finished = false
|
|
139
89
|
|
|
140
|
-
# rubocop:disable Metrics/BlockLength
|
|
90
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
141
91
|
enum = Enumerator.new do |y|
|
|
142
92
|
next if finished
|
|
143
93
|
|
|
@@ -185,7 +135,6 @@ module XTwitterScraper
|
|
|
185
135
|
rescue StandardError
|
|
186
136
|
raise XTwitterScraper::Errors::APIConnectionError.new(url: url, request: req)
|
|
187
137
|
end
|
|
188
|
-
# rubocop:enable Metrics/BlockLength
|
|
189
138
|
|
|
190
139
|
_, response = enum.next
|
|
191
140
|
body = XTwitterScraper::Internal::Util.fused_enum(enum, external: true) do
|
|
@@ -195,9 +144,6 @@ module XTwitterScraper
|
|
|
195
144
|
[Integer(response.code), response, body]
|
|
196
145
|
end
|
|
197
146
|
|
|
198
|
-
# @api private
|
|
199
|
-
#
|
|
200
|
-
# @param size [Integer]
|
|
201
147
|
def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
|
|
202
148
|
@mutex = Mutex.new
|
|
203
149
|
@size = size
|
|
@@ -7,34 +7,12 @@
|
|
|
7
7
|
module XTwitterScraper
|
|
8
8
|
module Internal
|
|
9
9
|
module Type
|
|
10
|
-
# @api private
|
|
11
|
-
#
|
|
12
|
-
# @abstract
|
|
13
|
-
#
|
|
14
|
-
# @generic Elem
|
|
15
|
-
#
|
|
16
|
-
# Array of items of a given type.
|
|
17
10
|
class ArrayOf
|
|
18
11
|
include XTwitterScraper::Internal::Type::Converter
|
|
19
12
|
include XTwitterScraper::Internal::Util::SorbetRuntimeSupport
|
|
20
13
|
|
|
21
14
|
private_class_method :new
|
|
22
15
|
|
|
23
|
-
# @overload [](type_info, spec = {})
|
|
24
|
-
#
|
|
25
|
-
# @param type_info [Hash{Symbol=>Object}, Proc, XTwitterScraper::Internal::Type::Converter, Class]
|
|
26
|
-
#
|
|
27
|
-
# @param spec [Hash{Symbol=>Object}] .
|
|
28
|
-
#
|
|
29
|
-
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
|
30
|
-
#
|
|
31
|
-
# @option spec [Proc] :enum
|
|
32
|
-
#
|
|
33
|
-
# @option spec [Proc] :union
|
|
34
|
-
#
|
|
35
|
-
# @option spec [Boolean] :"nil?"
|
|
36
|
-
#
|
|
37
|
-
# @return [self]
|
|
38
16
|
def self.[](...) = new(...)
|
|
39
17
|
|
|
40
18
|
# @api public
|
|
@@ -50,9 +28,8 @@ module XTwitterScraper
|
|
|
50
28
|
#
|
|
51
29
|
# @return [Boolean]
|
|
52
30
|
def ==(other)
|
|
53
|
-
# rubocop:disable Layout/LineLength
|
|
31
|
+
# rubocop:disable-next Layout/LineLength
|
|
54
32
|
other.is_a?(XTwitterScraper::Internal::Type::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
|
|
55
|
-
# rubocop:enable Layout/LineLength
|
|
56
33
|
end
|
|
57
34
|
|
|
58
35
|
# @api public
|
|
@@ -60,23 +37,6 @@ module XTwitterScraper
|
|
|
60
37
|
# @return [Integer]
|
|
61
38
|
def hash = [self.class, item_type].hash
|
|
62
39
|
|
|
63
|
-
# @api private
|
|
64
|
-
#
|
|
65
|
-
# @param value [Array<Object>, Object]
|
|
66
|
-
#
|
|
67
|
-
# @param state [Hash{Symbol=>Object}] .
|
|
68
|
-
#
|
|
69
|
-
# @option state [Boolean] :translate_names
|
|
70
|
-
#
|
|
71
|
-
# @option state [Boolean] :strictness
|
|
72
|
-
#
|
|
73
|
-
# @option state [Hash{Symbol=>Object}] :exactness
|
|
74
|
-
#
|
|
75
|
-
# @option state [Class<StandardError>] :error
|
|
76
|
-
#
|
|
77
|
-
# @option state [Integer] :branched
|
|
78
|
-
#
|
|
79
|
-
# @return [Array<Object>, Object]
|
|
80
40
|
def coerce(value, state:)
|
|
81
41
|
exactness = state.fetch(:exactness)
|
|
82
42
|
|
|
@@ -100,15 +60,6 @@ module XTwitterScraper
|
|
|
100
60
|
end
|
|
101
61
|
end
|
|
102
62
|
|
|
103
|
-
# @api private
|
|
104
|
-
#
|
|
105
|
-
# @param value [Array<Object>, Object]
|
|
106
|
-
#
|
|
107
|
-
# @param state [Hash{Symbol=>Object}] .
|
|
108
|
-
#
|
|
109
|
-
# @option state [Boolean] :can_retry
|
|
110
|
-
#
|
|
111
|
-
# @return [Array<Object>, Object]
|
|
112
63
|
def dump(value, state:)
|
|
113
64
|
target = item_type
|
|
114
65
|
if value.is_a?(Array)
|
|
@@ -120,47 +71,20 @@ module XTwitterScraper
|
|
|
120
71
|
end
|
|
121
72
|
end
|
|
122
73
|
|
|
123
|
-
# @api private
|
|
124
|
-
#
|
|
125
|
-
# @return [Object]
|
|
126
74
|
def to_sorbet_type
|
|
127
75
|
T::Array[XTwitterScraper::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(item_type)]
|
|
128
76
|
end
|
|
129
77
|
|
|
130
|
-
# @api private
|
|
131
|
-
#
|
|
132
|
-
# @return [generic<Elem>]
|
|
133
78
|
protected def item_type = @item_type_fn.call
|
|
134
79
|
|
|
135
|
-
# @api private
|
|
136
|
-
#
|
|
137
|
-
# @return [Boolean]
|
|
138
80
|
protected def nilable? = @nilable
|
|
139
81
|
|
|
140
|
-
# @api private
|
|
141
|
-
#
|
|
142
|
-
# @param type_info [Hash{Symbol=>Object}, Proc, XTwitterScraper::Internal::Type::Converter, Class]
|
|
143
|
-
#
|
|
144
|
-
# @param spec [Hash{Symbol=>Object}] .
|
|
145
|
-
#
|
|
146
|
-
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
|
147
|
-
#
|
|
148
|
-
# @option spec [Proc] :enum
|
|
149
|
-
#
|
|
150
|
-
# @option spec [Proc] :union
|
|
151
|
-
#
|
|
152
|
-
# @option spec [Boolean] :"nil?"
|
|
153
82
|
def initialize(type_info, spec = {})
|
|
154
83
|
@item_type_fn = XTwitterScraper::Internal::Type::Converter.type_info(type_info || spec)
|
|
155
84
|
@meta = XTwitterScraper::Internal::Type::Converter.meta_info(type_info, spec)
|
|
156
85
|
@nilable = spec.fetch(:nil?, false)
|
|
157
86
|
end
|
|
158
87
|
|
|
159
|
-
# @api private
|
|
160
|
-
#
|
|
161
|
-
# @param depth [Integer]
|
|
162
|
-
#
|
|
163
|
-
# @return [String]
|
|
164
88
|
def inspect(depth: 0)
|
|
165
89
|
items = XTwitterScraper::Internal::Type::Converter.inspect(item_type, depth: depth.succ)
|
|
166
90
|
|
|
@@ -7,54 +7,24 @@
|
|
|
7
7
|
module XTwitterScraper
|
|
8
8
|
module Internal
|
|
9
9
|
module Type
|
|
10
|
-
# @abstract
|
|
11
10
|
class BaseModel
|
|
12
11
|
extend XTwitterScraper::Internal::Type::Converter
|
|
13
12
|
extend XTwitterScraper::Internal::Util::SorbetRuntimeSupport
|
|
14
13
|
|
|
15
14
|
class << self
|
|
16
|
-
# @api private
|
|
17
|
-
#
|
|
18
|
-
# Assumes superclass fields are totally defined before fields are accessed /
|
|
19
|
-
# defined on subclasses.
|
|
20
|
-
#
|
|
21
|
-
# @param child [Class<XTwitterScraper::Internal::Type::BaseModel>]
|
|
22
15
|
def inherited(child)
|
|
23
16
|
super
|
|
24
17
|
child.known_fields.replace(known_fields.dup)
|
|
25
18
|
end
|
|
26
19
|
|
|
27
|
-
# @api private
|
|
28
|
-
#
|
|
29
|
-
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
|
30
20
|
def known_fields = @known_fields ||= {}
|
|
31
21
|
|
|
32
|
-
# @api private
|
|
33
|
-
#
|
|
34
|
-
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
|
35
22
|
def fields
|
|
36
23
|
known_fields.transform_values do |field|
|
|
37
24
|
{**field.except(:type_fn), type: field.fetch(:type_fn).call}
|
|
38
25
|
end
|
|
39
26
|
end
|
|
40
27
|
|
|
41
|
-
# @api private
|
|
42
|
-
#
|
|
43
|
-
# @param name_sym [Symbol]
|
|
44
|
-
#
|
|
45
|
-
# @param required [Boolean]
|
|
46
|
-
#
|
|
47
|
-
# @param type_info [Hash{Symbol=>Object}, Proc, XTwitterScraper::Internal::Type::Converter, Class]
|
|
48
|
-
#
|
|
49
|
-
# @param spec [Hash{Symbol=>Object}] .
|
|
50
|
-
#
|
|
51
|
-
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
|
52
|
-
#
|
|
53
|
-
# @option spec [Proc] :enum
|
|
54
|
-
#
|
|
55
|
-
# @option spec [Proc] :union
|
|
56
|
-
#
|
|
57
|
-
# @option spec [Boolean] :"nil?"
|
|
58
28
|
private def add_field(name_sym, required:, type_info:, spec:)
|
|
59
29
|
meta = XTwitterScraper::Internal::Type::Converter.meta_info(type_info, spec)
|
|
60
30
|
type_fn, info =
|
|
@@ -99,7 +69,7 @@ module XTwitterScraper
|
|
|
99
69
|
end
|
|
100
70
|
|
|
101
71
|
# rubocop:disable Style/CaseEquality
|
|
102
|
-
# rubocop:disable Metrics/BlockLength
|
|
72
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
103
73
|
define_method(name_sym) do
|
|
104
74
|
target = type_fn.call
|
|
105
75
|
|
|
@@ -136,54 +106,17 @@ module XTwitterScraper
|
|
|
136
106
|
end
|
|
137
107
|
end
|
|
138
108
|
end
|
|
139
|
-
# rubocop:enable Metrics/BlockLength
|
|
140
109
|
# rubocop:enable Style/CaseEquality
|
|
141
110
|
end
|
|
142
111
|
|
|
143
|
-
# @api private
|
|
144
|
-
#
|
|
145
|
-
# @param name_sym [Symbol]
|
|
146
|
-
#
|
|
147
|
-
# @param type_info [Hash{Symbol=>Object}, Proc, XTwitterScraper::Internal::Type::Converter, Class]
|
|
148
|
-
#
|
|
149
|
-
# @param spec [Hash{Symbol=>Object}] .
|
|
150
|
-
#
|
|
151
|
-
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
|
152
|
-
#
|
|
153
|
-
# @option spec [Proc] :enum
|
|
154
|
-
#
|
|
155
|
-
# @option spec [Proc] :union
|
|
156
|
-
#
|
|
157
|
-
# @option spec [Boolean] :"nil?"
|
|
158
112
|
def required(name_sym, type_info, spec = {})
|
|
159
113
|
add_field(name_sym, required: true, type_info: type_info, spec: spec)
|
|
160
114
|
end
|
|
161
115
|
|
|
162
|
-
# @api private
|
|
163
|
-
#
|
|
164
|
-
# @param name_sym [Symbol]
|
|
165
|
-
#
|
|
166
|
-
# @param type_info [Hash{Symbol=>Object}, Proc, XTwitterScraper::Internal::Type::Converter, Class]
|
|
167
|
-
#
|
|
168
|
-
# @param spec [Hash{Symbol=>Object}] .
|
|
169
|
-
#
|
|
170
|
-
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
|
171
|
-
#
|
|
172
|
-
# @option spec [Proc] :enum
|
|
173
|
-
#
|
|
174
|
-
# @option spec [Proc] :union
|
|
175
|
-
#
|
|
176
|
-
# @option spec [Boolean] :"nil?"
|
|
177
116
|
def optional(name_sym, type_info, spec = {})
|
|
178
117
|
add_field(name_sym, required: false, type_info: type_info, spec: spec)
|
|
179
118
|
end
|
|
180
119
|
|
|
181
|
-
# @api private
|
|
182
|
-
#
|
|
183
|
-
# `request_only` attributes not excluded from `.#coerce` when receiving responses
|
|
184
|
-
# even if well behaved servers should not send them
|
|
185
|
-
#
|
|
186
|
-
# @param blk [Proc]
|
|
187
120
|
private def request_only(&blk)
|
|
188
121
|
@mode = :dump
|
|
189
122
|
blk.call
|
|
@@ -191,11 +124,6 @@ module XTwitterScraper
|
|
|
191
124
|
@mode = nil
|
|
192
125
|
end
|
|
193
126
|
|
|
194
|
-
# @api private
|
|
195
|
-
#
|
|
196
|
-
# `response_only` attributes are omitted from `.#dump` when making requests
|
|
197
|
-
#
|
|
198
|
-
# @param blk [Proc]
|
|
199
127
|
private def response_only(&blk)
|
|
200
128
|
@mode = :coerce
|
|
201
129
|
blk.call
|
|
@@ -209,9 +137,8 @@ module XTwitterScraper
|
|
|
209
137
|
#
|
|
210
138
|
# @return [Boolean]
|
|
211
139
|
def ==(other)
|
|
212
|
-
# rubocop:disable Layout/LineLength
|
|
140
|
+
# rubocop:disable-next Layout/LineLength
|
|
213
141
|
other.is_a?(Class) && other <= XTwitterScraper::Internal::Type::BaseModel && other.fields == fields
|
|
214
|
-
# rubocop:enable Layout/LineLength
|
|
215
142
|
end
|
|
216
143
|
|
|
217
144
|
# @api public
|
|
@@ -233,23 +160,6 @@ module XTwitterScraper
|
|
|
233
160
|
def hash = [self.class, @data].hash
|
|
234
161
|
|
|
235
162
|
class << self
|
|
236
|
-
# @api private
|
|
237
|
-
#
|
|
238
|
-
# @param value [XTwitterScraper::Internal::Type::BaseModel, Hash{Object=>Object}, Object]
|
|
239
|
-
#
|
|
240
|
-
# @param state [Hash{Symbol=>Object}] .
|
|
241
|
-
#
|
|
242
|
-
# @option state [Boolean] :translate_names
|
|
243
|
-
#
|
|
244
|
-
# @option state [Boolean] :strictness
|
|
245
|
-
#
|
|
246
|
-
# @option state [Hash{Symbol=>Object}] :exactness
|
|
247
|
-
#
|
|
248
|
-
# @option state [Class<StandardError>] :error
|
|
249
|
-
#
|
|
250
|
-
# @option state [Integer] :branched
|
|
251
|
-
#
|
|
252
|
-
# @return [self, Object]
|
|
253
163
|
def coerce(value, state:)
|
|
254
164
|
exactness = state.fetch(:exactness)
|
|
255
165
|
|
|
@@ -270,7 +180,7 @@ module XTwitterScraper
|
|
|
270
180
|
data = instance.to_h
|
|
271
181
|
status = instance.instance_variable_get(:@coerced)
|
|
272
182
|
|
|
273
|
-
# rubocop:disable Metrics/BlockLength
|
|
183
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
274
184
|
fields.each do |name, field|
|
|
275
185
|
mode, required, target = field.fetch_values(:mode, :required, :type)
|
|
276
186
|
api_name, nilable, const = field.fetch_values(:api_name, :nilable, :const)
|
|
@@ -306,21 +216,11 @@ module XTwitterScraper
|
|
|
306
216
|
status.store(name, state.fetch(:error) || true)
|
|
307
217
|
data.store(name, converted)
|
|
308
218
|
end
|
|
309
|
-
# rubocop:enable Metrics/BlockLength
|
|
310
219
|
|
|
311
220
|
keys.each { data.store(_1, val.fetch(_1)) }
|
|
312
221
|
instance
|
|
313
222
|
end
|
|
314
223
|
|
|
315
|
-
# @api private
|
|
316
|
-
#
|
|
317
|
-
# @param value [self, Object]
|
|
318
|
-
#
|
|
319
|
-
# @param state [Hash{Symbol=>Object}] .
|
|
320
|
-
#
|
|
321
|
-
# @option state [Boolean] :can_retry
|
|
322
|
-
#
|
|
323
|
-
# @return [Hash{Object=>Object}, Object]
|
|
324
224
|
def dump(value, state:)
|
|
325
225
|
unless (coerced = XTwitterScraper::Internal::Util.coerce_hash(value)).is_a?(Hash)
|
|
326
226
|
return super
|
|
@@ -357,21 +257,12 @@ module XTwitterScraper
|
|
|
357
257
|
acc
|
|
358
258
|
end
|
|
359
259
|
|
|
360
|
-
# @api private
|
|
361
|
-
#
|
|
362
|
-
# @return [Object]
|
|
363
260
|
def to_sorbet_type
|
|
364
261
|
self
|
|
365
262
|
end
|
|
366
263
|
end
|
|
367
264
|
|
|
368
265
|
class << self
|
|
369
|
-
# @api private
|
|
370
|
-
#
|
|
371
|
-
# @param model [XTwitterScraper::Internal::Type::BaseModel]
|
|
372
|
-
# @param convert [Boolean]
|
|
373
|
-
#
|
|
374
|
-
# @return [Hash{Symbol=>Object}]
|
|
375
266
|
def recursively_to_h(model, convert:)
|
|
376
267
|
rec = ->(x) do
|
|
377
268
|
case x
|
|
@@ -442,16 +333,6 @@ module XTwitterScraper
|
|
|
442
333
|
# @return [Hash{Symbol=>Object}]
|
|
443
334
|
def deep_to_h = self.class.recursively_to_h(@data, convert: false)
|
|
444
335
|
|
|
445
|
-
# @param keys [Array<Symbol>, nil]
|
|
446
|
-
#
|
|
447
|
-
# @return [Hash{Symbol=>Object}]
|
|
448
|
-
#
|
|
449
|
-
# @example
|
|
450
|
-
# # `content_disclosure` is a `XTwitterScraper::ContentDisclosure`
|
|
451
|
-
# content_disclosure => {
|
|
452
|
-
# advertising: advertising,
|
|
453
|
-
# ai_generated: ai_generated
|
|
454
|
-
# }
|
|
455
336
|
def deconstruct_keys(keys)
|
|
456
337
|
(keys || self.class.known_fields.keys)
|
|
457
338
|
.filter_map do |k|
|
|
@@ -478,9 +359,6 @@ module XTwitterScraper
|
|
|
478
359
|
# @return [String]
|
|
479
360
|
def to_yaml(*a) = XTwitterScraper::Internal::Type::Converter.dump(self.class, self).to_yaml(*a)
|
|
480
361
|
|
|
481
|
-
# Create a new instance of a model.
|
|
482
|
-
#
|
|
483
|
-
# @param data [Hash{Symbol=>Object}, self]
|
|
484
362
|
def initialize(data = {})
|
|
485
363
|
@data = {}
|
|
486
364
|
@coerced = {}
|
|
@@ -495,11 +373,6 @@ module XTwitterScraper
|
|
|
495
373
|
end
|
|
496
374
|
|
|
497
375
|
class << self
|
|
498
|
-
# @api private
|
|
499
|
-
#
|
|
500
|
-
# @param depth [Integer]
|
|
501
|
-
#
|
|
502
|
-
# @return [String]
|
|
503
376
|
def inspect(depth: 0)
|
|
504
377
|
return super() if depth.positive?
|
|
505
378
|
|
|
@@ -522,9 +395,6 @@ module XTwitterScraper
|
|
|
522
395
|
# @return [String]
|
|
523
396
|
def to_s = deep_to_h.to_s
|
|
524
397
|
|
|
525
|
-
# @api private
|
|
526
|
-
#
|
|
527
|
-
# @return [String]
|
|
528
398
|
def inspect
|
|
529
399
|
converted = self.class.recursively_to_h(self, convert: true)
|
|
530
400
|
"#<#{self.class}:0x#{object_id.to_s(16)} #{converted}>"
|
|
@@ -7,11 +7,6 @@
|
|
|
7
7
|
module XTwitterScraper
|
|
8
8
|
module Internal
|
|
9
9
|
module Type
|
|
10
|
-
# @api private
|
|
11
|
-
#
|
|
12
|
-
# @generic Elem
|
|
13
|
-
#
|
|
14
|
-
# This module provides a base implementation for paginated responses in the SDK.
|
|
15
10
|
module BasePage
|
|
16
11
|
# rubocop:disable Lint/UnusedMethodArgument
|
|
17
12
|
|
|
@@ -34,24 +29,16 @@ module XTwitterScraper
|
|
|
34
29
|
# @return [void]
|
|
35
30
|
def auto_paging_each(&blk) = (raise NotImplementedError)
|
|
36
31
|
|
|
37
|
-
# @return [Enumerable<generic<Elem>>]
|
|
38
32
|
def to_enum = super(:auto_paging_each)
|
|
39
33
|
|
|
40
34
|
alias_method :enum_for, :to_enum
|
|
41
35
|
|
|
42
|
-
# @api private
|
|
43
|
-
#
|
|
44
|
-
# @param client [XTwitterScraper::Internal::Transport::BaseClient]
|
|
45
|
-
# @param req [Hash{Symbol=>Object}]
|
|
46
|
-
# @param headers [Hash{String=>String}]
|
|
47
|
-
# @param page_data [Object]
|
|
48
36
|
def initialize(client:, req:, headers:, page_data:)
|
|
49
37
|
@client = client
|
|
50
38
|
@req = req
|
|
51
39
|
@model = req.fetch(:model)
|
|
52
40
|
super()
|
|
53
41
|
end
|
|
54
|
-
|
|
55
42
|
# rubocop:enable Lint/UnusedMethodArgument
|
|
56
43
|
end
|
|
57
44
|
end
|
|
@@ -7,11 +7,6 @@
|
|
|
7
7
|
module XTwitterScraper
|
|
8
8
|
module Internal
|
|
9
9
|
module Type
|
|
10
|
-
# @api private
|
|
11
|
-
#
|
|
12
|
-
# @abstract
|
|
13
|
-
#
|
|
14
|
-
# Ruby has no Boolean class; this is something for models to refer to.
|
|
15
10
|
class Boolean
|
|
16
11
|
extend XTwitterScraper::Internal::Type::Converter
|
|
17
12
|
extend XTwitterScraper::Internal::Util::SorbetRuntimeSupport
|
|
@@ -33,44 +28,11 @@ module XTwitterScraper
|
|
|
33
28
|
def self.==(other) = other.is_a?(Class) && other <= XTwitterScraper::Internal::Type::Boolean
|
|
34
29
|
|
|
35
30
|
class << self
|
|
36
|
-
# @api private
|
|
37
|
-
#
|
|
38
|
-
# Coerce value to Boolean if possible, otherwise return the original value.
|
|
39
|
-
#
|
|
40
|
-
# @param value [Boolean, Object]
|
|
41
|
-
#
|
|
42
|
-
# @param state [Hash{Symbol=>Object}] .
|
|
43
|
-
#
|
|
44
|
-
# @option state [Boolean] :translate_names
|
|
45
|
-
#
|
|
46
|
-
# @option state [Boolean] :strictness
|
|
47
|
-
#
|
|
48
|
-
# @option state [Hash{Symbol=>Object}] :exactness
|
|
49
|
-
#
|
|
50
|
-
# @option state [Class<StandardError>] :error
|
|
51
|
-
#
|
|
52
|
-
# @option state [Integer] :branched
|
|
53
|
-
#
|
|
54
|
-
# @return [Boolean, Object]
|
|
55
31
|
def coerce(value, state:)
|
|
56
32
|
state.fetch(:exactness)[value == true || value == false ? :yes : :no] += 1
|
|
57
33
|
value
|
|
58
34
|
end
|
|
59
35
|
|
|
60
|
-
# @!method dump(value, state:)
|
|
61
|
-
# @api private
|
|
62
|
-
#
|
|
63
|
-
# @param value [Boolean, Object]
|
|
64
|
-
#
|
|
65
|
-
# @param state [Hash{Symbol=>Object}] .
|
|
66
|
-
#
|
|
67
|
-
# @option state [Boolean] :can_retry
|
|
68
|
-
#
|
|
69
|
-
# @return [Boolean, Object]
|
|
70
|
-
|
|
71
|
-
# @api private
|
|
72
|
-
#
|
|
73
|
-
# @return [Object]
|
|
74
36
|
def to_sorbet_type
|
|
75
37
|
T::Boolean
|
|
76
38
|
end
|