ruboty-tumblr_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: a2860949d535d935266ace0d0112768c39befc60
4
+ data.tar.gz: dfdc42cdd1d61116237e516cf076da3920155a1c
5
+ SHA512:
6
+ metadata.gz: 0974dc638b52ed9738e745a49d542bf92a0add8be6782e90c85fb8c2feab8c2102fe1e04fe3db535312b7493605fe6191e2b04cfb718418b64fc5167bd6b3248
7
+ data.tar.gz: d803a1bf05087232c64358fa7fcb5cf66c61f46c085a84c08aec4e424f1dbe2a69de7133bce9edd55df3206c5a4991d5cca6a54a9fa7839f3340173b373c78ee
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-tumblr_image.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 hogelog
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,11 @@
1
+ # Ruboty::TumblrImage
2
+ An ruboty handler to pickup images from Tumblr.
3
+
4
+ ## Usage
5
+ ```
6
+ @ruboty tumblr <username> - Pickup image from Tumblr
7
+ @ruboty tumblr unsafe <username> - Pickup image from Tumblr (unsafe)
8
+ ```
9
+
10
+ ## Thanks
11
+ `ruboty-tumblr_image` is forked from [`ruboty-google_image`](https://github.com/r7kamura/ruboty-google_image)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
Binary file
@@ -0,0 +1,18 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class TumblrImage < Base
4
+ on /tumblr(?<unsafe> unsafe)?(?<username>.+)/, name: "tumblr", description: "Pickup image from Tumblr"
5
+
6
+ def tumblr(message)
7
+ url = search(message[:username], !!message[:unsafe])
8
+ message.reply(url.to_s)
9
+ end
10
+
11
+ private
12
+
13
+ def search(username, unsafe)
14
+ Ruboty::TumblrImage::Client.new(username: username, unsafe: unsafe).get
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,68 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Ruboty
5
+ module TumblrImage
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: "site:#{options[:username]}.tumblr.com",
49
+ safe: options[:unsafe] ? "off" : "active",
50
+ }
51
+ end
52
+
53
+ def default_params
54
+ {
55
+ rsz: 8,
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 TumblrImage
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "ruboty"
2
+ require "ruboty/tumblr_image/client"
3
+ require "ruboty/tumblr_image/version"
4
+ require "ruboty/handlers/tumblr_image"
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/tumblr_image/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-tumblr_image"
7
+ spec.version = Ruboty::TumblrImage::VERSION
8
+ spec.authors = ["Sunao Komuro"]
9
+ spec.email = ["konbu.komuro@gmail.com"]
10
+ spec.summary = "An ruboty handler to pickup images from Tumblr."
11
+ spec.homepage = "https://github.com/hogelog/ruboty-tumblr_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,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-tumblr_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sunao Komuro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-30 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
+ - konbu.komuro@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/handlers/tumblr_image.rb
112
+ - lib/ruboty/tumblr_image.rb
113
+ - lib/ruboty/tumblr_image/client.rb
114
+ - lib/ruboty/tumblr_image/version.rb
115
+ - ruboty-tumblr_image.gemspec
116
+ homepage: https://github.com/hogelog/ruboty-tumblr_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 pickup images from Tumblr.
140
+ test_files: []