lita-google 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: 853d6f1983dc2bee474a44394f7be35a6a41c71c
4
+ data.tar.gz: 31d04ff13025b6a88d4297f81dca5f05f4020751
5
+ SHA512:
6
+ metadata.gz: 942940eff9b48227b6e3aa99e82461ab8a1a2d0fbeebdead7c82e37de42578efc255957ec78b4d88ab187fdaee90dd5fa328d5caadc7b3687779bc568c4e0ece
7
+ data.tar.gz: 29da7f4437619c6d0541b263a746528b2065c27e9e67829000fbb1883a2bd499982f4f5c96dde9e847cb3bbc21870e5bfc85762ab9752cd7999926186fe4476d
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -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 Jimmy Cuadra
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # lita-google
2
+
3
+ [![Build Status](https://travis-ci.org/jimmycuadra/lita-google.png?branch=master)](https://travis-ci.org/jimmycuadra/lita-google)
4
+ [![Code Climate](https://codeclimate.com/github/jimmycuadra/lita-google.png)](https://codeclimate.com/github/jimmycuadra/lita-google)
5
+ [![Coverage Status](https://coveralls.io/repos/jimmycuadra/lita-google/badge.png)](https://coveralls.io/r/jimmycuadra/lita-google)
6
+
7
+ **lita-google** is a handler for [Lita](http://lita.io/) that searches Google and replies with the first link.
8
+
9
+ ## Installation
10
+
11
+ Add lita-google to your Lita instance's Gemfile:
12
+
13
+ ``` ruby
14
+ gem "lita-google"
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ ### Optional attributes
20
+
21
+ * `safe_search` (String, Symbol) - The safe search setting to use. Possible values are `:active`, `:moderate`, and `:off`. Default: `:active`.
22
+
23
+ ### Example
24
+
25
+ ```
26
+ Lita.configure do |config|
27
+ config.handlers.google.safe_search = :off
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```
34
+ You: Lita, google ruby
35
+ Lita: Ruby Programming Language - https://www.ruby-lang.org/
36
+ ```
37
+
38
+ ## License
39
+
40
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -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/google"
@@ -0,0 +1,54 @@
1
+ require "lita"
2
+
3
+ module Lita
4
+ module Handlers
5
+ class Google < Handler
6
+ URL = "https://ajax.googleapis.com/ajax/services/search/web"
7
+
8
+ route(/^google\s+(.+)/i, :search, command: true, help: {
9
+ "google QUERY" => "Return the first Google search result for QUERY."
10
+ })
11
+
12
+ def self.default_config(handler_config)
13
+ handler_config.safe_search = :active
14
+ end
15
+
16
+ def search(response)
17
+ query = response.matches[0][0]
18
+
19
+ http_response = http.get(
20
+ URL,
21
+ safe: safe_value,
22
+ q: query,
23
+ v: "1.0"
24
+ )
25
+
26
+ if http_response.status == 200
27
+ data = MultiJson.load(http_response.body)
28
+ result = data["responseData"]["results"].first
29
+
30
+ if result
31
+ response.reply("#{result["titleNoFormatting"]} - #{result["url"]}")
32
+ else
33
+ response.reply("No search results for query: #{query}")
34
+ end
35
+ else
36
+ Lita.logger.warn(
37
+ "Non-200 response from Google for search query: #{query}"
38
+ )
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def safe_value
45
+ safe = Lita.config.handlers.google.safe_search || "active"
46
+ safe = safe.to_s.downcase
47
+ safe = "active" unless ["active", "moderate", "off"].include?(safe)
48
+ safe
49
+ end
50
+ end
51
+
52
+ Lita.register_handler(Google)
53
+ end
54
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-google"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Jimmy Cuadra"]
5
+ spec.email = ["jimmy@jimmycuadra.com"]
6
+ spec.description = %q{A Lita handler for returning Google search results.}
7
+ spec.summary = %q{A Lita handler for returning Google search results.}
8
+ spec.homepage = "https://github.com/jimmycuadra/lita-google"
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{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.6"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rspec", ">= 2.14"
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "coveralls"
23
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Google, lita_handler: true do
4
+ it { routes_command("google ruby").to(:search) }
5
+ it { routes_command("google me ruby").to(:search) }
6
+
7
+ describe "#search" do
8
+ let(:response) do
9
+ response = double("Faraday::Response")
10
+ allow(response).to receive(:status).and_return(200)
11
+ response
12
+ end
13
+
14
+ before do
15
+ allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(
16
+ response
17
+ )
18
+ end
19
+
20
+ it "replies with the first title and URL for the query" do
21
+ allow(response).to receive(:body).and_return(
22
+ <<-JSON.chomp
23
+ {
24
+ "responseData": {
25
+ "results": [{
26
+ "url": "https://www.ruby-lang.org/",
27
+ "titleNoFormatting": "Ruby Programming Language"
28
+ }]
29
+ }
30
+ }
31
+ JSON
32
+ )
33
+
34
+ send_command("google ruby")
35
+
36
+ expect(replies.last).to eq(
37
+ "Ruby Programming Language - https://www.ruby-lang.org/"
38
+ )
39
+ end
40
+
41
+ it "replies that no results were found if the results are empty" do
42
+ allow(response).to receive(:body).and_return(
43
+ <<-JSON.chomp
44
+ {
45
+ "responseData": {
46
+ "results": []
47
+ }
48
+ }
49
+ JSON
50
+ )
51
+
52
+ send_command("google ruby")
53
+
54
+ expect(replies.last).to match(/No search results/)
55
+ end
56
+
57
+ it "logs a warning on non-200 response" do
58
+ allow(response).to receive(:status).and_return(500)
59
+
60
+ expect(Lita.logger).to receive(:warn).with(/Non-200 response from Google/)
61
+
62
+ send_command("google ruby")
63
+ end
64
+ end
65
+ 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-google"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-google
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jimmy Cuadra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-06 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: 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: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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: coveralls
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: A Lita handler for returning Google search results.
98
+ email:
99
+ - jimmy@jimmycuadra.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - lib/lita-google.rb
111
+ - lib/lita/handlers/google.rb
112
+ - lita-google.gemspec
113
+ - spec/lita/handlers/google_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: https://github.com/jimmycuadra/lita-google
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.1.11
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: A Lita handler for returning Google search results.
139
+ test_files:
140
+ - spec/lita/handlers/google_spec.rb
141
+ - spec/spec_helper.rb