ruboty-image 0.0.1 → 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 +4 -4
- data/.gitignore +0 -5
- data/LICENSE.txt +17 -18
- data/README.md +15 -1
- data/bin/console +7 -0
- data/bin/setup +5 -0
- data/lib/ruboty/handlers/image.rb +6 -9
- data/lib/ruboty/image/client.rb +26 -24
- data/lib/ruboty/image/version.rb +1 -1
- data/ruboty-image.gemspec +8 -7
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ae2c1c00b34973086df2d3200e4ca4099feecb
|
4
|
+
data.tar.gz: 63960d444f31510724aba98f141aa70ce85bb3d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 078b6d47038a95e544bbaf5a9b9b4121564a79cb07be09c6a8bc51b63134d49b474568c895842f0eb3da8798b6e18eb6dd845ed1a78eca993849971bbcb88af4
|
7
|
+
data.tar.gz: 4099faef5bfcfbc5f2d9851d18de79d4b039002429081eb0d1b93e3e6bde6b81eb79bdbb8a6e7c4c16ce43e5b3b6c8a4c6fa8eb8f51d8f0129a2068f48d48903
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2015 kaihar4
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Ruboty handler to search a image from Google image.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add this line to your
|
7
|
+
Add this line to your ruboty's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
gem 'ruboty-image'
|
@@ -16,3 +16,17 @@ gem 'ruboty-image'
|
|
16
16
|
@ruboty img top <keyword> - Search a image from Google image
|
17
17
|
@ruboty img rand <keyword> - Search a random image from Google image
|
18
18
|
```
|
19
|
+
|
20
|
+
## Development
|
21
|
+
|
22
|
+
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.
|
23
|
+
|
24
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/kaihar4/ruboty-image/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -1,18 +1,15 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Handlers
|
3
3
|
class Image < Base
|
4
|
-
on /img (?<mode
|
4
|
+
on /img (?<mode>(top|rand)) (?<keyword>.+)/, name: 'img', description: 'Search a image from Google image'
|
5
5
|
|
6
6
|
def img(message)
|
7
|
-
|
8
|
-
message.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
private
|
7
|
+
result = Ruboty::Image::Client.new(
|
8
|
+
message[:mode].to_sym,
|
9
|
+
message[:keyword]
|
10
|
+
).search
|
13
11
|
|
14
|
-
|
15
|
-
Ruboty::Image::Client.new(query, mode).get
|
12
|
+
message.reply(result) if result
|
16
13
|
end
|
17
14
|
end
|
18
15
|
end
|
data/lib/ruboty/image/client.rb
CHANGED
@@ -5,21 +5,21 @@ require 'faraday'
|
|
5
5
|
module Ruboty
|
6
6
|
module Image
|
7
7
|
class Client
|
8
|
-
GOOGLE_API_URL =
|
8
|
+
GOOGLE_API_URL = 'http://ajax.googleapis.com'
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(mode, query)
|
11
11
|
@conn = Faraday.new(url: GOOGLE_API_URL) do |faraday|
|
12
12
|
faraday.request :url_encoded
|
13
13
|
faraday.adapter Faraday.default_adapter
|
14
14
|
end
|
15
|
-
@query = query
|
16
15
|
@mode = mode
|
16
|
+
@query = query
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
response = @conn.get
|
19
|
+
def search
|
20
|
+
response = @conn.get {|req|
|
21
21
|
req.url '/ajax/services/search/images', params
|
22
|
-
|
22
|
+
}.body
|
23
23
|
images = JSON.parse(response)['responseData']['results']
|
24
24
|
# when @mode is :top -> images.length is 1
|
25
25
|
images.sample['unescapedUrl']
|
@@ -30,24 +30,26 @@ module Ruboty
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def params
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
33
|
+
default_params = {
|
34
|
+
v: '1.0',
|
35
|
+
safe: 'off',
|
36
|
+
filter: 1,
|
37
|
+
q: @query
|
38
|
+
}
|
39
|
+
|
40
|
+
append_params =
|
41
|
+
case @mode
|
42
|
+
when :top
|
43
|
+
{
|
44
|
+
rsz: 1
|
45
|
+
}
|
46
|
+
when :rand
|
47
|
+
{
|
48
|
+
rsz: 8
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
default_params.merge(append_params)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/ruboty/image/version.rb
CHANGED
data/ruboty-image.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
2
3
|
require 'ruboty/image/version'
|
3
4
|
|
4
5
|
Gem::Specification.new do |spec|
|
@@ -11,14 +12,14 @@ Gem::Specification.new do |spec|
|
|
11
12
|
spec.homepage = 'https://github.com/kaihar4/ruboty-image'
|
12
13
|
spec.license = 'MIT'
|
13
14
|
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
-
spec.
|
16
|
-
spec.
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'exe'
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
18
|
spec.require_paths = ['lib']
|
18
19
|
|
19
|
-
spec.
|
20
|
-
spec.
|
20
|
+
spec.add_runtime_dependency 'ruboty'
|
21
|
+
spec.add_runtime_dependency 'faraday'
|
21
22
|
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
23
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
25
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.9'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.9'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +78,8 @@ files:
|
|
78
78
|
- LICENSE.txt
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
81
83
|
- lib/ruboty/handlers/image.rb
|
82
84
|
- lib/ruboty/image.rb
|
83
85
|
- lib/ruboty/image/client.rb
|
@@ -103,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
105
|
version: '0'
|
104
106
|
requirements: []
|
105
107
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.4.5
|
107
109
|
signing_key:
|
108
110
|
specification_version: 4
|
109
111
|
summary: Search a image from Google image
|