searchapi 1.0.0
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 +7 -0
- data/README.md +175 -0
- data/bin/test +14 -0
- data/lib/searchapi/error_result.rb +50 -0
- data/lib/searchapi/google_finance_options.rb +40 -0
- data/lib/searchapi/google_finance_request.rb +26 -0
- data/lib/searchapi/google_finance_result.rb +262 -0
- data/lib/searchapi/google_flights_options.rb +85 -0
- data/lib/searchapi/google_flights_request.rb +25 -0
- data/lib/searchapi/google_flights_result.rb +275 -0
- data/lib/searchapi/google_images_options.rb +64 -0
- data/lib/searchapi/google_images_request.rb +26 -0
- data/lib/searchapi/google_images_result.rb +133 -0
- data/lib/searchapi/google_light_options.rb +43 -0
- data/lib/searchapi/google_light_request.rb +26 -0
- data/lib/searchapi/google_light_result.rb +198 -0
- data/lib/searchapi/google_local_options.rb +40 -0
- data/lib/searchapi/google_local_request.rb +26 -0
- data/lib/searchapi/google_local_result.rb +85 -0
- data/lib/searchapi/google_news_light_options.rb +47 -0
- data/lib/searchapi/google_news_light_request.rb +26 -0
- data/lib/searchapi/google_news_light_result.rb +94 -0
- data/lib/searchapi/google_news_options.rb +53 -0
- data/lib/searchapi/google_news_portal_options.rb +40 -0
- data/lib/searchapi/google_news_portal_request.rb +89 -0
- data/lib/searchapi/google_news_portal_result.rb +137 -0
- data/lib/searchapi/google_news_request.rb +26 -0
- data/lib/searchapi/google_news_result.rb +129 -0
- data/lib/searchapi/google_scholar_options.rb +48 -0
- data/lib/searchapi/google_scholar_request.rb +26 -0
- data/lib/searchapi/google_scholar_result.rb +195 -0
- data/lib/searchapi/google_search_options.rb +67 -0
- data/lib/searchapi/google_search_request.rb +26 -0
- data/lib/searchapi/google_search_result.rb +301 -0
- data/lib/searchapi/helpers.rb +10 -0
- data/lib/searchapi/instagram_profile_options.rb +31 -0
- data/lib/searchapi/instagram_profile_request.rb +26 -0
- data/lib/searchapi/instagram_profile_result.rb +117 -0
- data/lib/searchapi/module_methods.rb +80 -0
- data/lib/searchapi/request.rb +25 -0
- data/lib/searchapi/response_methods.rb +14 -0
- data/lib/searchapi/tiktok_profile_options.rb +31 -0
- data/lib/searchapi/tiktok_profile_request.rb +26 -0
- data/lib/searchapi/tiktok_profile_result.rb +71 -0
- data/lib/searchapi/version.rb +3 -0
- data/lib/searchapi/youtube_search_options.rb +62 -0
- data/lib/searchapi/youtube_search_request.rb +26 -0
- data/lib/searchapi/youtube_search_result.rb +411 -0
- data/lib/searchapi.rb +70 -0
- data/searchapi.gemspec +37 -0
- metadata +164 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class TikTokProfileOptions
|
|
3
|
+
include DynamicSchema::Definable
|
|
4
|
+
include Helpers
|
|
5
|
+
|
|
6
|
+
schema do
|
|
7
|
+
# required
|
|
8
|
+
username String
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.build( options = nil, &block )
|
|
12
|
+
new( api_options: builder.build( options, &block ) )
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.build!( options = nil, &block )
|
|
16
|
+
new( api_options: builder.build!( options, &block ) )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def initialize( options = {}, api_options: nil )
|
|
20
|
+
@options = self.class.builder.build( options || {} )
|
|
21
|
+
@options = api_options.merge( @options ) if api_options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_h
|
|
25
|
+
result = @options.to_h
|
|
26
|
+
result[ :engine ] = 'tiktok_profile'
|
|
27
|
+
result
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class TikTokProfileRequest < Request
|
|
3
|
+
|
|
4
|
+
def profile( username, options = nil, &block )
|
|
5
|
+
if options
|
|
6
|
+
options = options.is_a?( TikTokProfileOptions ) ? options : TikTokProfileOptions.build!( options.to_h )
|
|
7
|
+
options = options.to_h
|
|
8
|
+
else
|
|
9
|
+
options = { engine: 'tiktok_profile' }
|
|
10
|
+
end
|
|
11
|
+
options[ :username ] = username.to_s
|
|
12
|
+
|
|
13
|
+
response = get( "#{ BASE_URI }/search", options, &block )
|
|
14
|
+
attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )
|
|
15
|
+
|
|
16
|
+
result = if response.success?
|
|
17
|
+
TikTokProfileResult.new( attributes || {} )
|
|
18
|
+
else
|
|
19
|
+
ErrorResult.new( response.status, attributes )
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
ResponseMethods.install( response, result )
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module SearchAPI
|
|
4
|
+
|
|
5
|
+
# TikTok Search metadata
|
|
6
|
+
TikTokProfileMetadataSchema = DynamicSchema::Struct.define do
|
|
7
|
+
id String
|
|
8
|
+
status String
|
|
9
|
+
created_at String, as: :created_at
|
|
10
|
+
request_time_taken Float, as: :request_time_taken
|
|
11
|
+
parsing_time_taken Float, as: :parsing_time_taken
|
|
12
|
+
total_time_taken Float, as: :total_time_taken
|
|
13
|
+
request_url String, as: :request_url
|
|
14
|
+
html_url String, as: :html_url
|
|
15
|
+
json_url String, as: :json_url
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class TikTokProfileMetadata < TikTokProfileMetadataSchema
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# TikTok Search parameters
|
|
22
|
+
TikTokProfileParametersSchema = DynamicSchema::Struct.define do
|
|
23
|
+
engine String
|
|
24
|
+
username String
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class TikTokProfileParameters < TikTokProfileParametersSchema
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Profile
|
|
31
|
+
TikTokProfileSchema = DynamicSchema::Struct.define do
|
|
32
|
+
username String
|
|
33
|
+
name String
|
|
34
|
+
bio String
|
|
35
|
+
avatar String
|
|
36
|
+
avatar_hd String, as: :avatar_hd
|
|
37
|
+
is_verified [ TrueClass, FalseClass ], as: :is_verified
|
|
38
|
+
is_private [ TrueClass, FalseClass ], as: :is_private
|
|
39
|
+
is_business [ TrueClass, FalseClass ], as: :is_business
|
|
40
|
+
posts Integer
|
|
41
|
+
followers Integer
|
|
42
|
+
following Integer
|
|
43
|
+
category String
|
|
44
|
+
bio_link String, as: :bio_link
|
|
45
|
+
hearts Integer
|
|
46
|
+
language String
|
|
47
|
+
created_at String, as: :created_at
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class TikTokProfile < TikTokProfileSchema
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Main TikTok profile result
|
|
54
|
+
TikTokProfileResultSchema = DynamicSchema::Struct.define do
|
|
55
|
+
search_metadata TikTokProfileMetadata, as: :search_metadata
|
|
56
|
+
search_parameters TikTokProfileParameters, as: :search_parameters
|
|
57
|
+
profile TikTokProfile
|
|
58
|
+
error String
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class TikTokProfileResult < TikTokProfileResultSchema
|
|
62
|
+
extend Forwardable
|
|
63
|
+
|
|
64
|
+
def_delegators :profile, :username, :name, :bio, :avatar, :followers, :following, :hearts
|
|
65
|
+
|
|
66
|
+
def success?
|
|
67
|
+
self.error.nil?
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class YouTubeSearchOptions
|
|
3
|
+
include DynamicSchema::Definable
|
|
4
|
+
include Helpers
|
|
5
|
+
|
|
6
|
+
COUNTRIES = %w[
|
|
7
|
+
DZ AR AU AT AZ BH BD BY BE BO BA BR BG KH CA
|
|
8
|
+
CL CO CR HR CY CZ DK DO EC EG SV EE FI FR GE
|
|
9
|
+
DE GH GR GT HN HK HU IS IN ID IQ IE IL IT JM
|
|
10
|
+
JP JO KZ KE KW LA LV LB LY LI LT LU MY MT MX
|
|
11
|
+
ME MA NP NL NZ NI NG MK NO OM PK PA PG PY PE
|
|
12
|
+
PH PL PT PR QA RO RU SA SN RS SG SK SI ZA KR
|
|
13
|
+
ES LK SE CH TW TZ TH TN TR UG UA AE GB US UY
|
|
14
|
+
VE VN YE ZW
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
LANGUAGES = %w[
|
|
18
|
+
af az id ms bs ca cs da de et en-in en-gb en
|
|
19
|
+
es es-419 es-us eu fil fr fr-ca gl hr zu is
|
|
20
|
+
it sw lv lt hu nl no uz pl pt-pt pt ro sq sk
|
|
21
|
+
sl sr-latn fi sv vi tr be bg ky kk mk mn ru
|
|
22
|
+
sr uk el hy iw ur ar fa ne mr hi as bn pa gu
|
|
23
|
+
or ta te kn ml si th lo my ka am km zh-cn
|
|
24
|
+
zh-tw zh-hk ja ko
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
NORMALIZE_UPCASE = ->(v) { v.to_s.upcase }
|
|
28
|
+
NORMALIZE_DOWNCASE = ->(v) { v.to_s.downcase }
|
|
29
|
+
|
|
30
|
+
schema do
|
|
31
|
+
# search query (required)
|
|
32
|
+
q String
|
|
33
|
+
|
|
34
|
+
# filter/pagination token
|
|
35
|
+
sp String
|
|
36
|
+
|
|
37
|
+
# localization
|
|
38
|
+
gl String, in: COUNTRIES, normalize: NORMALIZE_UPCASE
|
|
39
|
+
hl String, in: LANGUAGES, normalize: NORMALIZE_DOWNCASE
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.build( options = nil, &block )
|
|
43
|
+
new( api_options: builder.build( options, &block ) )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.build!( options = nil, &block )
|
|
47
|
+
new( api_options: builder.build!( options, &block ) )
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def initialize( options = {}, api_options: nil )
|
|
51
|
+
@options = self.class.builder.build( options || {} )
|
|
52
|
+
@options = api_options.merge( @options ) if api_options
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def to_h
|
|
56
|
+
result = @options.to_h
|
|
57
|
+
result[ :engine ] = 'youtube'
|
|
58
|
+
result
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class YouTubeSearchRequest < Request
|
|
3
|
+
|
|
4
|
+
def search( query, options = nil, &block )
|
|
5
|
+
if options
|
|
6
|
+
options = options.is_a?( YouTubeSearchOptions ) ? options : YouTubeSearchOptions.build!( options.to_h )
|
|
7
|
+
options = options.to_h
|
|
8
|
+
else
|
|
9
|
+
options = { engine: 'youtube' }
|
|
10
|
+
end
|
|
11
|
+
options[ :q ] = query.to_s
|
|
12
|
+
|
|
13
|
+
response = get( "#{ BASE_URI }/search", options, &block )
|
|
14
|
+
attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )
|
|
15
|
+
|
|
16
|
+
result = if response.success?
|
|
17
|
+
YouTubeSearchResult.new( attributes || {} )
|
|
18
|
+
else
|
|
19
|
+
ErrorResult.new( response.status, attributes )
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
ResponseMethods.install( response, result )
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module SearchAPI
|
|
4
|
+
|
|
5
|
+
# YouTube Search metadata
|
|
6
|
+
YouTubeSearchMetadataSchema = DynamicSchema::Struct.define do
|
|
7
|
+
id String
|
|
8
|
+
status String
|
|
9
|
+
created_at String, as: :created_at
|
|
10
|
+
request_time_taken Float, as: :request_time_taken
|
|
11
|
+
parsing_time_taken Float, as: :parsing_time_taken
|
|
12
|
+
total_time_taken Float, as: :total_time_taken
|
|
13
|
+
request_url String, as: :request_url
|
|
14
|
+
html_url String, as: :html_url
|
|
15
|
+
json_url String, as: :json_url
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class YouTubeSearchMetadata < YouTubeSearchMetadataSchema
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# YouTube Search parameters
|
|
22
|
+
YouTubeSearchParametersSchema = DynamicSchema::Struct.define do
|
|
23
|
+
engine String
|
|
24
|
+
q String
|
|
25
|
+
sp String
|
|
26
|
+
hl String
|
|
27
|
+
gl String
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class YouTubeSearchParameters < YouTubeSearchParametersSchema
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# YouTube Search information
|
|
34
|
+
YouTubeSearchInformationSchema = DynamicSchema::Struct.define do
|
|
35
|
+
total_results Integer, as: :total_results
|
|
36
|
+
state String
|
|
37
|
+
original_query String, as: :original_query
|
|
38
|
+
original_query_sp String, as: :original_query_sp
|
|
39
|
+
corrected_query String, as: :corrected_query
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class YouTubeSearchInformation < YouTubeSearchInformationSchema
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# YouTube Thumbnail
|
|
46
|
+
YouTubeThumbnailSchema = DynamicSchema::Struct.define do
|
|
47
|
+
static String
|
|
48
|
+
rich String
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class YouTubeThumbnail < YouTubeThumbnailSchema
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Video channel
|
|
55
|
+
YouTubeVideoChannelSchema = DynamicSchema::Struct.define do
|
|
56
|
+
id String
|
|
57
|
+
title String
|
|
58
|
+
link String
|
|
59
|
+
is_verified [ TrueClass, FalseClass ], as: :is_verified
|
|
60
|
+
thumbnail String
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class YouTubeVideoChannel < YouTubeVideoChannelSchema
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Key moment
|
|
67
|
+
YouTubeKeyMomentSchema = DynamicSchema::Struct.define do
|
|
68
|
+
title String
|
|
69
|
+
start_seconds Integer, as: :start_seconds
|
|
70
|
+
thumbnail String
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class YouTubeKeyMoment < YouTubeKeyMomentSchema
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Video result
|
|
77
|
+
YouTubeVideoSchema = DynamicSchema::Struct.define do
|
|
78
|
+
position Integer
|
|
79
|
+
id String
|
|
80
|
+
title String
|
|
81
|
+
link String
|
|
82
|
+
description String
|
|
83
|
+
views Integer
|
|
84
|
+
is_live [ TrueClass, FalseClass ], as: :is_live
|
|
85
|
+
channel YouTubeVideoChannel
|
|
86
|
+
length String
|
|
87
|
+
published_time String, as: :published_time
|
|
88
|
+
badges String, array: true
|
|
89
|
+
thumbnail YouTubeThumbnail
|
|
90
|
+
key_moments YouTubeKeyMoment, array: true, as: :key_moments
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class YouTubeVideo < YouTubeVideoSchema
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Channel result
|
|
97
|
+
YouTubeChannelSchema = DynamicSchema::Struct.define do
|
|
98
|
+
position Integer
|
|
99
|
+
id String
|
|
100
|
+
title String
|
|
101
|
+
link String
|
|
102
|
+
description String
|
|
103
|
+
is_verified [ TrueClass, FalseClass ], as: :is_verified
|
|
104
|
+
video_count Integer, as: :video_count
|
|
105
|
+
subscribers Integer
|
|
106
|
+
thumbnail YouTubeThumbnail
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class YouTubeChannel < YouTubeChannelSchema
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Playlist channel
|
|
113
|
+
YouTubePlaylistChannelSchema = DynamicSchema::Struct.define do
|
|
114
|
+
id String
|
|
115
|
+
title String
|
|
116
|
+
is_verified [ TrueClass, FalseClass ], as: :is_verified
|
|
117
|
+
link String
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
class YouTubePlaylistChannel < YouTubePlaylistChannelSchema
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Playlist video
|
|
124
|
+
YouTubePlaylistVideoSchema = DynamicSchema::Struct.define do
|
|
125
|
+
id String
|
|
126
|
+
title String
|
|
127
|
+
link String
|
|
128
|
+
length String
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
class YouTubePlaylistVideo < YouTubePlaylistVideoSchema
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Playlist result
|
|
135
|
+
YouTubePlaylistSchema = DynamicSchema::Struct.define do
|
|
136
|
+
position Integer
|
|
137
|
+
id String
|
|
138
|
+
title String
|
|
139
|
+
link String
|
|
140
|
+
video_count Integer, as: :video_count
|
|
141
|
+
channel YouTubePlaylistChannel
|
|
142
|
+
published_time String, as: :published_time
|
|
143
|
+
videos YouTubePlaylistVideo, array: true
|
|
144
|
+
thumbnail String
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
class YouTubePlaylist < YouTubePlaylistSchema
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Movie channel
|
|
151
|
+
YouTubeMovieChannelSchema = DynamicSchema::Struct.define do
|
|
152
|
+
id String
|
|
153
|
+
title String
|
|
154
|
+
link String
|
|
155
|
+
is_verified [ TrueClass, FalseClass ], as: :is_verified
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
class YouTubeMovieChannel < YouTubeMovieChannelSchema
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Metadata items
|
|
162
|
+
YouTubeMetadataItemsSchema = DynamicSchema::Struct.define do
|
|
163
|
+
top String, array: true
|
|
164
|
+
bottom String, array: true
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
class YouTubeMetadataItems < YouTubeMetadataItemsSchema
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Movie result
|
|
171
|
+
YouTubeMovieSchema = DynamicSchema::Struct.define do
|
|
172
|
+
position Integer
|
|
173
|
+
id String
|
|
174
|
+
title String
|
|
175
|
+
link String
|
|
176
|
+
description String
|
|
177
|
+
channel YouTubeMovieChannel
|
|
178
|
+
length String
|
|
179
|
+
metadata_items YouTubeMetadataItems, as: :metadata_items
|
|
180
|
+
badges String, array: true
|
|
181
|
+
buttons String, array: true
|
|
182
|
+
thumbnail String
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
class YouTubeMovie < YouTubeMovieSchema
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Short video
|
|
189
|
+
YouTubeShortSchema = DynamicSchema::Struct.define do
|
|
190
|
+
position Integer
|
|
191
|
+
id String
|
|
192
|
+
title String
|
|
193
|
+
link String
|
|
194
|
+
duration String
|
|
195
|
+
views Integer
|
|
196
|
+
thumbnail String
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
class YouTubeShort < YouTubeShortSchema
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Shorts section
|
|
203
|
+
YouTubeShortsSchema = DynamicSchema::Struct.define do
|
|
204
|
+
section_title String, as: :section_title
|
|
205
|
+
position Integer
|
|
206
|
+
items YouTubeShort, array: true
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
class YouTubeShorts < YouTubeShortsSchema
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Post channel
|
|
213
|
+
YouTubePostChannelSchema = DynamicSchema::Struct.define do
|
|
214
|
+
id String
|
|
215
|
+
title String
|
|
216
|
+
link String
|
|
217
|
+
is_verified [ TrueClass, FalseClass ], as: :is_verified
|
|
218
|
+
thumbnail String
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
class YouTubePostChannel < YouTubePostChannelSchema
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Post item
|
|
225
|
+
YouTubePostSchema = DynamicSchema::Struct.define do
|
|
226
|
+
position Integer
|
|
227
|
+
id String
|
|
228
|
+
link String
|
|
229
|
+
text String
|
|
230
|
+
likes String
|
|
231
|
+
extracted_likes Integer, as: :extracted_likes
|
|
232
|
+
comments String
|
|
233
|
+
extracted_comments Integer, as: :extracted_comments
|
|
234
|
+
channel YouTubePostChannel
|
|
235
|
+
published_time String, as: :published_time
|
|
236
|
+
thumbnail String
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
class YouTubePost < YouTubePostSchema
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Posts section
|
|
243
|
+
YouTubePostsSchema = DynamicSchema::Struct.define do
|
|
244
|
+
section_title String, as: :section_title
|
|
245
|
+
position Integer
|
|
246
|
+
items YouTubePost, array: true
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
class YouTubePosts < YouTubePostsSchema
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Section channel
|
|
253
|
+
YouTubeSectionChannelSchema = DynamicSchema::Struct.define do
|
|
254
|
+
id String
|
|
255
|
+
title String
|
|
256
|
+
link String
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
class YouTubeSectionChannel < YouTubeSectionChannelSchema
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# Section item
|
|
263
|
+
YouTubeSectionItemSchema = DynamicSchema::Struct.define do
|
|
264
|
+
id String
|
|
265
|
+
title String
|
|
266
|
+
link String
|
|
267
|
+
channel YouTubeSectionChannel
|
|
268
|
+
views Integer
|
|
269
|
+
published_time String, as: :published_time
|
|
270
|
+
length String
|
|
271
|
+
thumbnail String
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
class YouTubeSectionItem < YouTubeSectionItemSchema
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Section
|
|
278
|
+
YouTubeSectionSchema = DynamicSchema::Struct.define do
|
|
279
|
+
section_title String, as: :section_title
|
|
280
|
+
position Integer
|
|
281
|
+
items YouTubeSectionItem, array: true
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
class YouTubeSection < YouTubeSectionSchema
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# People also search for
|
|
288
|
+
YouTubePeopleAlsoSearchForSchema = DynamicSchema::Struct.define do
|
|
289
|
+
query String
|
|
290
|
+
link String
|
|
291
|
+
thumbnail String
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
class YouTubePeopleAlsoSearchFor < YouTubePeopleAlsoSearchForSchema
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Ad channel
|
|
298
|
+
YouTubeAdChannelSchema = DynamicSchema::Struct.define do
|
|
299
|
+
id String
|
|
300
|
+
title String
|
|
301
|
+
link String
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
class YouTubeAdChannel < YouTubeAdChannelSchema
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Ad result
|
|
308
|
+
YouTubeAdSchema = DynamicSchema::Struct.define do
|
|
309
|
+
position Integer
|
|
310
|
+
id String
|
|
311
|
+
title String
|
|
312
|
+
link String
|
|
313
|
+
description String
|
|
314
|
+
website String
|
|
315
|
+
channel YouTubeAdChannel
|
|
316
|
+
length String
|
|
317
|
+
thumbnail String
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
class YouTubeAd < YouTubeAdSchema
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Featured video channel
|
|
324
|
+
YouTubeFeaturedVideoChannelSchema = DynamicSchema::Struct.define do
|
|
325
|
+
id String
|
|
326
|
+
title String
|
|
327
|
+
link String
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
class YouTubeFeaturedVideoChannel < YouTubeFeaturedVideoChannelSchema
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# Featured video
|
|
334
|
+
YouTubeFeaturedVideoSchema = DynamicSchema::Struct.define do
|
|
335
|
+
id String
|
|
336
|
+
title String
|
|
337
|
+
subtitle String
|
|
338
|
+
link String
|
|
339
|
+
length String
|
|
340
|
+
channel YouTubeFeaturedVideoChannel
|
|
341
|
+
thumbnail String
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
class YouTubeFeaturedVideo < YouTubeFeaturedVideoSchema
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# Highlighted video
|
|
348
|
+
YouTubeHighlightedVideoSchema = DynamicSchema::Struct.define do
|
|
349
|
+
id String
|
|
350
|
+
title String
|
|
351
|
+
subtitle String
|
|
352
|
+
link String
|
|
353
|
+
length String
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
class YouTubeHighlightedVideo < YouTubeHighlightedVideoSchema
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Featured channel
|
|
360
|
+
YouTubeFeaturedChannelSchema = DynamicSchema::Struct.define do
|
|
361
|
+
id String
|
|
362
|
+
title String
|
|
363
|
+
subtitle String
|
|
364
|
+
link String
|
|
365
|
+
highlighted_video YouTubeHighlightedVideo, as: :highlighted_video
|
|
366
|
+
videos YouTubeFeaturedVideo, array: true
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
class YouTubeFeaturedChannel < YouTubeFeaturedChannelSchema
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
# Pagination
|
|
373
|
+
YouTubePaginationSchema = DynamicSchema::Struct.define do
|
|
374
|
+
next_page_token String, as: :next_page_token
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
class YouTubePagination < YouTubePaginationSchema
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# Main YouTube search result
|
|
381
|
+
YouTubeSearchResultSchema = DynamicSchema::Struct.define do
|
|
382
|
+
search_metadata YouTubeSearchMetadata, as: :search_metadata
|
|
383
|
+
search_parameters YouTubeSearchParameters, as: :search_parameters
|
|
384
|
+
search_information YouTubeSearchInformation, as: :search_information
|
|
385
|
+
suggestions String, array: true
|
|
386
|
+
ads YouTubeAd, array: true
|
|
387
|
+
channels YouTubeChannel, array: true
|
|
388
|
+
movies YouTubeMovie, array: true
|
|
389
|
+
videos YouTubeVideo, array: true
|
|
390
|
+
playlists YouTubePlaylist, array: true
|
|
391
|
+
sections YouTubeSection, array: true
|
|
392
|
+
shorts YouTubeShorts, array: true
|
|
393
|
+
posts YouTubePosts, array: true
|
|
394
|
+
people_also_search_for YouTubePeopleAlsoSearchFor, array: true, as: :people_also_search_for
|
|
395
|
+
featured_channel YouTubeFeaturedChannel, as: :featured_channel
|
|
396
|
+
pagination YouTubePagination
|
|
397
|
+
error String
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
class YouTubeSearchResult < YouTubeSearchResultSchema
|
|
401
|
+
extend Forwardable
|
|
402
|
+
include Enumerable
|
|
403
|
+
|
|
404
|
+
def_delegators :videos, :each, :[], :count, :size, :length, :first, :last, :empty?
|
|
405
|
+
|
|
406
|
+
def success?
|
|
407
|
+
self.error.nil?
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
end
|
data/lib/searchapi.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'uri'
|
|
3
|
+
|
|
4
|
+
require 'faraday'
|
|
5
|
+
require 'dynamic_schema'
|
|
6
|
+
|
|
7
|
+
require_relative 'searchapi/version'
|
|
8
|
+
|
|
9
|
+
require_relative 'searchapi/helpers'
|
|
10
|
+
require_relative 'searchapi/error_result'
|
|
11
|
+
require_relative 'searchapi/request'
|
|
12
|
+
require_relative 'searchapi/response_methods'
|
|
13
|
+
|
|
14
|
+
require_relative 'searchapi/google_search_options'
|
|
15
|
+
require_relative 'searchapi/google_search_result'
|
|
16
|
+
require_relative 'searchapi/google_search_request'
|
|
17
|
+
|
|
18
|
+
require_relative 'searchapi/youtube_search_options'
|
|
19
|
+
require_relative 'searchapi/youtube_search_result'
|
|
20
|
+
require_relative 'searchapi/youtube_search_request'
|
|
21
|
+
|
|
22
|
+
require_relative 'searchapi/instagram_profile_options'
|
|
23
|
+
require_relative 'searchapi/instagram_profile_result'
|
|
24
|
+
require_relative 'searchapi/instagram_profile_request'
|
|
25
|
+
|
|
26
|
+
require_relative 'searchapi/tiktok_profile_options'
|
|
27
|
+
require_relative 'searchapi/tiktok_profile_result'
|
|
28
|
+
require_relative 'searchapi/tiktok_profile_request'
|
|
29
|
+
|
|
30
|
+
require_relative 'searchapi/google_finance_options'
|
|
31
|
+
require_relative 'searchapi/google_finance_result'
|
|
32
|
+
require_relative 'searchapi/google_finance_request'
|
|
33
|
+
|
|
34
|
+
require_relative 'searchapi/google_flights_options'
|
|
35
|
+
require_relative 'searchapi/google_flights_result'
|
|
36
|
+
require_relative 'searchapi/google_flights_request'
|
|
37
|
+
|
|
38
|
+
require_relative 'searchapi/google_light_options'
|
|
39
|
+
require_relative 'searchapi/google_light_result'
|
|
40
|
+
require_relative 'searchapi/google_light_request'
|
|
41
|
+
|
|
42
|
+
require_relative 'searchapi/google_news_options'
|
|
43
|
+
require_relative 'searchapi/google_news_result'
|
|
44
|
+
require_relative 'searchapi/google_news_request'
|
|
45
|
+
|
|
46
|
+
require_relative 'searchapi/google_news_portal_options'
|
|
47
|
+
require_relative 'searchapi/google_news_portal_result'
|
|
48
|
+
require_relative 'searchapi/google_news_portal_request'
|
|
49
|
+
|
|
50
|
+
require_relative 'searchapi/google_news_light_options'
|
|
51
|
+
require_relative 'searchapi/google_news_light_result'
|
|
52
|
+
require_relative 'searchapi/google_news_light_request'
|
|
53
|
+
|
|
54
|
+
require_relative 'searchapi/google_images_options'
|
|
55
|
+
require_relative 'searchapi/google_images_result'
|
|
56
|
+
require_relative 'searchapi/google_images_request'
|
|
57
|
+
|
|
58
|
+
require_relative 'searchapi/google_local_options'
|
|
59
|
+
require_relative 'searchapi/google_local_result'
|
|
60
|
+
require_relative 'searchapi/google_local_request'
|
|
61
|
+
|
|
62
|
+
require_relative 'searchapi/google_scholar_options'
|
|
63
|
+
require_relative 'searchapi/google_scholar_result'
|
|
64
|
+
require_relative 'searchapi/google_scholar_request'
|
|
65
|
+
|
|
66
|
+
require_relative 'searchapi/module_methods'
|
|
67
|
+
|
|
68
|
+
module SearchAPI
|
|
69
|
+
extend ModuleMethods
|
|
70
|
+
end
|