ruboty-google_image 0.0.7

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d23e3c4fb1c91fe1f350fd7544d74dbc2dc082e7
4
+ data.tar.gz: 0b86bdcb140fc868bfa89ee1f7746279c87ce671
5
+ SHA512:
6
+ metadata.gz: 1f1f76a80bbf015f73272e665559150dbbf04c537f529011b1df553eca6bbca46c4d401a8421ff9ea68cad8ba6488408cd78a1b7a2feea8b584f322773869d71
7
+ data.tar.gz: 172f6f41c31edb1767560d0c1e2b210bd9a3cc2238d080ebefc0430d38845f0d9e51502174000958d73225f241c1dfef79f32d7a8bc97c2bb1e010e962aa1feb
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ ## 0.0.7
2
+ * Rename: Ellen -> Ruboty
3
+
4
+ ## 0.0.6
5
+ * Support Ruboty v0.2.0
6
+
7
+ ## 0.0.5
8
+ * Obsolete animate command
9
+
10
+ ## 0.0.4
11
+ * Add optional `me`: e.g. `image me ruboty`
12
+
13
+ ## 0.0.3
14
+ * Adapt to ruboty 0.0.8's new handler interface
15
+
16
+ ## 0.0.2
17
+ * Fix animate query
18
+
19
+ ## 0.0.1
20
+ * 1st Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-google_image.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
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:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
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.
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Ruboty::GoogleImage
2
+ An ruboty handler to search images from Google.
3
+
4
+ ## Usage
5
+ ```
6
+ @ruboty image <keyword> - Search image from Google
7
+ ```
8
+
9
+ ![](https://raw.githubusercontent.com/r7kamura/ruboty-google_image/master/images/screenshot.png)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
Binary file
@@ -0,0 +1,68 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Ruboty
5
+ module GoogleImage
6
+ class Client
7
+ GOOGLE_IMAGE_API_URL = "http://ajax.googleapis.com/ajax/services/search/images"
8
+
9
+ attr_reader :options
10
+
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ def get
16
+ resource["unescapedUrl"] if resource
17
+ rescue => exception
18
+ Ruboty.logger.error("Error: #{self}##{__method__} - #{exception}")
19
+ nil
20
+ end
21
+
22
+ private
23
+
24
+ def resource
25
+ @resource ||= begin
26
+ if data = response.body["responseData"]
27
+ if results = data["results"]
28
+ results.sample
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def response
35
+ connection.get(url, params)
36
+ end
37
+
38
+ def url
39
+ GOOGLE_IMAGE_API_URL
40
+ end
41
+
42
+ def params
43
+ default_params.merge(given_params).reject {|key, value| value.nil? }
44
+ end
45
+
46
+ def given_params
47
+ {
48
+ q: options[:query],
49
+ }
50
+ end
51
+
52
+ def default_params
53
+ {
54
+ rsz: 8,
55
+ safe: "active",
56
+ v: "1.0",
57
+ }
58
+ end
59
+
60
+ def connection
61
+ Faraday.new do |connection|
62
+ connection.adapter :net_http
63
+ connection.response :json
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module GoogleImage
3
+ VERSION = "0.0.7"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "ruboty"
2
+ require "ruboty/google_image/client"
3
+ require "ruboty/google_image/version"
4
+ require "ruboty/handlers/google_image"
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class GoogleImage < Base
4
+ on /image( me)? (?<keyword>.+)/, name: "image", description: "Search image from Google"
5
+
6
+ def image(message)
7
+ if url = search(message[:keyword])
8
+ message.reply(url)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def search(query)
15
+ Ruboty::GoogleImage::Client.new(query: query).get
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/google_image/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-google_image"
7
+ spec.version = Ruboty::GoogleImage::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "An ruboty handler to search images from Google."
11
+ spec.homepage = "https://github.com/r7kamura/ruboty-google_image"
12
+ spec.license = "MIT"
13
+
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)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ruboty"
20
+ spec.add_dependency "faraday"
21
+ spec.add_dependency "faraday_middleware"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-google_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - r7kamura@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - images/screenshot.png
111
+ - lib/ruboty/google_image.rb
112
+ - lib/ruboty/google_image/client.rb
113
+ - lib/ruboty/google_image/version.rb
114
+ - lib/ruboty/handlers/google_image.rb
115
+ - ruboty-google_image.gemspec
116
+ homepage: https://github.com/r7kamura/ruboty-google_image
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: An ruboty handler to search images from Google.
140
+ test_files: []
141
+ has_rdoc: