Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ Asghar committed Jun 18, 2015
0 parents commit d50efdb
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -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
8 changes: 8 additions & 0 deletions .travis.yml
@@ -0,0 +1,8 @@
language: ruby
rvm:
- 2.0.0
script: bundle exec rake
before_install:
- gem update --system
services:
- redis-server
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
22 changes: 22 additions & 0 deletions README.md
@@ -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.
6 changes: 6 additions & 0 deletions Rakefile
@@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

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

task default: :spec
12 changes: 12 additions & 0 deletions lib/lita-pokemon.rb
@@ -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__
)
42 changes: 42 additions & 0 deletions lib/lita/handlers/pokemon.rb
@@ -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
26 changes: 26 additions & 0 deletions lita-pokemon.gemspec
@@ -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
4 changes: 4 additions & 0 deletions locales/en.yml
@@ -0,0 +1,4 @@
en:
lita:
handlers:
pokemon:
40 changes: 40 additions & 0 deletions spec/lita/handlers/pokemon_spec.rb
@@ -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
14 changes: 14 additions & 0 deletions spec/spec_helper.rb
@@ -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 added templates/.gitkeep
Empty file.

0 comments on commit d50efdb

Please sign in to comment.