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 +4 -4
- data/README.md +11 -0
- data/lib/ruboty/image/client.rb +9 -7
- data/lib/ruboty/image/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b2dcbcd2c1a0236ae72d8356698aa469ed99bd
|
4
|
+
data.tar.gz: 40b1d5ae413fc9e7555573e8a41451fd7b84829f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/ruboty/image/client.rb
CHANGED
@@ -5,7 +5,7 @@ require 'faraday'
|
|
5
5
|
module Ruboty
|
6
6
|
module Image
|
7
7
|
class Client
|
8
|
-
GOOGLE_API_URL = '
|
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 '/
|
21
|
+
req.url '/customsearch/v1', params
|
22
22
|
}.body
|
23
|
-
images = JSON.parse(response)['
|
23
|
+
images = JSON.parse(response)['items']
|
24
24
|
# when @mode is :top -> images.length is 1
|
25
|
-
images.sample['
|
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
|
-
|
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
|
-
|
46
|
+
num: 1
|
45
47
|
}
|
46
48
|
when :rand
|
47
49
|
{
|
48
|
-
|
50
|
+
num: 8
|
49
51
|
}
|
50
52
|
end
|
51
53
|
|
data/lib/ruboty/image/version.rb
CHANGED
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.
|
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:
|
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.
|
108
|
+
rubygems_version: 2.5.1
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Search a image from Google image
|