Skip to content

Commit

Permalink
Check it yo
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Jan 16, 2017
0 parents commit abf3b4e
Show file tree
Hide file tree
Showing 12 changed files with 888 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
.idea
lita_config.rb
bin
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: ruby
rvm:
- 2.2.6
- 2.3.3
script: bundle exec rake
before_install:
- gem update --system
services:
- redis-server
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gemspec
20 changes: 20 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
lita-onewheel-duckduckgo
--------------------

[![Build Status](https://travis-ci.org/onewheelskyward/lita-onewheel-duckduckgo.png?branch=master)](https://travis-ci.org/onewheelskyward/lita-onewheel-duckduckgo)
[![Coverage Status](https://coveralls.io/repos/onewheelskyward/lita-onewheel-duckduckgo/badge.png)](https://coveralls.io/r/onewheelskyward/lita-onewheel-duckduckgo)

Queries the Duck Duck Go Answers api for things.

Installation
------------
Add lita-onewheel-duckduckgo to your Lita instance's Gemfile:

``` ruby
gem "lita-onewheel-duckduckgo"
```

Usage
-----

!duck go
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :spec
3 changes: 3 additions & 0 deletions lib/lita-onewheel-duckduckgo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'lita'

require 'lita/handlers/onewheel_duckduckgo'
25 changes: 25 additions & 0 deletions lib/lita/handlers/onewheel_duckduckgo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rest-client'

module Lita
module Handlers
class OnewheelDuckDuckGo < Handler
route /^duck\s+(.*)$/, :search, command: true

def search(response)
query = response.matches[0][0]
Lita.logger.debug "Querying for #{query}"
result = get_result(query)
Lita.logger.debug "Result: #{result}"
reply = "DuckDuckGo Result: #{result['Abstract'][0..250]}"
Lita.logger.debug "Reply: #{reply}"
response.reply reply
end

def get_result(query)
result = RestClient.get("http://api.duckduckgo.com/?q=#{query}&format=json")
end

Lita.register_handler(self)
end
end
end
26 changes: 26 additions & 0 deletions lita-onewheel-duckduckgo.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-duckduckgo'
spec.version = '0.0.0'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = 'Lita handler for Duck Duck Go\'s answers engine.'
spec.summary = 'Duck Duck Goose'
spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-duckduckgo'
spec.license = 'MIT'
spec.metadata = { 'lita_plugin_type' => 'handler' }

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'lita', '~> 4'
spec.add_runtime_dependency 'rest-client', '~> 1'

spec.add_development_dependency 'bundler', '~> 1'
spec.add_development_dependency 'rake', '~> 10'
spec.add_development_dependency 'rack-test', '~> 0.6'
spec.add_development_dependency 'rspec', '~> 3'
spec.add_development_dependency 'simplecov', '~> 0.10'
spec.add_development_dependency 'coveralls', '~> 0.8'
end
221 changes: 221 additions & 0 deletions spec/fixtures/mock_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"DefinitionSource": "",
"Heading": "DuckDuckGo",
"ImageWidth": 340,
"RelatedTopics": [
{
"Result": "<a href=\"https://duckduckgo.com/Names_Database\">Names Database</a> - The Names Database is a partially defunct social network, owned and operated by Classmates.com, a wholly owned subsidiary of United Online. The site does not appear to be significantly updated since 2008, and has many broken links and display issues.",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/Names_Database",
"Text": "Names Database - The Names Database is a partially defunct social network, owned and operated by Classmates.com, a wholly owned subsidiary of United Online. The site does not appear to be significantly updated since 2008, and has many broken links and display issues."
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Companies_based_in_Chester_County%2C_Pennsylvania\">Companies based in Chester County, Pennsylvania</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Companies_based_in_Chester_County%2C_Pennsylvania",
"Text": "Companies based in Chester County, Pennsylvania"
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Tor_hidden_services\">Tor hidden services</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Tor_hidden_services",
"Text": "Tor hidden services"
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Internet_privacy_software\">Internet privacy software</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Internet_privacy_software",
"Text": "Internet privacy software"
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Perl_software\">Perl software</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Perl_software",
"Text": "Perl software"
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Proprietary_cross-platform_software\">Proprietary cross-platform software</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Proprietary_cross-platform_software",
"Text": "Proprietary cross-platform software"
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Internet_search_engines\">Internet search engines</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Internet_search_engines",
"Text": "Internet search engines"
},
{
"Result": "<a href=\"https://duckduckgo.com/c/Android_(operating_system)_software\">Android (operating system) software</a>",
"Icon": {
"URL": "",
"Height": "",
"Width": ""
},
"FirstURL": "https://duckduckgo.com/c/Android_(operating_system)_software",
"Text": "Android (operating system) software"
}
],
"Entity": "website",
"meta": {
"maintainer": {
"github": "duckduckgo"
},
"perl_module": "DDG::Fathead::Wikipedia",
"status": "live",
"production_state": "online",
"dev_date": null,
"js_callback_name": "wikipedia",
"signal_from": "wikipedia_fathead",
"live_date": null,
"src_id": 1,
"src_options": {
"skip_end": "0",
"skip_abstract": 0,
"skip_qr": "",
"language": "en",
"skip_icon": 0,
"skip_image_name": 0,
"directory": "",
"min_abstract_length": "20",
"skip_abstract_paren": 0,
"is_wikipedia": 1,
"source_skip": "",
"is_fanon": 0,
"is_mediawiki": 1,
"src_info": ""
},
"repo": "fathead",
"developer": [
{
"url": "http://www.duckduckhack.com",
"name": "DDG Team",
"type": "ddg"
}
],
"tab": "About",
"producer": null,
"unsafe": 0,
"id": "wikipedia_fathead",
"dev_milestone": "live",
"topic": [
"productivity"
],
"name": "Wikipedia",
"attribution": null,
"created_date": null,
"example_query": "nikola tesla",
"description": "Wikipedia",
"is_stackexchange": null,
"designer": null,
"src_domain": "en.wikipedia.org",
"src_name": "Wikipedia",
"blockgroup": null,
"src_url": null
},
"Type": "A",
"Redirect": "",
"DefinitionURL": "",
"AbstractURL": "https://en.wikipedia.org/wiki/DuckDuckGo",
"Definition": "",
"AbstractSource": "Wikipedia",
"Infobox": {
"content": [
{
"data_type": "string",
"sort_order": "1",
"value": "The search engine that doesn't track you.",
"label": "Slogan",
"wiki_order": 1
},
{
"data_type": "string",
"sort_order": "1",
"value": "Web search engine",
"label": "Type of site",
"wiki_order": 3
},
{
"data_type": "string",
"sort_order": "2",
"value": "DuckDuckGo, Inc.",
"label": "Owner",
"wiki_order": 7
},
{
"data_type": "string",
"sort_order": "3",
"value": "Gabriel Weinberg",
"label": "Created by",
"wiki_order": 8
},
{
"data_type": "string",
"sort_order": "3",
"value": "September 25, 2008",
"label": "Launched",
"wiki_order": 9
},
{
"data_type": "string",
"sort_order": "4",
"value": "560 (December 16, 2016)",
"label": "Alexa rank",
"wiki_order": 10
}
],
"meta": [
{
"data_type": "string",
"value": "DuckDuckGo",
"label": "article_title"
},
{
"data_type": "string",
"value": "infobox website",
"label": "template_name"
},
{
"data_type": "string",
"value": "website",
"label": "formatting_rules"
}
]
},
"Image": "https://duckduckgo.com/i/adad4e5c.png",
"ImageIsLogo": 1,
"Abstract": "DuckDuckGo is an Internet search engine that emphasizes protecting searchers' privacy and avoiding the filter bubble of personalized search results. DuckDuckGo distinguishes itself from other search engines by not profiling its users and by deliberately showing all users the same search results for a given search term. DuckDuckGo emphasizes getting information from the best sources rather than the most sources, generating its search results from key crowdsourced sites such as Wikipedia and from partnerships with other search engines like Yandex, Yahoo!, Bing, and Yummly.",
"AbstractText": "DuckDuckGo is an Internet search engine that emphasizes protecting searchers' privacy and avoiding the filter bubble of personalized search results. DuckDuckGo distinguishes itself from other search engines by not profiling its users and by deliberately showing all users the same search results for a given search term. DuckDuckGo emphasizes getting information from the best sources rather than the most sources, generating its search results from key crowdsourced sites such as Wikipedia and from partnerships with other search engines like Yandex, Yahoo!, Bing, and Yummly.",
"AnswerType": "",
"ImageHeight": 270,
"Answer": "",
"Results": []
}
Loading

0 comments on commit abf3b4e

Please sign in to comment.