lita-howlongtobeat 0.1.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: fb31af125c192ec7dcd13232b24d6164cd33a20a
4
+ data.tar.gz: c91f5b605c190ca566e6c4cf2a311d63f1bfc775
5
+ SHA512:
6
+ metadata.gz: c2aea2755662ae358f3b8d4e6e2d288fa5f56c3d23f7acdd261df6fc75c0e0d23794af8b79e80ea888d2737a5b0cb37d16c16b58e9a4541efabd05017a895959
7
+ data.tar.gz: 21c861b430922e7fa3d0804b0b7aa667c733956bb61b17e19f27f22061c798a98dafa9c533e11879fa57d3a93ae64fa3b76f1615850a51cee4a44eae5452d7e4
@@ -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,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Magnus Skog
4
+
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:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,21 @@
1
+ # lita-howlongtobeat
2
+
3
+ **lita-howlongtobeat** is a [Lita](https://github.com/litaio/lita) handler that returns the average length of the main story for a video game.
4
+
5
+ ## Installation
6
+
7
+ Add lita-howlongtobeat to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-howlongtobeat"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ To get the length of the Main Story of a game:
16
+
17
+ ```
18
+ <me> lita: hltp Witcher 3
19
+ <lita> Source: http://howlongtobeat.com/game.php?id=10270
20
+ <lita> It will take about 43½ Hours to beat the main story of The Witcher 3: Wild Hunt
21
+ ```
@@ -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,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.0.0
@@ -0,0 +1,13 @@
1
+ require "lita"
2
+ require 'nokogiri'
3
+
4
+ Lita.load_locales Dir[File.expand_path(
5
+ File.join("..", "..", "locales", "*.yml"), __FILE__
6
+ )]
7
+
8
+ require "lita/handlers/howlongtobeat"
9
+
10
+ Lita::Handlers::Howlongtobeat.template_root File.expand_path(
11
+ File.join("..", "..", "templates"),
12
+ __FILE__
13
+ )
@@ -0,0 +1,23 @@
1
+ module Lita
2
+ module Handlers
3
+ class Howlongtobeat < Handler
4
+ SITE_URL = "http://howlongtobeat.com"
5
+ SEARCH_URL = "http://howlongtobeat.com/search_main.php?page=1"
6
+
7
+ route(/^(?:hltp|howlongtobeat)\s+(.*)/i, :howlongtobeat, command: true, help: { t("help.howlongtobeat_key") => t("help.howlongtobeat_value")})
8
+
9
+ def howlongtobeat(response)
10
+ term = response.matches[0][0]
11
+ search = http.post(SEARCH_URL, queryString: term, t: 'games', sorthead: 'popular', sortd: 'Normal Order', detail: '0')
12
+ document = Nokogiri::HTML(search.body)
13
+ title = document.css('a')[0]
14
+ response.reply("No results found for #{term}") && return unless title
15
+ story = document.css(".search_list_tidbit.center")[0].text
16
+ response.reply("It will take about #{story}to beat the main story of #{title.attr('title')}")
17
+ response.reply("Source: #{SITE_URL}/#{title.attr('href')}")
18
+ end
19
+
20
+ Lita.register_handler(self)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-howlongtobeat"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Magnus Skog"]
5
+ spec.email = ["magnus.m.skog@gmail.com"]
6
+ spec.description = "A Lita handler that returns the average number of hours required to beat a game from http://howlongtobeat.com"
7
+ spec.summary = "A Lita handler that returns the average number of hours required to beat a game from http://howlongtobeat.com"
8
+ spec.homepage = "https://github.com/mskog/lita-howlongtobeat"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.6"
18
+ spec.add_runtime_dependency "nokogiri", ">= 1.6.6"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "pry-byebug"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "rspec", ">= 3.0.0"
25
+ spec.add_development_dependency 'webmock', '>= 1.22.3'
26
+ end
@@ -0,0 +1,8 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ howlongtobeat:
5
+ help:
6
+ howlongtobeat_key: hltp NAME
7
+ howlongtobeat_value: "Look up the Main Story length of game NAME"
8
+
@@ -0,0 +1,17 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sun, 15 Nov 2015 13:14:29 GMT
3
+ Content-Type: text/html; charset=windows-1252
4
+ Transfer-Encoding: chunked
5
+ Connection: keep-alive
6
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
7
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
8
+ Pragma: no-cache
9
+ Set-Cookie: hl2b_save=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=howlongtobeat.com; httponly
10
+ Vary: Accept-Encoding
11
+ Set-Cookie: _asomcnc=1; Max-Age=900; Path=/
12
+ X-NoCache: 1
13
+ Server: cloudflare-nginx
14
+ CF-RAY: 245b3829368c3ccb-CPH
15
+ Content-Encoding: gzip
16
+
17
+ <li class='global_padding back_white shadow_box'>No results for <strong>fasdifjasiofjsafij</strong> in <u>games</u>.</li>
@@ -0,0 +1,57 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sun, 15 Nov 2015 12:54:53 GMT
3
+ Content-Type: text/html; charset=windows-1252
4
+ Transfer-Encoding: chunked
5
+ Connection: keep-alive
6
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
7
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
8
+ Pragma: no-cache
9
+ Set-Cookie: hl2b_save=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=howlongtobeat.com; httponly
10
+ Vary: Accept-Encoding
11
+ Set-Cookie: _asomcnc=1; Max-Age=900; Path=/
12
+ X-NoCache: 1
13
+ Server: cloudflare-nginx
14
+ CF-RAY: 245b1b7844be3d31-CPH
15
+ Content-Encoding: gzip
16
+
17
+ <h3 class='head_padding shadow_box back_blue'>We Found 2 Games for "witcher 3"</h3> <li class="back_white shadow_box"> <div class="search_list_image">
18
+ <a title="The Witcher 3: Wild Hunt" href="game.php?id=10270">
19
+ <img src="gameimages/256px-TW3_Wild_Hunt_logo.png"/>
20
+ </a>
21
+ </div> <div class="search_list_details"> <h3><a class="text_blue" title="The Witcher 3: Wild Hunt" href="game.php?id=10270">The Witcher 3: Wild Hunt</a></h3> <div class="search_list_details_block"> <div>
22
+ <div class="search_list_tidbit">Main Story</div>
23
+ <div class="search_list_tidbit center time_100">43&#189; Hours </div>
24
+ </div>
25
+ <div>
26
+ <div class="search_list_tidbit">Main + Extra</div>
27
+ <div class="search_list_tidbit center time_100">94&#189; Hours </div>
28
+ </div>
29
+ <div>
30
+ <div class="search_list_tidbit">Completionist</div>
31
+ <div class="search_list_tidbit center time_100">165&#189; Hours </div>
32
+ </div>
33
+ <div>
34
+ <div class="search_list_tidbit">Combined</div>
35
+ <div class="search_list_tidbit center time_100">97 Hours </div>
36
+ </div> </div>
37
+ </div> <div class="clear"></div> </li> <li class="back_white shadow_box"> <div class="search_list_image">
38
+ <a title="The Witcher 3: Wild Hunt - Hearts of Stone" href="game.php?id=30003">
39
+ <img src="gameimages/The-Witcher-3-Wild-Hunt-Hearts-of-Stone-Expansion-Teaser.jpg"/>
40
+ </a>
41
+ </div> <div class="search_list_details"> <h3><a class="text_blue" title="The Witcher 3: Wild Hunt - Hearts of Stone" href="game.php?id=30003">The Witcher 3: Wild Hunt - Hearts of Stone</a></h3> <div class="search_list_details_block"> <div>
42
+ <div class="search_list_tidbit">Main Story</div>
43
+ <div class="search_list_tidbit center time_60">10 Hours </div>
44
+ </div>
45
+ <div>
46
+ <div class="search_list_tidbit">Main + Extra</div>
47
+ <div class="search_list_tidbit center time_80">14&#189; Hours </div>
48
+ </div>
49
+ <div>
50
+ <div class="search_list_tidbit">Completionist</div>
51
+ <div class="search_list_tidbit center time_50">17&#189; Hours </div>
52
+ </div>
53
+ <div>
54
+ <div class="search_list_tidbit">Combined</div>
55
+ <div class="search_list_tidbit center time_100">14 Hours </div>
56
+ </div> </div>
57
+ </div> <div class="clear"></div> </li>
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Howlongtobeat, lita_handler: true do
4
+ it { is_expected.to route_command("howlongtobeat witcher 3").to(:howlongtobeat) }
5
+ it { is_expected.to route_command("hltp witcher 3").to(:howlongtobeat) }
6
+
7
+ describe "#howlongtobeat" do
8
+ before :each do
9
+ stub_request(:post, described_class::SEARCH_URL).with(body: {"detail"=>"0", "queryString"=>"sdfdfsfdfds", "sortd"=>"Normal Order", "sorthead"=>"popular", "t"=>"games"}).to_return(File.read('spec/fixtures/nothing_found.txt'))
10
+ end
11
+
12
+ context "with a term with results" do
13
+ before :each do
14
+ stub_request(:post, described_class::SEARCH_URL).with(body: {"detail"=>"0", "queryString"=>"witcher 3", "sortd"=>"Normal Order", "sorthead"=>"popular", "t"=>"games"}).to_return(File.read('spec/fixtures/witcher_3.txt'))
15
+ end
16
+
17
+ it "returns the title and the main story length" do
18
+ send_command "howlongtobeat witcher 3"
19
+ expect(replies.count).to eq 2
20
+ expect(replies[0]).to match 'It will take about 43½ Hours to beat the main story of The Witcher 3: Wild Hunt'
21
+ expect(replies[1]).to match "Source: #{described_class::SITE_URL}/game.php?id=10270"
22
+ end
23
+ end
24
+
25
+ context "with no results" do
26
+ let(:command){'sdfdfsfdfds'}
27
+
28
+ before :each do
29
+ stub_request(:post, described_class::SEARCH_URL).with(body: {"detail"=>"0", "queryString"=> command, "sortd"=>"Normal Order", "sorthead"=>"popular", "t"=>"games"}).to_return(File.read('spec/fixtures/nothing_found.txt'))
30
+ end
31
+
32
+ it "returns an error" do
33
+ send_command "hltp #{command}"
34
+ expect(replies.count).to eq 1
35
+ expect(replies[0]).to match "No results found for #{command}"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ require "lita-howlongtobeat"
2
+ require "lita/rspec"
3
+ require 'webmock/rspec'
4
+
5
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
6
+ # was generated with Lita 4, the compatibility mode should be left disabled.
7
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-howlongtobeat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Magnus Skog
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-16 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: '4.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.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.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.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: pry-byebug
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: rake
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: rack-test
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: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.22.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.22.3
125
+ description: A Lita handler that returns the average number of hours required to beat
126
+ a game from http://howlongtobeat.com
127
+ email:
128
+ - magnus.m.skog@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - circle.yml
140
+ - lib/lita-howlongtobeat.rb
141
+ - lib/lita/handlers/howlongtobeat.rb
142
+ - lita-howlongtobeat.gemspec
143
+ - locales/en.yml
144
+ - spec/fixtures/nothing_found.txt
145
+ - spec/fixtures/witcher_3.txt
146
+ - spec/lita/handlers/howlongtobeat_spec.rb
147
+ - spec/spec_helper.rb
148
+ - templates/.gitkeep
149
+ homepage: https://github.com/mskog/lita-howlongtobeat
150
+ licenses:
151
+ - MIT
152
+ metadata:
153
+ lita_plugin_type: handler
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.4.5
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: A Lita handler that returns the average number of hours required to beat
174
+ a game from http://howlongtobeat.com
175
+ test_files:
176
+ - spec/fixtures/nothing_found.txt
177
+ - spec/fixtures/witcher_3.txt
178
+ - spec/lita/handlers/howlongtobeat_spec.rb
179
+ - spec/spec_helper.rb
180
+ has_rdoc: