ketchum 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ketchum-0.1.1.gem +0 -0
- data/lib/ketchum.rb +1 -49
- data/lib/ketchum/client.rb +51 -0
- data/lib/ketchum/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03cb4ea08c57f53d3c37efa1572f27afb7f1e968
|
4
|
+
data.tar.gz: abe626ee01e1f903679c6ba7fd4631fcd93f17a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 731eed35c73d4d77392f4e57c55f529c1c50b00d19e3d74445a0f3258591f95eb57abdfec8d33db9053d568b2ef1a27ed906d9997fe857931165724cd1dbedb9
|
7
|
+
data.tar.gz: e6998e3579230a5a641a7428ff970e13be9b45d845dded78adf9e12e22a670629c040e198ce302cdc912c8f58afe4559862aad3156e98c938ce216b05491aa3f
|
data/ketchum-0.1.1.gem
ADDED
Binary file
|
data/lib/ketchum.rb
CHANGED
@@ -1,50 +1,2 @@
|
|
1
|
+
require 'ketchum/client'
|
1
2
|
require 'ketchum/version'
|
2
|
-
|
3
|
-
require 'rest-client'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
class Ketchum
|
7
|
-
BASE_URL = 'http://pokeapi.co/api/v2/'
|
8
|
-
|
9
|
-
RESOURCES = [
|
10
|
-
'ability', 'berry', 'berry_firmness', 'berry_flavor', 'characteristic',
|
11
|
-
'contest_effect', 'contest_type', 'egg_group', 'encounter_condition',
|
12
|
-
'encounter_condition_value', 'encounter_method', 'evolution_chain',
|
13
|
-
'evolution_trigger', 'gender', 'generation', 'growth_rate', 'item',
|
14
|
-
'item_attribute', 'item_category', 'item_fling_effect', 'item_pocket',
|
15
|
-
'language', 'location', 'location_area', 'move', 'move_ailment',
|
16
|
-
'move_battle_style', 'move_category', 'move_damage_class',
|
17
|
-
'move_learn_method', 'move_target', 'nature', 'pal_park_area',
|
18
|
-
'pokeathlon_stat', 'pokedex', 'pokemon', 'pokemon_color', 'pokemon_form',
|
19
|
-
'pokemon_shape', 'pokemon_species', 'region', 'stat',
|
20
|
-
'super_contest_effect', 'type', 'version', 'version_group'
|
21
|
-
]
|
22
|
-
|
23
|
-
def initialize(format = :json)
|
24
|
-
@format = format
|
25
|
-
end
|
26
|
-
|
27
|
-
def method_missing(method, *args)
|
28
|
-
if RESOURCES.include? method.to_s
|
29
|
-
method = hyphenate(method.to_s)
|
30
|
-
get(method.to_s, args[0], args[1])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def get(resource, id = '', format = @format)
|
37
|
-
url = "#{BASE_URL}#{resource}/#{id}"
|
38
|
-
response = RestClient.get(url)
|
39
|
-
if format == :hash
|
40
|
-
response = JSON.parse(response)
|
41
|
-
elsif format == :ostruct
|
42
|
-
response = OpenStruct.new(JSON.parse(response))
|
43
|
-
end
|
44
|
-
response
|
45
|
-
end
|
46
|
-
|
47
|
-
def hyphenate(resource)
|
48
|
-
resource.gsub('_', '-')
|
49
|
-
end
|
50
|
-
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Ketchum
|
6
|
+
class Client
|
7
|
+
BASE_URL = 'http://pokeapi.co/api/v2/'
|
8
|
+
|
9
|
+
RESOURCES = [
|
10
|
+
'ability', 'berry', 'berry_firmness', 'berry_flavor', 'characteristic',
|
11
|
+
'contest_effect', 'contest_type', 'egg_group', 'encounter_condition',
|
12
|
+
'encounter_condition_value', 'encounter_method', 'evolution_chain',
|
13
|
+
'evolution_trigger', 'gender', 'generation', 'growth_rate', 'item',
|
14
|
+
'item_attribute', 'item_category', 'item_fling_effect', 'item_pocket',
|
15
|
+
'language', 'location', 'location_area', 'move', 'move_ailment',
|
16
|
+
'move_battle_style', 'move_category', 'move_damage_class',
|
17
|
+
'move_learn_method', 'move_target', 'nature', 'pal_park_area',
|
18
|
+
'pokeathlon_stat', 'pokedex', 'pokemon', 'pokemon_color', 'pokemon_form',
|
19
|
+
'pokemon_shape', 'pokemon_species', 'region', 'stat',
|
20
|
+
'super_contest_effect', 'type', 'version', 'version_group'
|
21
|
+
]
|
22
|
+
|
23
|
+
def initialize(format = :json)
|
24
|
+
@format = format
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(method, *args)
|
28
|
+
if RESOURCES.include? method.to_s
|
29
|
+
method = hyphenate(method.to_s)
|
30
|
+
get(method.to_s, args[0], args[1])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def get(resource, id = '', format = @format)
|
37
|
+
url = "#{BASE_URL}#{resource}/#{id}"
|
38
|
+
response = RestClient.get(url)
|
39
|
+
if format == :hash
|
40
|
+
response = JSON.parse(response)
|
41
|
+
elsif format == :ostruct
|
42
|
+
response = OpenStruct.new(JSON.parse(response))
|
43
|
+
end
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
def hyphenate(resource)
|
48
|
+
resource.gsub('_', '-')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/ketchum/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ketchum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Miles
|
@@ -81,8 +81,10 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- bin/console
|
83
83
|
- bin/setup
|
84
|
+
- ketchum-0.1.1.gem
|
84
85
|
- ketchum.gemspec
|
85
86
|
- lib/ketchum.rb
|
87
|
+
- lib/ketchum/client.rb
|
86
88
|
- lib/ketchum/version.rb
|
87
89
|
homepage: https://github.com/christophermiles9/ketchum
|
88
90
|
licenses:
|