google_search_results 1.3.2 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cf8b604485ff927dae81c9fd1a5017d92563b339bc77994e0365926a14f6192
4
- data.tar.gz: 46cca48662a2bfe6d7b7c79e34b92afa931d3be9e8cf38eb139d6d086068d2c7
3
+ metadata.gz: f00191ba840fc5fdcde18b6e46293dca43ddd5cff4fa4896d72efc65544d92d2
4
+ data.tar.gz: 23c60e7e337ccc23fe9d4f7b3b5d1cb9257b877490042c79eccfaaa46ba51ac3
5
5
  SHA512:
6
- metadata.gz: 6d26a044da90201b3c7e77841e7acc5bce8f0534ad7840df78b42120a7549ca79a3b787af90ad25e1062713b47a0fe7ab32b000a9ada008f27a64421ae97370c
7
- data.tar.gz: 5257a57981176ee85df134f6bc89e1eebf2b16e44d0d3c90ee72a63541359b83e9ac8a69639c41c87d9f8a2eeb6571360bd223bd87b8474f90c3aa0a53b4796d
6
+ metadata.gz: 327808805373bc9aa99c38c1255e031b728b6c59737b6bed6332a70efa9d2a534787621ba162d176204c14e49521f45c1950b95db0098f80be48150b0a2fab43
7
+ data.tar.gz: 6f55bb911ae9c9620e5cb41de6d0ed36a13c82c883202af8228817be6500eab2dee3678b83bee0cca3ce648052604c3b9cbd48bc825194e53d31d2dcc06a17b5
@@ -1,39 +1,13 @@
1
- require_relative 'serp_api_client'
2
-
3
- # Google Search Result for Ruby powered by SerpApi
4
- #
5
- # Search API Usage
6
- #
7
- # ```ruby
8
- # parameter = {
9
- # q: "query",
10
- # google_domain: "Google Domain",
11
- # location: "Location Requested",
12
- # device: device,
13
- # hl: "Google UI Language",
14
- # gl: "Google Country",
15
- # safe: "Safe Search Flag",
16
- # num: "Number of Results",
17
- # start: "Pagination Offset",
18
- # tbm: "to be matched field",
19
- # tbs: "to be searched field",
20
- # api_key: "Your SERP API Key"
21
- # }
22
- #
23
- # search = GoogleSearchResults.new(parameter)
24
- # search.params[:location] = "Portland"
25
- #
26
- # html_results = search.get_html
27
- # hash_results = search.get_hash
28
- # json_results = search.get_json
29
- # ```
30
- #
31
- # doc: https://serpapi.com/search-api
32
- class GoogleSearchResults < SerpApiClient
33
-
34
- def initialize(params = {})
35
- super(params, GOOGLE_ENGINE)
36
- check_params([:q, :engine])
37
- end
38
-
39
- end
1
+ require_relative 'search/serp_api_search.rb'
2
+ require_relative 'search/baidu_search.rb'
3
+ require_relative 'search/bing_search.rb'
4
+ require_relative 'search/ebay_search.rb'
5
+ require_relative 'search/google_search.rb'
6
+ require_relative 'search/yahoo_search.rb'
7
+ require_relative 'search/yandex_search.rb'
8
+ require_relative 'search/youtube_search.rb'
9
+ require_relative 'search/walmart_search.rb'
10
+ require_relative 'search/duckduckgo_search.rb'
11
+ require_relative 'search/homedepot_search.rb'
12
+ require_relative 'search/apple_store_search.rb'
13
+ require_relative 'search/naver_search.rb'
@@ -0,0 +1,34 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Apple Store Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # term: "laptop",
10
+ # api_key: "Your SERP API Key"
11
+ # }
12
+ #
13
+ # search = AppleStoreSearch.new(parameter)
14
+ #
15
+ # html_results = search.get_html
16
+ # hash_results = search.get_hash
17
+ # json_results = search.get_json
18
+ #
19
+ # ```
20
+ #
21
+ # doc: https://serpapi.com/bing-search-api
22
+
23
+ class AppleStoreSearch < SerpApiSearch
24
+
25
+ def initialize(params = {})
26
+ super(params, APPLE_STORE_ENGINE)
27
+ check_params([:term, :engine])
28
+ end
29
+
30
+ def get_location
31
+ raise SerpApiException.new('location is not supported by ' + APPLE_STORE_ENGINE)
32
+ end
33
+
34
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'serp_api_client'
1
+ require_relative 'serp_api_search'
2
2
 
3
3
  # Baidu Search Result for Ruby powered by SerpApi
4
4
  #
@@ -10,7 +10,7 @@ require_relative 'serp_api_client'
10
10
  # api_key: "Serp API Key"
11
11
  # }
12
12
  #
13
- # search = BaiduSearchResults.new(parameter)
13
+ # search = BaiduSearch.new(parameter)
14
14
  #
15
15
  # html_results = search.get_html
16
16
  # hash_results = search.get_hash
@@ -19,15 +19,15 @@ require_relative 'serp_api_client'
19
19
  # ```
20
20
  # doc: https://serpapi.com/baidu-search-api
21
21
 
22
- class BaiduSearchResults < SerpApiClient
22
+ class BaiduSearch < SerpApiSearch
23
23
 
24
24
  def initialize(params = {})
25
- super(params, BING_ENGINE)
25
+ super(params, BAIDU_ENGINE)
26
26
  check_params([:q, :engine])
27
27
  end
28
28
 
29
29
  def get_location
30
- raise 'location is not supported by Baidu'
30
+ raise SerpApiException.new('location is not supported by Baidu')
31
31
  end
32
32
 
33
33
  end
@@ -1,4 +1,4 @@
1
- require_relative '../lib/bing_search_results'
1
+ require_relative 'serp_api_search'
2
2
 
3
3
  # Bing Search Result for Ruby powered by SerpApi
4
4
  #
@@ -11,7 +11,7 @@ require_relative '../lib/bing_search_results'
11
11
  # api_key: "Your SERP API Key"
12
12
  # }
13
13
  #
14
- # search = BingSearchResults.new(parameter)
14
+ # search = BingSearch.new(parameter)
15
15
  # search.params[:location] = "Portland"
16
16
  #
17
17
  # html_results = search.get_html
@@ -22,7 +22,7 @@ require_relative '../lib/bing_search_results'
22
22
  #
23
23
  # doc: https://serpapi.com/bing-search-api
24
24
 
25
- class BingSearchResults < SerpApiClient
25
+ class BingSearch < SerpApiSearch
26
26
 
27
27
  def initialize(params = {})
28
28
  super(params, BING_ENGINE)
@@ -0,0 +1,29 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Duckduckgo Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # search_query: "query",
10
+ # api_key: "Serp API Key"
11
+ # }
12
+ #
13
+ # search = DuckduckgoSearch.new(parameter)
14
+ #
15
+ # html_results = search.get_html
16
+ # hash_results = search.get_hash
17
+ # json_results = search.get_json
18
+ #
19
+ # ```
20
+ # doc: https://serpapi.com/Duckduckgo-search-api
21
+
22
+ class DuckduckgoSearch < SerpApiSearch
23
+
24
+ def initialize(params = {})
25
+ super(params, DUCKDUCKGO_ENGINE)
26
+ check_params([:q, :engine])
27
+ end
28
+
29
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'serp_api_client'
1
+ require_relative 'serp_api_search'
2
2
 
3
3
  # Ebay Search Result for Ruby powered by SerpApi
4
4
  #
@@ -10,7 +10,7 @@ require_relative 'serp_api_client'
10
10
  # api_key: "Your SERP API Key"
11
11
  # }
12
12
  #
13
- # search = EbaySearchResults.new(parameter)
13
+ # search = EbaySearch.new(parameter)
14
14
  # search.params[:ebay_domain] = "ebay.com"
15
15
  #
16
16
  # html_results = search.get_html
@@ -21,7 +21,7 @@ require_relative 'serp_api_client'
21
21
  #
22
22
  # doc: https://serpapi.com/ebay-search-api
23
23
 
24
- class EbaySearchResults < SerpApiClient
24
+ class EbaySearch < SerpApiSearch
25
25
 
26
26
  def initialize(params = {})
27
27
  super(params, EBAY_ENGINE)
@@ -29,7 +29,7 @@ class EbaySearchResults < SerpApiClient
29
29
  end
30
30
 
31
31
  def get_location
32
- raise 'location is not supported by ' + EBAY_ENGINE
32
+ raise SerpApiException.new('location is not supported by ' + EBAY_ENGINE)
33
33
  end
34
34
 
35
35
  end
@@ -0,0 +1,39 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Google Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # q: "query",
10
+ # google_domain: "Google Domain",
11
+ # location: "Location Requested",
12
+ # device: device,
13
+ # hl: "Google UI Language",
14
+ # gl: "Google Country",
15
+ # safe: "Safe Search Flag",
16
+ # num: "Number of Results",
17
+ # start: "Pagination Offset",
18
+ # tbm: "to be matched field",
19
+ # tbs: "to be searched field",
20
+ # api_key: "Your SERP API Key"
21
+ # }
22
+ #
23
+ # search = GoogleSearch.new(parameter)
24
+ # search.params[:location] = "Portland"
25
+ #
26
+ # html_results = search.get_html
27
+ # hash_results = search.get_hash
28
+ # json_results = search.get_json
29
+ # ```
30
+ #
31
+ # doc: https://serpapi.com/search-api
32
+ class GoogleSearch < SerpApiSearch
33
+
34
+ def initialize(params = {})
35
+ super(params, GOOGLE_ENGINE)
36
+ check_params([:q, :engine])
37
+ end
38
+
39
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Homedepot Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # search_query: "query",
10
+ # api_key: "Serp API Key"
11
+ # }
12
+ #
13
+ # search = HomedepotSearch.new(parameter)
14
+ #
15
+ # html_results = search.get_html
16
+ # hash_results = search.get_hash
17
+ # json_results = search.get_json
18
+ #
19
+ # ```
20
+ # doc: https://serpapi.com/Homedepot-search-api
21
+
22
+ class HomedepotSearch < SerpApiSearch
23
+
24
+ def initialize(params = {})
25
+ super(params, HOMEDEPOT_ENGINE)
26
+ check_params([:q, :engine])
27
+ end
28
+
29
+ def get_location
30
+ raise SerpApiException.new('location is not supported by Homedepot')
31
+ end
32
+
33
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Naver Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # q: "query",
10
+ # location: "city,state,country",
11
+ # api_key: "Your SERP API Key"
12
+ # }
13
+ #
14
+ # search = NaverSearch.new(parameter)
15
+ # search.params[:location] = "Portland"
16
+ #
17
+ # html_results = search.get_html
18
+ # hash_results = search.get_hash
19
+ # json_results = search.get_json
20
+ #
21
+ # ```
22
+ #
23
+ # doc: https://serpapi.com/bing-search-api
24
+
25
+ class NaverSearch < SerpApiSearch
26
+
27
+ def initialize(params = {})
28
+ super(params, NAVER_ENGINE)
29
+ check_params([:query, :engine])
30
+ end
31
+
32
+ def get_location
33
+ raise SerpApiException.new('location is not supported by ' + NAVER_ENGINE)
34
+ end
35
+
36
+ end
@@ -7,13 +7,18 @@ BING_ENGINE = 'bing'
7
7
  YAHOO_ENGINE = 'yahoo'
8
8
  YANDEX_ENGINE = 'yandex'
9
9
  EBAY_ENGINE = 'ebay'
10
-
10
+ YOUTUBE_ENGINE = 'youtube'
11
+ DUCKDUCKGO_ENGINE = 'duckduckgo'
12
+ WALMART_ENGINE = 'walmart'
13
+ HOMEDEPOT_ENGINE = 'home_depot'
14
+ APPLE_STORE_ENGINE = 'apple_app_store'
15
+ NAVER_ENGINE = 'naver'
11
16
 
12
17
  # Generic HTTP client for serpapi.com
13
18
  #
14
- class SerpApiClient
19
+ class SerpApiSearch
15
20
 
16
- VERSION = "1.3.2"
21
+ VERSION = "2.2.0"
17
22
  BACKEND = "serpapi.com"
18
23
 
19
24
  attr_accessor :params
@@ -24,8 +29,8 @@ class SerpApiClient
24
29
  # ---
25
30
  #
26
31
  # ```ruby
27
- # require 'google_search_results'
28
- # search = SerpApiClient.new({q: "coffee", api_key: "secure API key", engine: "google"})
32
+ # require 'google_search'
33
+ # search = SerpApiSearch.new({q: "coffee", api_key: "secure API key", engine: "google"})
29
34
  # result = search.get_json
30
35
  # ```
31
36
  #
@@ -34,7 +39,7 @@ class SerpApiClient
34
39
  def initialize(params, engine = nil)
35
40
  @params = params
36
41
  @params[:engine] ||= engine
37
- raise 'engine must be defined in params or a second argument' if @params[:engine].nil?
42
+ raise SerpApiException.new('engine must be defined in params or a second argument') if @params[:engine].nil?
38
43
  end
39
44
 
40
45
  # get_json
@@ -78,7 +83,7 @@ class SerpApiClient
78
83
 
79
84
  # Retrieve search result from the Search Archive API
80
85
  def get_search_archive(search_id, format = 'json')
81
- raise 'format must be json or html' if format !~ /^(html|json)$/
86
+ raise SerpApiException.new('format must be json or html') if format !~ /^(html|json)$/
82
87
  as_json(get_results("/searches/#{search_id}.#{format}"))
83
88
  end
84
89
 
@@ -131,7 +136,7 @@ class SerpApiClient
131
136
  def get_results(path)
132
137
  begin
133
138
  url = construct_url(path)
134
- URI::open(url, read_timeout: 600).read
139
+ URI(url).open(read_timeout: 600).read
135
140
  rescue OpenURI::HTTPError => e
136
141
  if error = JSON.load(e.io.read)["error"]
137
142
  puts "server returns error for url: #{url}"
@@ -149,7 +154,7 @@ class SerpApiClient
149
154
  def check_params(keys = [])
150
155
  return if @params.keys == [:engine]
151
156
 
152
- raise 'keys must be a list of String or Symbol' unless keys.class == Array
157
+ raise SerpApiException.new('keys must be a list of String or Symbol') unless keys.class == Array
153
158
  missing = []
154
159
  keys.each do |key|
155
160
  case key.class.to_s
@@ -166,13 +171,19 @@ class SerpApiClient
166
171
  end
167
172
  end
168
173
  else
169
- raise 'keys must contains Symbol or String'
174
+ raise SerpApiException.new('keys must contains Symbol or String')
170
175
  end
171
176
  end
172
177
  if !missing.empty?
173
- raise "missing required keys in params.\n #{missing.join(',')}"
178
+ raise SerpApiException.new("missing required keys in params: \n - #{missing.join("\n -")}")
174
179
  end
175
180
  end
176
181
 
177
182
  end
178
183
 
184
+ # Standard SerpApiException for anything related to the client
185
+ class SerpApiException < StandardError
186
+ def initialize(message)
187
+ super(message)
188
+ end
189
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Walmart Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # query: "search keywords",
10
+ # api_key: "Serp API Key"
11
+ # }
12
+ #
13
+ # search = WalmartSearch.new(parameter)
14
+ #
15
+ # html_results = search.get_html
16
+ # hash_results = search.get_hash
17
+ # json_results = search.get_json
18
+ #
19
+ # ```
20
+ # doc: https://serpapi.com/youtube-search-api
21
+
22
+ class WalmartSearch < SerpApiSearch
23
+
24
+ def initialize(params = {})
25
+ super(params, WALMART_ENGINE)
26
+ check_params([:query, :engine])
27
+ end
28
+
29
+ def get_location
30
+ raise SerpApiException.new('location is not supported by Walmart')
31
+ end
32
+
33
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'serp_api_client'
1
+ require_relative 'serp_api_search'
2
2
 
3
3
  # Yahoo Search Result for Ruby powered by SerpApi
4
4
  #
@@ -10,7 +10,7 @@ require_relative 'serp_api_client'
10
10
  # api_key: "Your SERP API Key"
11
11
  # }
12
12
  #
13
- # search = YahooSearchResults.new(parameter)
13
+ # search = YahooSearch.new(parameter)
14
14
  # search.params[:yahoo_domain] = "fr"
15
15
  #
16
16
  # html_results = search.get_html
@@ -21,7 +21,7 @@ require_relative 'serp_api_client'
21
21
  #
22
22
  # doc: https://serpapi.com/yahoo-search-api
23
23
 
24
- class YahooSearchResults < SerpApiClient
24
+ class YahooSearch < SerpApiSearch
25
25
 
26
26
  def initialize(params = {})
27
27
  super(params, YAHOO_ENGINE)
@@ -29,7 +29,7 @@ class YahooSearchResults < SerpApiClient
29
29
  end
30
30
 
31
31
  def get_location
32
- raise 'location is not supported by ' + YAHOO_ENGINE
32
+ raise SerpApiException.new('location is not supported by ' + YAHOO_ENGINE)
33
33
  end
34
34
 
35
35
  end
@@ -1,4 +1,4 @@
1
- require_relative 'serp_api_client'
1
+ require_relative 'serp_api_search'
2
2
 
3
3
  # Yandex Search Result for Ruby powered by SerpApi
4
4
  #
@@ -10,7 +10,7 @@ require_relative 'serp_api_client'
10
10
  # api_key: "Your SERP API Key"
11
11
  # }
12
12
  #
13
- # search = YandexSearchResults.new(parameter)
13
+ # search = YandexSearch.new(parameter)
14
14
  # search.params[:yandex_domain] = "yandex.com"
15
15
  #
16
16
  # html_results = search.get_html
@@ -21,7 +21,7 @@ require_relative 'serp_api_client'
21
21
  #
22
22
  # doc: https://serpapi.com/yandex-search-api
23
23
 
24
- class YandexSearchResults < SerpApiClient
24
+ class YandexSearch < SerpApiSearch
25
25
 
26
26
  def initialize(params = {})
27
27
  super(params, YANDEX_ENGINE)
@@ -29,7 +29,7 @@ class YandexSearchResults < SerpApiClient
29
29
  end
30
30
 
31
31
  def get_location
32
- raise 'location is not supported by ' + YAHOO_ENGINE
32
+ raise SerpApiException.new('location is not supported by ' + YAHOO_ENGINE)
33
33
  end
34
34
 
35
35
  end
@@ -0,0 +1,29 @@
1
+ require_relative 'serp_api_search'
2
+
3
+ # Youtube Search Result for Ruby powered by SerpApi
4
+ #
5
+ # Search API Usage
6
+ #
7
+ # ```ruby
8
+ # parameter = {
9
+ # search_query: "query",
10
+ # api_key: "Serp API Key"
11
+ # }
12
+ #
13
+ # search = YoutubeSearch.new(parameter)
14
+ #
15
+ # html_results = search.get_html
16
+ # hash_results = search.get_hash
17
+ # json_results = search.get_json
18
+ #
19
+ # ```
20
+ # doc: https://serpapi.com/youtube-search-api
21
+
22
+ class YoutubeSearch < SerpApiSearch
23
+
24
+ def initialize(params = {})
25
+ super(params, YOUTUBE_ENGINE)
26
+ check_params([:search_query, :engine])
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_search_results
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hartator
8
8
  - jvmvik
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-05 00:00:00.000000000 Z
12
+ date: 2021-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -74,19 +74,26 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - lib/baidu_search_results.rb
78
- - lib/bing_search_results.rb
79
- - lib/ebay_search_results.rb
80
77
  - lib/google_search_results.rb
81
- - lib/serp_api_client.rb
82
- - lib/yahoo_search_results.rb
83
- - lib/yandex_search_results.rb
78
+ - lib/search/apple_store_search.rb
79
+ - lib/search/baidu_search.rb
80
+ - lib/search/bing_search.rb
81
+ - lib/search/duckduckgo_search.rb
82
+ - lib/search/ebay_search.rb
83
+ - lib/search/google_search.rb
84
+ - lib/search/homedepot_search.rb
85
+ - lib/search/naver_search.rb
86
+ - lib/search/serp_api_search.rb
87
+ - lib/search/walmart_search.rb
88
+ - lib/search/yahoo_search.rb
89
+ - lib/search/yandex_search.rb
90
+ - lib/search/youtube_search.rb
84
91
  homepage: https://github.com/serpapi/google-search-results-ruby
85
92
  licenses:
86
93
  - MIT
87
94
  metadata:
88
95
  yard.run: yri
89
- post_install_message:
96
+ post_install_message:
90
97
  rdoc_options: []
91
98
  require_paths:
92
99
  - lib
@@ -101,8 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
108
  - !ruby/object:Gem::Version
102
109
  version: '0'
103
110
  requirements: []
104
- rubygems_version: 3.1.2
105
- signing_key:
111
+ rubygems_version: 3.2.22
112
+ signing_key:
106
113
  specification_version: 4
107
- summary: Get Google, Bing, Baidu, Ebay, Yahoo, Yandex Search Results via SerpApi.com
114
+ summary: Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo,
115
+ Youtube search results via SerpApi.com
108
116
  test_files: []