ellen-google_image 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cbd30dbc7694ec734cb8b62652f9ecf5e5ccc7a0
4
+ data.tar.gz: 8c4d18388f61dc36a4daea1b2bf273ff83d88025
5
+ SHA512:
6
+ metadata.gz: 57e4f08c1a5f4875bc085cae5d0acbbb65a49a46c2d02f61715f797f12e60aa8a89c94a4c231899c8b30d84fc216d72ac308788698b60e892b9995037bda70b9
7
+ data.tar.gz: 473dd1a30e55cb1e05d824b7fd53691c112f0db02c4deda06563e0b3351384f626f2533ac1b0ce39fd44ef87be74e4caf3fa672a714bb8adfd6c314496c1b0d4
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen-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,8 @@
1
+ # Ellen::GoogleImage
2
+ An ellen handler to search images from Google.
3
+
4
+ ## Usage
5
+ ```
6
+ @ellen image <query> - Search image from Google
7
+ @ellen animate <query> - Search animation from Google
8
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ellen/google_image/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ellen-google_image"
7
+ spec.version = Ellen::GoogleImage::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "An ellen handler to search images from Google."
11
+ spec.homepage = "https://github.com/r7kamura/ellen-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 "ellen", ">= 0.0.5"
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
@@ -0,0 +1,73 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Ellen
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
+ Ellen.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
+ imgType: image_type,
50
+ }
51
+ end
52
+
53
+ def default_params
54
+ {
55
+ rsz: 8,
56
+ safe: "active",
57
+ v: "1.0",
58
+ }
59
+ end
60
+
61
+ def image_type
62
+ "ainmated" if options[:animated]
63
+ end
64
+
65
+ def connection
66
+ Faraday.new do |connection|
67
+ connection.adapter :net_http
68
+ connection.response :json
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ module Ellen
2
+ module GoogleImage
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "ellen"
2
+ require "ellen/google_image/client"
3
+ require "ellen/google_image/version"
4
+ require "ellen/handlers/google_image"
@@ -0,0 +1,17 @@
1
+ module Ellen
2
+ module Handlers
3
+ class GoogleImage < Base
4
+ on /image (.+)/, description: "Search image from Google" do |message|
5
+ if url = Ellen::GoogleImage::Client.new(query: message[1]).get
6
+ say url
7
+ end
8
+ end
9
+
10
+ on /animate (.+)/, description: "Search animation from Google" do |message|
11
+ if url = Ellen::GoogleImage::Client.new(query: message[1]).get
12
+ say url
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen-google_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ellen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.5
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
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - ellen-google_image.gemspec
110
+ - lib/ellen/google_image.rb
111
+ - lib/ellen/google_image/client.rb
112
+ - lib/ellen/google_image/version.rb
113
+ - lib/ellen/handlers/google_image.rb
114
+ homepage: https://github.com/r7kamura/ellen-google_image
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: An ellen handler to search images from Google.
138
+ test_files: []