google_search_results 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/google_search_results.rb +15 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0899a32cef6abed47a9b920b7ec17ebda201ab81'
4
- data.tar.gz: 7bd94626b964705d2075c4fe7642c966bbfd68c3
3
+ metadata.gz: feaca1e28d95b0808fb48c4071621544d402c032
4
+ data.tar.gz: 8bbe22d3aea6b7824a1b9a46a806d3ff5a80f45c
5
5
  SHA512:
6
- metadata.gz: 90a1a22f6a293af5374a129d4c2895e58c4eb5c2b04e1589a270d5ab1aac8dcc5253ac33c372e58dea0af70d0a4ce91cdd0a2afbc0204b536b089726f681eceb
7
- data.tar.gz: 7783e0c512887a162ed174cc4b846fedfe4d2d97f46ce6e742b3c3069b36377e810e99cd2824cea796b9a5313203ed525f68e3ebe03e0f148ec875e88c9848a2
6
+ metadata.gz: 45b4eac6e1e4c1ad097bb0f65cb98c70c61a780580eea320a75d410ec51679806da38d7300c8948bf993da818733d79cd07ac73be35a5385e8ec78abe4362903
7
+ data.tar.gz: e443121731de866c2db6404fe6633a595df0e40a181b3522bd7a5c7ac8258722dd975a991e5629e7035a2b3e306119269ca3af6aa6e0c7a6317d7b2ea6f37116
@@ -6,7 +6,7 @@ require_relative 'google_search_results/hash'
6
6
 
7
7
  class GoogleSearchResults
8
8
 
9
- VERSION = "0.1.0"
9
+ VERSION = "0.2.0"
10
10
  BACKEND = "serpapi.com"
11
11
 
12
12
  @@serp_api_key = nil
@@ -29,14 +29,26 @@ class GoogleSearchResults
29
29
  URI::HTTPS.build(host: BACKEND, path: '/search', query: URI.encode_www_form(@params))
30
30
  end
31
31
 
32
+ def get_results
33
+ begin
34
+ open(construct_url).read
35
+ rescue OpenURI::HTTPError => e
36
+ if error = JSON.load(e.io.read)["error"]
37
+ raise error
38
+ else
39
+ raise e
40
+ end
41
+ end
42
+ end
43
+
32
44
  def get_html
33
45
  @params[:output] = "html"
34
- open(construct_url).read
46
+ get_results
35
47
  end
36
48
 
37
49
  def get_json
38
50
  @params[:output] = "json"
39
- open(construct_url).read
51
+ get_results
40
52
  end
41
53
 
42
54
  def get_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_search_results
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hartator