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,198 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module SearchAPI
|
|
4
|
+
|
|
5
|
+
GoogleLightMetadataSchema = DynamicSchema::Struct.define do
|
|
6
|
+
id String
|
|
7
|
+
status String
|
|
8
|
+
created_at String, as: :created_at
|
|
9
|
+
request_time_taken Float, as: :request_time_taken
|
|
10
|
+
parsing_time_taken Float, as: :parsing_time_taken
|
|
11
|
+
total_time_taken Float, as: :total_time_taken
|
|
12
|
+
request_url String, as: :request_url
|
|
13
|
+
html_url String, as: :html_url
|
|
14
|
+
json_url String, as: :json_url
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class GoogleLightMetadata < GoogleLightMetadataSchema
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
GoogleLightParametersSchema = DynamicSchema::Struct.define do
|
|
21
|
+
engine String
|
|
22
|
+
q String
|
|
23
|
+
location String
|
|
24
|
+
location_used String, as: :location_used
|
|
25
|
+
uule String
|
|
26
|
+
google_domain String, as: :google_domain
|
|
27
|
+
hl String
|
|
28
|
+
gl String
|
|
29
|
+
lr String
|
|
30
|
+
nfpr String
|
|
31
|
+
filter String
|
|
32
|
+
safe String
|
|
33
|
+
page Integer
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class GoogleLightParameters < GoogleLightParametersSchema
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
GoogleLightSearchInformationSchema = DynamicSchema::Struct.define do
|
|
40
|
+
query_displayed String, as: :query_displayed
|
|
41
|
+
page Integer
|
|
42
|
+
detected_location String, as: :detected_location
|
|
43
|
+
did_you_mean String, as: :did_you_mean
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class GoogleLightSearchInformation < GoogleLightSearchInformationSchema
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
GoogleLightAnswerBoxSourceSchema = DynamicSchema::Struct.define do
|
|
50
|
+
title String
|
|
51
|
+
link String
|
|
52
|
+
displayed_link String, as: :displayed_link
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class GoogleLightAnswerBoxSource < GoogleLightAnswerBoxSourceSchema
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
GoogleLightAnswerBoxSchema = DynamicSchema::Struct.define do
|
|
59
|
+
question String
|
|
60
|
+
answer String
|
|
61
|
+
answer_highlight String, as: :answer_highlight
|
|
62
|
+
answer_list String, array: true, as: :answer_list
|
|
63
|
+
source GoogleLightAnswerBoxSource
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class GoogleLightAnswerBox < GoogleLightAnswerBoxSchema
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
GoogleLightKnowledgeGraphSourceSchema = DynamicSchema::Struct.define do
|
|
70
|
+
name String
|
|
71
|
+
link String
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class GoogleLightKnowledgeGraphSource < GoogleLightKnowledgeGraphSourceSchema
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
GoogleLightKnowledgeGraphSchema = DynamicSchema::Struct.define do
|
|
78
|
+
title String
|
|
79
|
+
type String
|
|
80
|
+
rating Float
|
|
81
|
+
reviews Integer
|
|
82
|
+
website String
|
|
83
|
+
directions String
|
|
84
|
+
source GoogleLightKnowledgeGraphSource
|
|
85
|
+
description String
|
|
86
|
+
facts Hash
|
|
87
|
+
thumbnail String
|
|
88
|
+
images String, array: true
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class GoogleLightKnowledgeGraph < GoogleLightKnowledgeGraphSchema
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
GoogleLightSitelinkSchema = DynamicSchema::Struct.define do
|
|
95
|
+
title String
|
|
96
|
+
link String
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class GoogleLightSitelink < GoogleLightSitelinkSchema
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
GoogleLightSitelinksSchema = DynamicSchema::Struct.define do
|
|
103
|
+
inline GoogleLightSitelink, array: true
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class GoogleLightSitelinks < GoogleLightSitelinksSchema
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
GoogleLightOrganicResultSchema = DynamicSchema::Struct.define do
|
|
110
|
+
position Integer
|
|
111
|
+
title String
|
|
112
|
+
link String
|
|
113
|
+
displayed_link String, as: :displayed_link
|
|
114
|
+
snippet String
|
|
115
|
+
date String
|
|
116
|
+
rating Float
|
|
117
|
+
reviews Integer
|
|
118
|
+
sitelinks GoogleLightSitelinks
|
|
119
|
+
extensions String, array: true
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
class GoogleLightOrganicResult < GoogleLightOrganicResultSchema
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
GoogleLightTopStorySchema = DynamicSchema::Struct.define do
|
|
126
|
+
title String
|
|
127
|
+
link String
|
|
128
|
+
source String
|
|
129
|
+
date String
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
class GoogleLightTopStory < GoogleLightTopStorySchema
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
GoogleLightLatestPostSchema = DynamicSchema::Struct.define do
|
|
136
|
+
title String
|
|
137
|
+
link String
|
|
138
|
+
source String
|
|
139
|
+
date String
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
class GoogleLightLatestPost < GoogleLightLatestPostSchema
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
GoogleLightRelatedQuestionSchema = DynamicSchema::Struct.define do
|
|
146
|
+
question String
|
|
147
|
+
answer String
|
|
148
|
+
answer_highlight String, as: :answer_highlight
|
|
149
|
+
answer_list String, array: true, as: :answer_list
|
|
150
|
+
source GoogleLightAnswerBoxSource
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
class GoogleLightRelatedQuestion < GoogleLightRelatedQuestionSchema
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
GoogleLightRelatedSearchSchema = DynamicSchema::Struct.define do
|
|
157
|
+
query String
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
class GoogleLightRelatedSearch < GoogleLightRelatedSearchSchema
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
GoogleLightPaginationSchema = DynamicSchema::Struct.define do
|
|
164
|
+
current Integer
|
|
165
|
+
previous String
|
|
166
|
+
_value :next, type: String
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
class GoogleLightPagination < GoogleLightPaginationSchema
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
GoogleLightResultSchema = DynamicSchema::Struct.define do
|
|
173
|
+
search_metadata GoogleLightMetadata, as: :search_metadata
|
|
174
|
+
search_parameters GoogleLightParameters, as: :search_parameters
|
|
175
|
+
search_information GoogleLightSearchInformation, as: :search_information
|
|
176
|
+
answer_box GoogleLightAnswerBox, as: :answer_box
|
|
177
|
+
knowledge_graph GoogleLightKnowledgeGraph, as: :knowledge_graph
|
|
178
|
+
organic_results GoogleLightOrganicResult, array: true, as: :organic_results
|
|
179
|
+
top_stories GoogleLightTopStory, array: true, as: :top_stories
|
|
180
|
+
latest_posts GoogleLightLatestPost, array: true, as: :latest_posts
|
|
181
|
+
related_questions GoogleLightRelatedQuestion, array: true, as: :related_questions
|
|
182
|
+
related_searches GoogleLightRelatedSearch, array: true, as: :related_searches
|
|
183
|
+
pagination GoogleLightPagination
|
|
184
|
+
error String
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
class GoogleLightResult < GoogleLightResultSchema
|
|
188
|
+
extend Forwardable
|
|
189
|
+
include Enumerable
|
|
190
|
+
|
|
191
|
+
def_delegators :organic_results, :each, :[], :count, :size, :length, :first, :last, :empty?
|
|
192
|
+
|
|
193
|
+
def success?
|
|
194
|
+
self.error.nil?
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class GoogleLocalOptions
|
|
3
|
+
include DynamicSchema::Definable
|
|
4
|
+
include Helpers
|
|
5
|
+
|
|
6
|
+
DEVICES = %w[ desktop mobile tablet ]
|
|
7
|
+
NORMALIZE_DOWNCASE = ->(v) { v.to_s.downcase }
|
|
8
|
+
|
|
9
|
+
schema do
|
|
10
|
+
q String
|
|
11
|
+
device String, in: DEVICES, normalize: NORMALIZE_DOWNCASE
|
|
12
|
+
location String
|
|
13
|
+
uule String
|
|
14
|
+
google_domain String
|
|
15
|
+
gl String
|
|
16
|
+
hl String
|
|
17
|
+
page Integer
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.build( options = nil, &block )
|
|
21
|
+
new( api_options: builder.build( options, &block ) )
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.build!( options = nil, &block )
|
|
25
|
+
new( api_options: builder.build!( options, &block ) )
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def initialize( options = {}, api_options: nil )
|
|
29
|
+
@options = self.class.builder.build( options || {} )
|
|
30
|
+
@options = api_options.merge( @options ) if api_options
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_h
|
|
34
|
+
result = @options.to_h
|
|
35
|
+
result[ :engine ] = 'google_local'
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class GoogleLocalRequest < Request
|
|
3
|
+
|
|
4
|
+
def search( query, options = nil, &block )
|
|
5
|
+
if options
|
|
6
|
+
options = options.is_a?( GoogleLocalOptions ) ? options : GoogleLocalOptions.build!( options.to_h )
|
|
7
|
+
options = options.to_h
|
|
8
|
+
else
|
|
9
|
+
options = { engine: 'google_local' }
|
|
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
|
+
GoogleLocalSearchResult.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,85 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module SearchAPI
|
|
4
|
+
|
|
5
|
+
GoogleLocalSearchMetadataSchema = DynamicSchema::Struct.define do
|
|
6
|
+
id String
|
|
7
|
+
status String
|
|
8
|
+
created_at String, as: :created_at
|
|
9
|
+
request_time_taken Float, as: :request_time_taken
|
|
10
|
+
parsing_time_taken Float, as: :parsing_time_taken
|
|
11
|
+
total_time_taken Float, as: :total_time_taken
|
|
12
|
+
request_url String, as: :request_url
|
|
13
|
+
html_url String, as: :html_url
|
|
14
|
+
json_url String, as: :json_url
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class GoogleLocalSearchMetadata < GoogleLocalSearchMetadataSchema
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
GoogleLocalSearchParametersSchema = DynamicSchema::Struct.define do
|
|
21
|
+
engine String
|
|
22
|
+
q String
|
|
23
|
+
device String
|
|
24
|
+
location String
|
|
25
|
+
location_used String, as: :location_used
|
|
26
|
+
uule String
|
|
27
|
+
google_domain String, as: :google_domain
|
|
28
|
+
gl String
|
|
29
|
+
hl String
|
|
30
|
+
page Integer
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class GoogleLocalSearchParameters < GoogleLocalSearchParametersSchema
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
GoogleLocalSearchExtractedPriceSchema = DynamicSchema::Struct.define do
|
|
37
|
+
min Integer
|
|
38
|
+
max Integer
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class GoogleLocalSearchExtractedPrice < GoogleLocalSearchExtractedPriceSchema
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
GoogleLocalSearchResultItemSchema = DynamicSchema::Struct.define do
|
|
45
|
+
position Integer
|
|
46
|
+
title String
|
|
47
|
+
ludocid String
|
|
48
|
+
rating Float
|
|
49
|
+
reviews Integer
|
|
50
|
+
price String
|
|
51
|
+
extracted_price GoogleLocalSearchExtractedPrice, as: :extracted_price
|
|
52
|
+
comment String
|
|
53
|
+
extensions String, array: true
|
|
54
|
+
image String
|
|
55
|
+
link String
|
|
56
|
+
hotel_class String, as: :hotel_class
|
|
57
|
+
amenities String, array: true
|
|
58
|
+
direction String
|
|
59
|
+
website String
|
|
60
|
+
phone String
|
|
61
|
+
order String
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class GoogleLocalSearchResultItem < GoogleLocalSearchResultItemSchema
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
GoogleLocalSearchResultSchema = DynamicSchema::Struct.define do
|
|
68
|
+
search_metadata GoogleLocalSearchMetadata, as: :search_metadata
|
|
69
|
+
search_parameters GoogleLocalSearchParameters, as: :search_parameters
|
|
70
|
+
local_results GoogleLocalSearchResultItem, array: true, as: :local_results
|
|
71
|
+
error String
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class GoogleLocalSearchResult < GoogleLocalSearchResultSchema
|
|
75
|
+
extend Forwardable
|
|
76
|
+
include Enumerable
|
|
77
|
+
|
|
78
|
+
def_delegators :local_results, :each, :[], :count, :size, :length, :first, :last, :empty?
|
|
79
|
+
|
|
80
|
+
def success?
|
|
81
|
+
self.error.nil?
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class GoogleNewsLightOptions
|
|
3
|
+
include DynamicSchema::Definable
|
|
4
|
+
include Helpers
|
|
5
|
+
|
|
6
|
+
TIME_PERIODS = %w[ last_hour last_day last_week last_month last_year ]
|
|
7
|
+
SORT_BY = %w[ most_recent ]
|
|
8
|
+
SAFE_SEARCH = %w[ active off ]
|
|
9
|
+
|
|
10
|
+
NORMALIZE_DOWNCASE = ->(v) { v.to_s.downcase }
|
|
11
|
+
|
|
12
|
+
schema do
|
|
13
|
+
q String
|
|
14
|
+
location String
|
|
15
|
+
uule String
|
|
16
|
+
google_domain String, as: :google_domain
|
|
17
|
+
gl String
|
|
18
|
+
hl String
|
|
19
|
+
time_period String, in: TIME_PERIODS, as: :time_period, normalize: NORMALIZE_DOWNCASE
|
|
20
|
+
sort_by String, in: SORT_BY, as: :sort_by, normalize: NORMALIZE_DOWNCASE
|
|
21
|
+
nfpr Integer
|
|
22
|
+
filter Integer
|
|
23
|
+
safe String, in: SAFE_SEARCH, normalize: NORMALIZE_DOWNCASE
|
|
24
|
+
page Integer
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.build( options = nil, &block )
|
|
28
|
+
new( api_options: builder.build( options, &block ) )
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.build!( options = nil, &block )
|
|
32
|
+
new( api_options: builder.build!( options, &block ) )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def initialize( options = {}, api_options: nil )
|
|
36
|
+
@options = self.class.builder.build( options || {} )
|
|
37
|
+
@options = api_options.merge( @options ) if api_options
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_h
|
|
41
|
+
result = @options.to_h
|
|
42
|
+
result[ :engine ] = 'google_news_light'
|
|
43
|
+
result
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class GoogleNewsLightRequest < Request
|
|
3
|
+
|
|
4
|
+
def search( query, options = nil, &block )
|
|
5
|
+
if options
|
|
6
|
+
options = options.is_a?( GoogleNewsLightOptions ) ? options : GoogleNewsLightOptions.build!( options.to_h )
|
|
7
|
+
options = options.to_h
|
|
8
|
+
else
|
|
9
|
+
options = { engine: 'google_news_light' }
|
|
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
|
+
GoogleNewsLightResult.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,94 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module SearchAPI
|
|
4
|
+
|
|
5
|
+
GoogleNewsLightMetadataSchema = DynamicSchema::Struct.define do
|
|
6
|
+
id String
|
|
7
|
+
status String
|
|
8
|
+
created_at String, as: :created_at
|
|
9
|
+
request_time_taken Float, as: :request_time_taken
|
|
10
|
+
parsing_time_taken Float, as: :parsing_time_taken
|
|
11
|
+
total_time_taken Float, as: :total_time_taken
|
|
12
|
+
request_url String, as: :request_url
|
|
13
|
+
html_url String, as: :html_url
|
|
14
|
+
json_url String, as: :json_url
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class GoogleNewsLightMetadata < GoogleNewsLightMetadataSchema
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
GoogleNewsLightParametersSchema = DynamicSchema::Struct.define do
|
|
21
|
+
engine String
|
|
22
|
+
q String
|
|
23
|
+
location String
|
|
24
|
+
location_used String, as: :location_used
|
|
25
|
+
uule String
|
|
26
|
+
google_domain String, as: :google_domain
|
|
27
|
+
gl String
|
|
28
|
+
hl String
|
|
29
|
+
time_period String, as: :time_period
|
|
30
|
+
sort_by String, as: :sort_by
|
|
31
|
+
nfpr Integer
|
|
32
|
+
filter Integer
|
|
33
|
+
safe String
|
|
34
|
+
page Integer
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class GoogleNewsLightParameters < GoogleNewsLightParametersSchema
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
GoogleNewsLightSearchInformationSchema = DynamicSchema::Struct.define do
|
|
41
|
+
query_displayed String, as: :query_displayed
|
|
42
|
+
total_results Integer, as: :total_results
|
|
43
|
+
page Integer
|
|
44
|
+
time_taken_displayed Float, as: :time_taken_displayed
|
|
45
|
+
detected_location String, as: :detected_location
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class GoogleNewsLightSearchInformation < GoogleNewsLightSearchInformationSchema
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
GoogleNewsLightArticleSchema = DynamicSchema::Struct.define do
|
|
52
|
+
position Integer
|
|
53
|
+
title String
|
|
54
|
+
link String
|
|
55
|
+
source String
|
|
56
|
+
date String
|
|
57
|
+
snippet String
|
|
58
|
+
thumbnail String
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class GoogleNewsLightArticle < GoogleNewsLightArticleSchema
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
GoogleNewsLightTopStorySchema = DynamicSchema::Struct.define do
|
|
65
|
+
title String
|
|
66
|
+
link String
|
|
67
|
+
source String
|
|
68
|
+
date String
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class GoogleNewsLightTopStory < GoogleNewsLightTopStorySchema
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
GoogleNewsLightResultSchema = DynamicSchema::Struct.define do
|
|
75
|
+
search_metadata GoogleNewsLightMetadata, as: :search_metadata
|
|
76
|
+
search_parameters GoogleNewsLightParameters, as: :search_parameters
|
|
77
|
+
search_information GoogleNewsLightSearchInformation, as: :search_information
|
|
78
|
+
organic_results GoogleNewsLightArticle, array: true, as: :organic_results
|
|
79
|
+
top_stories GoogleNewsLightTopStory, array: true, as: :top_stories
|
|
80
|
+
error String
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class GoogleNewsLightResult < GoogleNewsLightResultSchema
|
|
84
|
+
extend Forwardable
|
|
85
|
+
include Enumerable
|
|
86
|
+
|
|
87
|
+
def_delegators :organic_results, :each, :[], :count, :size, :length, :first, :last, :empty?
|
|
88
|
+
|
|
89
|
+
def success?
|
|
90
|
+
self.error.nil?
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class GoogleNewsOptions
|
|
3
|
+
include DynamicSchema::Definable
|
|
4
|
+
include Helpers
|
|
5
|
+
|
|
6
|
+
DEVICES = %w[ desktop mobile tablet ]
|
|
7
|
+
SAFE_SEARCH = %w[ active off ]
|
|
8
|
+
TIME_PERIODS = %w[ last_hour last_day last_week last_month last_year ]
|
|
9
|
+
SORT_BY = %w[ most_recent ]
|
|
10
|
+
|
|
11
|
+
NORMALIZE_DOWNCASE = ->(v) { v.to_s.downcase }
|
|
12
|
+
|
|
13
|
+
schema do
|
|
14
|
+
q String
|
|
15
|
+
device String, in: DEVICES, normalize: NORMALIZE_DOWNCASE
|
|
16
|
+
location String
|
|
17
|
+
uule String
|
|
18
|
+
google_domain String
|
|
19
|
+
hl String
|
|
20
|
+
gl String
|
|
21
|
+
lr String
|
|
22
|
+
cr String
|
|
23
|
+
nfpr String
|
|
24
|
+
filter String
|
|
25
|
+
safe String, in: SAFE_SEARCH, normalize: NORMALIZE_DOWNCASE
|
|
26
|
+
page Integer
|
|
27
|
+
time_period String, in: TIME_PERIODS, normalize: NORMALIZE_DOWNCASE
|
|
28
|
+
time_period_min String
|
|
29
|
+
time_period_max String
|
|
30
|
+
sort_by String, in: SORT_BY, normalize: NORMALIZE_DOWNCASE
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.build( options = nil, &block )
|
|
34
|
+
new( api_options: builder.build( options, &block ) )
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.build!( options = nil, &block )
|
|
38
|
+
new( api_options: builder.build!( options, &block ) )
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def initialize( options = {}, api_options: nil )
|
|
42
|
+
@options = self.class.builder.build( options || {} )
|
|
43
|
+
@options = api_options.merge( @options ) if api_options
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_h
|
|
47
|
+
result = @options.to_h
|
|
48
|
+
result[ :engine ] = 'google_news'
|
|
49
|
+
result
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module SearchAPI
|
|
2
|
+
class GoogleNewsPortalOptions
|
|
3
|
+
include DynamicSchema::Definable
|
|
4
|
+
include Helpers
|
|
5
|
+
|
|
6
|
+
SORT_BY = %w[ relevance date ]
|
|
7
|
+
|
|
8
|
+
NORMALIZE_DOWNCASE = ->(v) { v.to_s.downcase }
|
|
9
|
+
|
|
10
|
+
schema do
|
|
11
|
+
q String
|
|
12
|
+
ceid String
|
|
13
|
+
story_token String, as: :story_token
|
|
14
|
+
topic_token String, as: :topic_token
|
|
15
|
+
publication_token String, as: :publication_token
|
|
16
|
+
section_token String, as: :section_token
|
|
17
|
+
sort_by String, in: SORT_BY, as: :sort_by, normalize: NORMALIZE_DOWNCASE
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.build( options = nil, &block )
|
|
21
|
+
new( api_options: builder.build( options, &block ) )
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.build!( options = nil, &block )
|
|
25
|
+
new( api_options: builder.build!( options, &block ) )
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def initialize( options = {}, api_options: nil )
|
|
29
|
+
@options = self.class.builder.build( options || {} )
|
|
30
|
+
@options = api_options.merge( @options ) if api_options
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_h
|
|
34
|
+
result = @options.to_h
|
|
35
|
+
result[ :engine ] = 'google_news_portal'
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|