ruboty-image 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50ae2c1c00b34973086df2d3200e4ca4099feecb
4
- data.tar.gz: 63960d444f31510724aba98f141aa70ce85bb3d5
3
+ metadata.gz: 81b2dcbcd2c1a0236ae72d8356698aa469ed99bd
4
+ data.tar.gz: 40b1d5ae413fc9e7555573e8a41451fd7b84829f
5
5
  SHA512:
6
- metadata.gz: 078b6d47038a95e544bbaf5a9b9b4121564a79cb07be09c6a8bc51b63134d49b474568c895842f0eb3da8798b6e18eb6dd845ed1a78eca993849971bbcb88af4
7
- data.tar.gz: 4099faef5bfcfbc5f2d9851d18de79d4b039002429081eb0d1b93e3e6bde6b81eb79bdbb8a6e7c4c16ce43e5b3b6c8a4c6fa8eb8f51d8f0129a2068f48d48903
6
+ metadata.gz: 49619f389d66972b36f3e158a664f170de2f33c3a9cb83a6765b534d33f801058d1566de0e21ab4509c1f9a14ef12ca63dbb119525653ff4e0e729454f6bbe3e
7
+ data.tar.gz: 1f1d389637336402336c1fbafbedaf1cc7db13aca9ba2236b3aee10af17ca95949efff5fa963d624228a4ab8cd2b35cea94964f049e6acd667964c14f0ca8617
data/README.md CHANGED
@@ -17,6 +17,17 @@ gem 'ruboty-image'
17
17
  @ruboty img rand <keyword> - Search a random image from Google image
18
18
  ```
19
19
 
20
+ ## Setup
21
+
22
+ Ruboty::Image requires access tokens.
23
+
24
+ Please get via [here](https://developers.google.com/custom-search/json-api/v1/overview?hl=ja#cx).
25
+
26
+ ```
27
+ export CSE_ID=
28
+ export CSE_KEY=
29
+ ```
30
+
20
31
  ## Development
21
32
 
22
33
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,7 +5,7 @@ require 'faraday'
5
5
  module Ruboty
6
6
  module Image
7
7
  class Client
8
- GOOGLE_API_URL = 'http://ajax.googleapis.com'
8
+ GOOGLE_API_URL = 'https://www.googleapis.com'
9
9
 
10
10
  def initialize(mode, query)
11
11
  @conn = Faraday.new(url: GOOGLE_API_URL) do |faraday|
@@ -18,11 +18,11 @@ module Ruboty
18
18
 
19
19
  def search
20
20
  response = @conn.get {|req|
21
- req.url '/ajax/services/search/images', params
21
+ req.url '/customsearch/v1', params
22
22
  }.body
23
- images = JSON.parse(response)['responseData']['results']
23
+ images = JSON.parse(response)['items']
24
24
  # when @mode is :top -> images.length is 1
25
- images.sample['unescapedUrl']
25
+ images.sample['link']
26
26
  rescue
27
27
  nil
28
28
  end
@@ -31,9 +31,11 @@ module Ruboty
31
31
 
32
32
  def params
33
33
  default_params = {
34
- v: '1.0',
34
+ searchType: 'image',
35
35
  safe: 'off',
36
36
  filter: 1,
37
+ cx: ENV['CSE_ID'],
38
+ key: ENV['CSE_KEY'],
37
39
  q: @query
38
40
  }
39
41
 
@@ -41,11 +43,11 @@ module Ruboty
41
43
  case @mode
42
44
  when :top
43
45
  {
44
- rsz: 1
46
+ num: 1
45
47
  }
46
48
  when :rand
47
49
  {
48
- rsz: 8
50
+ num: 8
49
51
  }
50
52
  end
51
53
 
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Image
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-image
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
  - kaihar4
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-16 00:00:00.000000000 Z
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.4.5
108
+ rubygems_version: 2.5.1
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Search a image from Google image