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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b4bc3abb93dda1ff8171070aaec1468d29092fb
4
- data.tar.gz: 83326a2f4739249d21e01a84152165168d60232b
3
+ metadata.gz: 50ae2c1c00b34973086df2d3200e4ca4099feecb
4
+ data.tar.gz: 63960d444f31510724aba98f141aa70ce85bb3d5
5
5
  SHA512:
6
- metadata.gz: 2f30878a80c8d82d183ad83be8ee76b3754d83339648b545800e4b07efb643ddc5015a2b372abea839079fcfc95a9a99a243b5d5ea9dc9bb6e9d6979a493dae9
7
- data.tar.gz: 628a994d113236409864475e6e030ac5e238aaa4a2e13194f09db476b70eec1de0816b426e8d21d5767c05bd7f5ebebf312f5a7e092eba6101087f798a1fbe83
6
+ metadata.gz: 078b6d47038a95e544bbaf5a9b9b4121564a79cb07be09c6a8bc51b63134d49b474568c895842f0eb3da8798b6e18eb6dd845ed1a78eca993849971bbcb88af4
7
+ data.tar.gz: 4099faef5bfcfbc5f2d9851d18de79d4b039002429081eb0d1b93e3e6bde6b81eb79bdbb8a6e7c4c16ce43e5b3b6c8a4c6fa8eb8f51d8f0129a2068f48d48903
data/.gitignore CHANGED
@@ -7,8 +7,3 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 kaihar4
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 kaihar4
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
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
- included in all copies or substantial portions of the Software.
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
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 application's Gemfile:
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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruboty/image'
5
+
6
+ require 'irb'
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path vendor/bundle
@@ -1,18 +1,15 @@
1
1
  module Ruboty
2
2
  module Handlers
3
3
  class Image < Base
4
- on /img (?<mode>.+?) (?<keyword>.+)/, name: 'img', description: 'Search a image from Google image'
4
+ on /img (?<mode>(top|rand)) (?<keyword>.+)/, name: 'img', description: 'Search a image from Google image'
5
5
 
6
6
  def img(message)
7
- if url = search(message[:keyword], message[:mode].to_sym)
8
- message.reply(url)
9
- end
10
- end
11
-
12
- private
7
+ result = Ruboty::Image::Client.new(
8
+ message[:mode].to_sym,
9
+ message[:keyword]
10
+ ).search
13
11
 
14
- def search(query, mode)
15
- Ruboty::Image::Client.new(query, mode).get
12
+ message.reply(result) if result
16
13
  end
17
14
  end
18
15
  end
@@ -5,21 +5,21 @@ 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 = 'http://ajax.googleapis.com'
9
9
 
10
- def initialize(query, mode)
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 get
20
- response = @conn.get do |req|
19
+ def search
20
+ response = @conn.get {|req|
21
21
  req.url '/ajax/services/search/images', params
22
- end.body
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
- case @mode
34
- when :top
35
- {
36
- v: '1.0',
37
- safe: 'off',
38
- filter: 1,
39
- rsz: 1,
40
- q: @query
41
- }
42
- when :rand
43
- {
44
- v: '1.0',
45
- safe: 'off',
46
- filter: 1,
47
- rsz: 8,
48
- q: @query
49
- }
50
- end
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
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Image
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
data/ruboty-image.gemspec CHANGED
@@ -1,4 +1,5 @@
1
- $LOAD_PATH << File.expand_path('../lib', __FILE__)
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.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
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.add_dependency 'ruboty'
20
- spec.add_dependency 'faraday'
20
+ spec.add_runtime_dependency 'ruboty'
21
+ spec.add_runtime_dependency 'faraday'
21
22
 
22
- spec.add_development_dependency 'bundler', '~> 1.7'
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.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-11-09 00:00:00.000000000 Z
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.7'
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.7'
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.2.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