pokedex 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +16 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/lib/pokedex.rb +34 -0
- data/lib/pokedex/area.rb +22 -0
- data/lib/pokedex/egg_group.rb +22 -0
- data/lib/pokedex/evolution_chain.rb +34 -0
- data/lib/pokedex/generation.rb +30 -0
- data/lib/pokedex/location.rb +24 -0
- data/lib/pokedex/modules_helper/description.rb +12 -0
- data/lib/pokedex/modules_helper/locale.rb +14 -0
- data/lib/pokedex/modules_helper/name.rb +18 -0
- data/lib/pokedex/pokemon.rb +55 -0
- data/lib/pokedex/region.rb +28 -0
- data/lib/pokedex/version.rb +6 -0
- data/lib/pokedex/version_group.rb +19 -0
- data/pokedex.gemspec +30 -0
- metadata +194 -0
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at daniel.romero.esteban@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Daniel Romero
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Pokedex
|
2
|
+
[![Build Status](https://travis-ci.org/danielRomero/pokedex.svg?branch=master)](https://travis-ci.org/danielRomero/pokedex)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/danielRomero/pokedex/badges/gpa.svg)](https://codeclimate.com/github/danielRomero/pokedex)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/danielRomero/pokedex/badges/coverage.svg)](https://codeclimate.com/github/danielRomero/pokedex/coverage)
|
5
|
+
|
6
|
+
Ruby wrapper for http://pokeapi.co Pokemon API.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'pokedex'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install pokedex
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
#### Available configuration
|
27
|
+
You can set different timeout. The http://pokeapi.co sometimes can be very slow.
|
28
|
+
```ruby
|
29
|
+
# application.rb
|
30
|
+
Pokedex.timeout = 30 # seconds
|
31
|
+
```
|
32
|
+
#### Methods
|
33
|
+
Example of Pokemon info
|
34
|
+
```
|
35
|
+
pokemon = Pokedex::Pokemon.find 1
|
36
|
+
pokemon.name 'zh' # Pokemon's name by locale
|
37
|
+
pokemon.evolution_chain
|
38
|
+
|
39
|
+
```
|
40
|
+
##### Resources Availables:
|
41
|
+
- Area: Location areas are sections of areas, such as floors in a building or cave. Each area has its own set of possible Pokémon encounters.
|
42
|
+
|
43
|
+
- EggGroup: Egg Groups are categories which determine which Pokémon are able to interbreed. Pokémon may belong to either one or two Egg Groups.
|
44
|
+
|
45
|
+
- EvolutionChain: Evolution chains are essentially family trees. They start with the lowest stage within a family and detail evolution conditions for each as well as Pokémon they can evolve into up through the hierarchy.
|
46
|
+
|
47
|
+
- Generation: A generation is a grouping of the Pokémon games that separates them based on the Pokémon they include.
|
48
|
+
|
49
|
+
- Location: Locations that can be visited within the games. Locations make up sizable portions of regions, like cities or routes.
|
50
|
+
|
51
|
+
- Pokemon: Pokémon are the creatures that inhabit the world of the Pokémon games. They can be caught using Pokéballs and trained by battling with other Pokémon.
|
52
|
+
|
53
|
+
- Region: A region is an organized area of the Pokémon world. Most often, the main difference between regions is the species of Pokémon that can be encountered within them.
|
54
|
+
|
55
|
+
- VersionGroup: Version groups categorize highly similar versions of the games.
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/danielromero/pokedex.
|
66
|
+
|
67
|
+
### Steps to contribute:
|
68
|
+
1. Open new issue https://github.com/danielRomero/pokedex/issues/new
|
69
|
+
2. Clone this repo to your local machine `git clone git@github.com:danielRomero/pokedex.git`
|
70
|
+
3. Checkout to new branch with issue ID as name `git checkout -b issue-1234`
|
71
|
+
4. Install dependencies `bundle install`
|
72
|
+
5. Test your changes `bundle exec rake spec`
|
73
|
+
6. Commit and push your branch and make new pull request https://github.com/danielRomero/pokedex/compare
|
74
|
+
7. If everything is ok, your changes will be included to the next version.
|
75
|
+
|
76
|
+
## TODO
|
77
|
+
|
78
|
+
1. Improve Tests
|
79
|
+
2. Cover all http://pokeapi.co resources & attributes
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/pokedex.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Pokedex
|
2
|
+
require 'pry' # only for debug
|
3
|
+
require 'awesome_print' # only for debug
|
4
|
+
|
5
|
+
require 'unirest' # for api requests
|
6
|
+
|
7
|
+
require 'pokedex/area'
|
8
|
+
require 'pokedex/egg_group'
|
9
|
+
require 'pokedex/evolution_chain'
|
10
|
+
require 'pokedex/generation'
|
11
|
+
require 'pokedex/location'
|
12
|
+
require 'pokedex/pokemon'
|
13
|
+
require 'pokedex/region'
|
14
|
+
require 'pokedex/version_group'
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def get resource_path, options = {}
|
19
|
+
Unirest.timeout(timeout)
|
20
|
+
url = "#{Pokedex::API_BASE_URL}/#{resource_path}"
|
21
|
+
puts "[Pokedex] request to #{url} -- timeout: #{timeout}"
|
22
|
+
response = Unirest.get(url, headers: {}, parameters: options[:params], auth: nil)
|
23
|
+
response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
def timeout=(timeout_value)
|
27
|
+
@@timeout = timeout_value
|
28
|
+
end
|
29
|
+
|
30
|
+
def timeout
|
31
|
+
@@timeout ||= Pokedex::DEFAULT_TIMEOUT
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/pokedex/area.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Pokedex
|
2
|
+
class Area
|
3
|
+
require 'pokedex/modules_helper/name'
|
4
|
+
include Pokedex::ModulesHelper::Name
|
5
|
+
|
6
|
+
attr_accessor :id, :names
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
@id = args['id']
|
10
|
+
extract_names args
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find id
|
14
|
+
new Pokedex.get "api/v2/location-area/#{id}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find_by_url url
|
18
|
+
new Pokedex.get URI.parse(url).path
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Pokedex
|
2
|
+
class EggGroup
|
3
|
+
require 'pokedex/modules_helper/name'
|
4
|
+
include Pokedex::ModulesHelper::Name
|
5
|
+
|
6
|
+
attr_accessor :id, :names, :pokemon_urls
|
7
|
+
|
8
|
+
def initialize(args = {})
|
9
|
+
@id = args['id']
|
10
|
+
@pokemon_urls = args['pokemon_species'].map{ |pokemon_specie| pokemon_specie['url'] }
|
11
|
+
extract_names args
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find id
|
15
|
+
new Pokedex.get "api/v2/egg-group/#{id}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_by_url url
|
19
|
+
new Pokedex.get URI.parse(url).path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Pokedex
|
2
|
+
class EvolutionChain
|
3
|
+
attr_accessor :id, :evolves
|
4
|
+
|
5
|
+
def initialize(args = {})
|
6
|
+
@id = args['id']
|
7
|
+
@evolves = [ generate_evolves(args['chain']) ]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.find id
|
11
|
+
new Pokedex.get "api/v2/evolution-chain/#{id}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find_by_url url
|
15
|
+
new Pokedex.get URI.parse(url).path
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_evolves(chain_args={}, evolves={})
|
21
|
+
return evolves if chain_args.empty? || chain_args.nil?
|
22
|
+
evolves[:pokemon] = chain_args['species'].nil? ?
|
23
|
+
nil :
|
24
|
+
Pokemon.find_by_url(chain_args['species']['url'])
|
25
|
+
evolves[:min_level] = chain_args['evolution_details'].nil? ?
|
26
|
+
nil :
|
27
|
+
chain_args['evolution_details']['min_level']
|
28
|
+
evolves[:evolves_to] = chain_args['evolves_to'].map{ |evolve|
|
29
|
+
generate_evolves(evolve)}
|
30
|
+
evolves
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Pokedex
|
2
|
+
class Generation
|
3
|
+
|
4
|
+
require 'pokedex/modules_helper/name'
|
5
|
+
include Pokedex::ModulesHelper::Name
|
6
|
+
|
7
|
+
attr_accessor :id, :region_url, :names, :pokemon_urls, :version_groups
|
8
|
+
|
9
|
+
def initialize(args={})
|
10
|
+
@id = args['id']
|
11
|
+
@pokemon_urls = args['pokemon_species'].map{ |pokemon_specie| pokemon_specie['url'] }
|
12
|
+
@version_groups = args['version_groups'].map{ |version_group| version_group['url'] }
|
13
|
+
@region_url = args['main_region']['url']
|
14
|
+
extract_names args
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find id
|
18
|
+
new Pokedex.get "api/v2/generation/#{id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_by_url url
|
22
|
+
new Pokedex.get URI.parse(url).path
|
23
|
+
end
|
24
|
+
|
25
|
+
def region
|
26
|
+
Region.find_by_url region_url
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Pokedex
|
2
|
+
class Location
|
3
|
+
require 'pokedex/modules_helper/name'
|
4
|
+
include Pokedex::ModulesHelper::Name
|
5
|
+
|
6
|
+
attr_accessor :id, :names, :region, :areas
|
7
|
+
|
8
|
+
def initialize(args = {})
|
9
|
+
@id = args['id']
|
10
|
+
@region = Region.find_by_url args['region']['url']
|
11
|
+
@areas = args['areas'].map{ |area| Area.find_by_url area['url'] }
|
12
|
+
extract_names args
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find id
|
16
|
+
new Pokedex.get "api/v2/location/#{id}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_by_url url
|
20
|
+
new Pokedex.get URI.parse(url).path
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pokedex
|
2
|
+
module ModulesHelper
|
3
|
+
module Locale
|
4
|
+
# extract elem from array of hashes depends of locale
|
5
|
+
# array => [{elem: 'translation', locale: 'en'}, {elem: 'traduccion', locale: 'es'}]
|
6
|
+
# locale => 'es', 'en', 'it'...
|
7
|
+
# elem => :name, :description, :genus...
|
8
|
+
def extract_locale(array, locale, elem)
|
9
|
+
n = array.find{ |e| e[:locale] == locale.to_s }
|
10
|
+
n ? n[elem] : ''
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Pokedex
|
2
|
+
module ModulesHelper
|
3
|
+
module Name
|
4
|
+
require 'pokedex/modules_helper/locale'
|
5
|
+
include Pokedex::ModulesHelper::Locale
|
6
|
+
|
7
|
+
def name(locale='es')
|
8
|
+
extract_locale names, locale, :name
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def extract_names(args={})
|
14
|
+
@names = args['names'].map{ |name| {name: name['name'], locale: name['language']['name']} }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Pokedex
|
2
|
+
class Pokemon
|
3
|
+
require 'pokedex/modules_helper/name'
|
4
|
+
include Pokedex::ModulesHelper::Name
|
5
|
+
require 'pokedex/modules_helper/description'
|
6
|
+
include Pokedex::ModulesHelper::Description
|
7
|
+
|
8
|
+
attr_accessor :id, :sprite, :capture_rate, :names, :descriptions, :evolution_chain_url, :is_baby, :generas, :egg_groups, :generation_name
|
9
|
+
|
10
|
+
def initialize(args={})
|
11
|
+
@id = args['id']
|
12
|
+
@generas = args['genera'].map{ |genera| { genus: genera['genus'], locale: genera['language']['name']} }
|
13
|
+
@descriptions = get_descriptions args['flavor_text_entries']
|
14
|
+
@is_baby = args['is_baby']
|
15
|
+
@sprite = "#{Pokedex::API_BASE_URL}/media/img/#{args['id']}.png"
|
16
|
+
@capture_rate = args['capture_rate']
|
17
|
+
@evolution_chain_url = args['evolution_chain']['url']
|
18
|
+
@egg_groups = args['egg_groups'].map{ |egg_groups| EggGroup.find_by_url egg_groups['url'] }
|
19
|
+
@generation_name = args['generation']['name']
|
20
|
+
extract_names args
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find id
|
24
|
+
new Pokedex.get "api/v2/pokemon-species/#{id}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_by_url url
|
28
|
+
new Pokedex.get URI.parse(url).path
|
29
|
+
end
|
30
|
+
|
31
|
+
def genera locale='es'
|
32
|
+
extract_locale generas, locale, :genus
|
33
|
+
end
|
34
|
+
|
35
|
+
def evolution_chain
|
36
|
+
EvolutionChain.find_by_url evolution_chain_url
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# return the first description by locale from API response
|
42
|
+
def get_descriptions text_entries
|
43
|
+
checked_locales = []
|
44
|
+
text_entries.map{ |text_entry|
|
45
|
+
if checked_locales.include?(text_entry['language']['name'])
|
46
|
+
nil
|
47
|
+
else
|
48
|
+
checked_locales << text_entry['language']['name']
|
49
|
+
{ locale: text_entry['language']['name'], description: text_entry['flavor_text'] }
|
50
|
+
end
|
51
|
+
}.compact
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|