lita-googlefight 1.0.0
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +24 -0
- data/Rakefile +6 -0
- data/lib/lita-googlefight.rb +52 -0
- data/lita-googlefight.gemspec +24 -0
- data/spec/googlefight_spec.rb +16 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8d9a495518744e122943611e1bb8a116b5c57ca
|
4
|
+
data.tar.gz: 55f3b3db7ce80a316489c02f2ccd0c7df5f12e8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7841cdb0dc838c6e243bbca504f4ae725bad8cbb74773af62df9937d04fbbe19862c700252f2b9ee18116b4686c5790530bb67144e264734ec9b68e2bfd64d09
|
7
|
+
data.tar.gz: 6e712599816fb49aed66ea74f1865ca5e86f88633a0b9df34868e0dff6a1d0bf12c5df2806a90b309a671f865a50b16401276fb39ad2ee033e725efdd18a8d09
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2015-, Simon Lundström <simmel@soy.se>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# lita-googlefight
|
2
|
+
|
3
|
+
Fight two terms to see which one has more hits on Google.
|
4
|
+
Inspired by http://googlefight.com/
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add lita-googlefight to your Lita instance's Gemfile:
|
9
|
+
|
10
|
+
``` ruby
|
11
|
+
gem "lita-googlefight"
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```
|
17
|
+
You: !googlefight google:altavista
|
18
|
+
Lita: google (832000000) vs. altavista (1180000): WINNER: google!
|
19
|
+
```
|
20
|
+
|
21
|
+
```
|
22
|
+
You: !gf "something else";"totally another"
|
23
|
+
Lita: "something else" (10400000) vs. "totally another" (5660): WINNER: "something else"!
|
24
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "lita"
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
Word = Struct.new(:word, :hits)
|
7
|
+
|
8
|
+
module Lita
|
9
|
+
module Handlers
|
10
|
+
class Googlefight < Handler
|
11
|
+
|
12
|
+
route(/^!g(?:oogle)?f(?:ight)?\s+(.+)/, :googlefight, help: { "!g(oogle)f(ight) term one(:|;)term two" => "GoogleFight terms against each other" })
|
13
|
+
|
14
|
+
def googlefight(response)
|
15
|
+
one, two = response.match_data.captures.join.split(/ *[:;] */, 2).map {
|
16
|
+
|i| Word.new(i)
|
17
|
+
}
|
18
|
+
result = nil
|
19
|
+
|
20
|
+
[one, two].each do |word|
|
21
|
+
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' + CGI.escape(word.word)
|
22
|
+
begin
|
23
|
+
open(url, "Referer" => "http://soy.se", "User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19") do |f|
|
24
|
+
word.hits = JSON.parse(f.read)['responseData']['cursor']['estimatedResultCount'].to_i
|
25
|
+
end
|
26
|
+
rescue OpenURI::HTTPError => e
|
27
|
+
result = e.io.status.first.to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
if word.hits.nil?
|
31
|
+
result = "Google returned HTTP Status #{result} ='/"
|
32
|
+
debug.log result + " on " + url
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if result.nil?
|
38
|
+
winner = [one, two].sort_by { |w| w.hits }.reverse.first
|
39
|
+
result = one.word + " (" + one.hits.to_s + ") vs. " + two.word + " (" + two.hits.to_s + "): WINNER: " + winner.word + "!"
|
40
|
+
response.reply result
|
41
|
+
else
|
42
|
+
log.error result, winner, one, two
|
43
|
+
response.reply "ohnoes, I fail = /"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
Lita.register_handler(Googlefight)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-googlefight"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["Simon Lundström"]
|
5
|
+
spec.email = ["simmel@soy.se"]
|
6
|
+
spec.description = "GoogleFight two terms: there can only be one winner."
|
7
|
+
spec.summary = "Fight to find out which has more hits on Google"
|
8
|
+
spec.homepage = "https://github.com/simmel/lita-googlefight"
|
9
|
+
spec.license = "ISC license"
|
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.3"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "pry-byebug"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rack-test"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "lita-googlefight"
|
2
|
+
require "lita/rspec"
|
3
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
4
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
5
|
+
Lita.version_3_compatibility_mode = false
|
6
|
+
|
7
|
+
describe Lita::Handlers::Googlefight, lita_handler: true do
|
8
|
+
|
9
|
+
it { is_expected.to route_command("!googlefight this;that").to(:googlefight) }
|
10
|
+
it { is_expected.to route_command("!gf 'another this';'another that'").to(:googlefight) }
|
11
|
+
|
12
|
+
it "google clearly is more popular than altavista nowadays" do
|
13
|
+
send_message("!googlefight google;altavista")
|
14
|
+
expect(replies.last).to match(/WINNER: google!$/)
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-googlefight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Lundström
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-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.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: 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: rack-test
|
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: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
description: 'GoogleFight two terms: there can only be one winner.'
|
98
|
+
email:
|
99
|
+
- simmel@soy.se
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/lita-googlefight.rb
|
110
|
+
- lita-googlefight.gemspec
|
111
|
+
- spec/googlefight_spec.rb
|
112
|
+
homepage: https://github.com/simmel/lita-googlefight
|
113
|
+
licenses:
|
114
|
+
- ISC license
|
115
|
+
metadata:
|
116
|
+
lita_plugin_type: handler
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.0.14
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Fight to find out which has more hits on Google
|
137
|
+
test_files:
|
138
|
+
- spec/googlefight_spec.rb
|