lita-bukkit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 478b3f11a8680bdd44724c361a1eea4d38667f28
4
+ data.tar.gz: 04edd2c16ebc6b8cba24c45e148fbd09cf762866
5
+ SHA512:
6
+ metadata.gz: 34ad673eaaa63abc7caabae8f0d11a4ba86c9b43c010ca2f68e7fd7793c4f5e681f96953323246ef01033835e0c7317d0b8d2c8ea61e0d21469d9f2cb7290f5a
7
+ data.tar.gz: 72c62d159b85c46cbca28a6a7c8656c3c9194a00b263fbf01d0b7dc504876750ff53fff38d85d195b59258568c8495a185f1addfcd1ac12c3efbc1809105fead
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Paul Simpson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # lita-bukkit
2
+
3
+ [![Travis-CI Badge](https://api.travis-ci.org/prsimp/lita-bukkit.png)](https://travis-ci.org/prsimp/lita-bukkit)
4
+ [![Coverage Status](https://coveralls.io/repos/prsimp/lita-bukkit/badge.png)](https://coveralls.io/r/prsimp/lita-bukkit)
5
+
6
+ Grabs a random image from the list of images at [http://bukk.it](http://bukk.it)
7
+
8
+ ## Installation
9
+
10
+ Add lita-bukkit to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem "lita-bukkit"
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ None.
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ Lita: bukkit me
24
+ ```
25
+
26
+ ## License
27
+
28
+ [MIT](http://opensource.org/licenses/MIT)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require "lita/handlers/bukkit"
@@ -0,0 +1,45 @@
1
+ require "lita"
2
+ require "nokogiri"
3
+
4
+ module Lita
5
+ module Handlers
6
+ class Bukkit < Handler
7
+ URL = "http://bukk.it"
8
+
9
+ route %r{bukkit me}, :fetch, command: true, help: {
10
+ "bukkit me" => "Fetches a random image from bukkit."
11
+ }
12
+
13
+ def fetch(response)
14
+ http_resp = http.get(URL)
15
+
16
+ if http_resp.status == 200
17
+ response.reply extract_image_url_from(http_resp)
18
+ else
19
+ Lita.logger.warn("Bukkit could not be reached.")
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def extract_image_url_from(resp)
26
+ links = parse_rows(Nokogiri::HTML(resp.body)).compact
27
+ "#{URL}/#{parse_hrefs(links).sample}"
28
+ end
29
+
30
+ def parse_rows(page)
31
+ extract_rows(page).map { |row| row.css("a").first }
32
+ end
33
+
34
+ def extract_rows(page)
35
+ page.css("tr").slice(2..-1)
36
+ end
37
+
38
+ def parse_hrefs(links)
39
+ links.map { |link| link.attributes["href"] }.compact.map(&:value)
40
+ end
41
+ end
42
+
43
+ Lita.register_handler(Bukkit)
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-bukkit"
3
+ spec.version = "1.0.0"
4
+ spec.authors = ["Paul Simpson"]
5
+ spec.email = ["prsimp@gmail.com"]
6
+ spec.description = %q{A Lita handler for fetching images from http://bukk.it}
7
+ spec.summary = %q{A Lita handler for fetching images from http://bukk.it}
8
+ spec.homepage = "https://github.com/prsimp/lita-bukkit"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^spec/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.6"
17
+ spec.add_runtime_dependency "nokogiri", "~> 1.6"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec", ">= 2.14"
22
+ spec.add_development_dependency "simplecov"
23
+ spec.add_development_dependency "coveralls"
24
+ end
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Bukkit, lita_handler: true do
4
+ it { routes_command("bukkit me").to(:fetch) }
5
+
6
+ describe "#fetch" do
7
+ let(:response) { double("Faraday::Response") }
8
+
9
+ before do
10
+ allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
11
+ end
12
+
13
+ it "replies with an image URL on success" do
14
+ allow(response).to receive(:status).and_return(200)
15
+ allow(response).to receive(:body).and_return(<<-HTML.chomp
16
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
17
+ <html>
18
+ <head>
19
+ <title>Index of /</title>
20
+ </head>
21
+ <body>
22
+ <h1>Index of /</h1>
23
+ <table>
24
+ <tr>
25
+ <th><img src="/icons/blank.gif" alt="[ICO]"></th>
26
+ <th><a href="?C=N;O=A">Name</a></th>
27
+ <th><a href="?C=M;O=A">Last modified</a></th>
28
+ <th><a href="?C=S;O=A">Size</a></th>
29
+ <th><a href="?C=D;O=A">Description</a></th>
30
+ </tr>
31
+ <tr>
32
+ <th colspan="5"><hr></th>
33
+ </tr>
34
+ <tr>
35
+ <td valign="top"><img src="/icons/image2.gif" alt="[IMG]"></td>
36
+ <td><a href="googleglass.gif">googleglass.gif</a></td>
37
+ <td align="right">19-Nov-2013 12:41 </td>
38
+ <td align="right">860K</td>
39
+ </tr>
40
+ </table>
41
+ </body>
42
+ </html>
43
+ HTML
44
+ )
45
+
46
+ send_command("bukkit me")
47
+
48
+ expect(replies.last).to eq("http://bukk.it/googleglass.gif")
49
+ end
50
+
51
+ it "logs a warning on failure" do
52
+ allow(response).to receive(:status).and_return(500)
53
+
54
+ expect(Lita.logger).to receive(:warn).with(/Bukkit could not be reached./)
55
+
56
+ send_command("bukkit me")
57
+
58
+ expect(replies).to be_empty
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-bukkit"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-bukkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Simpson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '2.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '2.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
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
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A Lita handler for fetching images from http://bukk.it
112
+ email:
113
+ - prsimp@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .travis.yml
120
+ - Gemfile
121
+ - LICENSE
122
+ - README.md
123
+ - Rakefile
124
+ - lib/lita-bukkit.rb
125
+ - lib/lita/handlers/bukkit.rb
126
+ - lita-bukkit.gemspec
127
+ - spec/lita/handlers/bukkit_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/prsimp/lita-bukkit
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.1
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: A Lita handler for fetching images from http://bukk.it
153
+ test_files:
154
+ - spec/lita/handlers/bukkit_spec.rb
155
+ - spec/spec_helper.rb