Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JJ Asghar
committed
Jun 18, 2015
0 parents
commit d50efdb
Showing
12 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
language: ruby | ||
rvm: | ||
- 2.0.0 | ||
script: bundle exec rake | ||
before_install: | ||
- gem update --system | ||
services: | ||
- redis-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# lita-pokemon | ||
|
||
[![Build Status](https://travis-ci.org/jjasghar/lita-pokemon.png?branch=master)](https://travis-ci.org/jjasghar/lita-pokemon) | ||
[![Coverage Status](https://coveralls.io/repos/jjasghar/lita-pokemon/badge.png)](https://coveralls.io/r/jjasghar/lita-pokemon) | ||
|
||
TODO: Add a description of the plugin. | ||
|
||
## Installation | ||
|
||
Add lita-pokemon to your Lita instance's Gemfile: | ||
|
||
``` ruby | ||
gem "lita-pokemon" | ||
``` | ||
|
||
## Configuration | ||
|
||
TODO: Describe any configuration attributes the plugin exposes. | ||
|
||
## Usage | ||
|
||
TODO: Describe the plugin's features and how to use them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "lita" | ||
|
||
Lita.load_locales Dir[File.expand_path( | ||
File.join("..", "..", "locales", "*.yml"), __FILE__ | ||
)] | ||
|
||
require "lita/handlers/pokemon" | ||
|
||
Lita::Handlers::Pokemon.template_root File.expand_path( | ||
File.join("..", "..", "templates"), | ||
__FILE__ | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Lita | ||
module Handlers | ||
class Pokemon < Handler | ||
|
||
route(/^throw a pokeball!$/i, :throw, command: false, help: { "throw a pokeball!" => "Gets a random pokemon and names it.."} ) | ||
route(/^pokemon\s+(.+)$/i, :search, command: false, help: { "pokemon <number>" => "Gets a specific pokemon via the National pokedex and gives some stats"} ) | ||
|
||
def throw(request) | ||
random_number = rand(001..778) | ||
name = get_pokemon(random_number) | ||
request.reply "http://assets14.pokemon.com/assets/cms2/img/pokedex/detail/#{random_number}.png" | ||
request.reply "I choose you #{name}!" | ||
end | ||
|
||
def search(request) | ||
pokemon_number = request.matches[0][0] | ||
if pokemon_number.to_i > 778 | ||
request.reply "You've picked a too high of a pokedex number!" | ||
else | ||
name = get_pokemon(pokemon_number) | ||
request.reply "http://assets14.pokemon.com/assets/cms2/img/pokedex/detail/#{pokemon_number}.png" | ||
request.reply "I choose you #{name}!" | ||
end | ||
end | ||
|
||
def get_pokemon(pokemon_number) | ||
url = "http://pokeapi.co/api/v1/pokemon/#{pokemon_number}/" | ||
http_response = http.get(url) | ||
data = MultiJson.load(http_response.body) | ||
name = data["name"] | ||
# pkdx_id = data["pkdx_id"] | ||
# sp_atk = data["sp_atk"] | ||
# sp_def = data["sp_def"] | ||
# speed = data["speed"] | ||
# attack = data["attack"] | ||
# defense = data["defense"] | ||
end | ||
end | ||
|
||
Lita.register_handler(Pokemon) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = "lita-pokemon" | ||
spec.version = "0.1.0" | ||
spec.authors = ["JJ Asghar"] | ||
spec.email = ["jj@getchef.com"] | ||
spec.description = "TODO: Add a description" | ||
spec.summary = "TODO: Add a summary" | ||
spec.homepage = "TODO: Add a homepage" | ||
spec.license = "TODO: Add a license" | ||
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.3" | ||
|
||
spec.add_development_dependency "bundler", "~> 1.3" | ||
spec.add_development_dependency "pry-byebug" | ||
spec.add_development_dependency "rake" | ||
spec.add_development_dependency "rack-test" | ||
spec.add_development_dependency "rspec", ">= 3.0.0" | ||
spec.add_development_dependency "simplecov" | ||
spec.add_development_dependency "coveralls" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
en: | ||
lita: | ||
handlers: | ||
pokemon: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "spec_helper" | ||
|
||
describe Lita::Handlers::Pokemon, lita_handler: true do | ||
|
||
it { is_expected.to route("throw a pokeball!") } | ||
it { is_expected.to route("pokemon 25") } | ||
it { is_expected.to route("pokemon 44") } | ||
it { is_expected.not_to route("throw a pokeball") } | ||
|
||
# it "should respond with a random pokemon name" do | ||
# send_message("throw a pokeball!") | ||
# name = get_random_pokemon(25) | ||
# expect(replies.last).to eq("I choose you Pikachu!") | ||
# end | ||
|
||
it "should respond with a Pikachu" do | ||
send_message("pokemon 25") | ||
expect(replies.last).to eq("I choose you Pikachu!") | ||
end | ||
|
||
it "should respond with a Gloom" do | ||
send_message("pokemon 044") | ||
expect(replies.last).to eq("I choose you Gloom!") | ||
end | ||
|
||
it "should respond with an semi-too large error" do | ||
send_message("pokemon 779") | ||
expect(replies.last).to eq("You've picked a too high of a pokedex number!") | ||
end | ||
|
||
it "should respond with an too large error" do | ||
send_message("pokemon 800") | ||
expect(replies.last).to eq("You've picked a too high of a pokedex number!") | ||
end | ||
|
||
it "should respond with an non number error" do | ||
send_message("pokemon pokemon") | ||
expect(replies.last).to eq("You've picked a non-number for the pokedex!") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "simplecov" | ||
require "coveralls" | ||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ | ||
SimpleCov::Formatter::HTMLFormatter, | ||
Coveralls::SimpleCov::Formatter | ||
] | ||
SimpleCov.start { add_filter "/spec/" } | ||
|
||
require "lita-pokemon" | ||
require "lita/rspec" | ||
|
||
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin | ||
# was generated with Lita 4, the compatibility mode should be left disabled. | ||
Lita.version_3_compatibility_mode = false |
Empty file.