ruboty-google_image 0.0.7 → 0.1.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
  SHA1:
3
- metadata.gz: d23e3c4fb1c91fe1f350fd7544d74dbc2dc082e7
4
- data.tar.gz: 0b86bdcb140fc868bfa89ee1f7746279c87ce671
3
+ metadata.gz: ed6973ac9a39495dfebcb57abedb2018ce870085
4
+ data.tar.gz: f3ffea6d9ed22d16b76b5e6ebb5f8e273d253834
5
5
  SHA512:
6
- metadata.gz: 1f1f76a80bbf015f73272e665559150dbbf04c537f529011b1df553eca6bbca46c4d401a8421ff9ea68cad8ba6488408cd78a1b7a2feea8b584f322773869d71
7
- data.tar.gz: 172f6f41c31edb1767560d0c1e2b210bd9a3cc2238d080ebefc0430d38845f0d9e51502174000958d73225f241c1dfef79f32d7a8bc97c2bb1e010e962aa1feb
6
+ metadata.gz: 21057cc67f83cf3a28f21c3a824f1a7c283e3848c4d3bce07e604d6af65341aac4625099bed6ebf4b1508bb5ddefecc60eff8fe578fb076102fbcf65ad01bedc
7
+ data.tar.gz: 3fc5384f046a5ec08b98232b2aa21c435de3f9267264f9a90dc78c8a17006d427a2db70ec92ca0c86c04684356b2be8073eb40988019014449a71a2cc1a21d49
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.0
2
+ * Use Google Custom Search API instead of Google Image Search API
3
+
1
4
  ## 0.0.7
2
5
  * Rename: Ellen -> Ruboty
3
6
 
data/README.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # Ruboty::GoogleImage
2
2
  An ruboty handler to search images from Google.
3
3
 
4
+ ## Install
5
+
6
+ This gem needs two environment variables.
7
+
8
+ - GOOGLE_CSE_ID
9
+ - GOOGLE_CSE_KEY
10
+
11
+ ### CSE setup
12
+
13
+ 1. Create a CSE via these [instructions](https://developers.google.com/custom-search/docs/tutorial/creatingcse).
14
+ 1. Turn on images in Edit Search Engine > Setup > Basic > Image Search
15
+ 1. Get the CSE ID in Edit Search Engine > Setup > Basic > Details (via [these instructions](https://support.google.com/customsearch/answer/2649143?hl=en))
16
+ 1. Get the CSE KEY [here](https://code.google.com/apis/console)
17
+ 1. Update your env
18
+
4
19
  ## Usage
5
20
  ```
6
21
  @ruboty image <keyword> - Search image from Google
@@ -4,7 +4,7 @@ require "faraday_middleware"
4
4
  module Ruboty
5
5
  module GoogleImage
6
6
  class Client
7
- GOOGLE_IMAGE_API_URL = "http://ajax.googleapis.com/ajax/services/search/images"
7
+ GOOGLE_IMAGE_API_URL = "https://www.googleapis.com/customsearch/v1"
8
8
 
9
9
  attr_reader :options
10
10
 
@@ -13,7 +13,7 @@ module Ruboty
13
13
  end
14
14
 
15
15
  def get
16
- resource["unescapedUrl"] if resource
16
+ resource["link"] if resource
17
17
  rescue => exception
18
18
  Ruboty.logger.error("Error: #{self}##{__method__} - #{exception}")
19
19
  nil
@@ -23,10 +23,8 @@ module Ruboty
23
23
 
24
24
  def resource
25
25
  @resource ||= begin
26
- if data = response.body["responseData"]
27
- if results = data["results"]
28
- results.sample
29
- end
26
+ if items = response.body["items"]
27
+ items.sample
30
28
  end
31
29
  end
32
30
  end
@@ -51,9 +49,11 @@ module Ruboty
51
49
 
52
50
  def default_params
53
51
  {
54
- rsz: 8,
55
- safe: "active",
56
- v: "1.0",
52
+ searchType: 'image',
53
+ safe: 'high',
54
+ fields: 'items(link)',
55
+ cx: ENV['GOOGLE_CSE_ID'],
56
+ key: ENV['GOOGLE_CSE_KEY']
57
57
  }
58
58
  end
59
59
 
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module GoogleImage
3
- VERSION = "0.0.7"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-google_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.4.5
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: An ruboty handler to search images from Google.