game_of_thrones_api 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +4 -4
- data/lib/game_of_thrones_api.rb +32 -8
- data/lib/game_of_thrones_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a078977179fabc795d32224b634241e1626bdf99
|
4
|
+
data.tar.gz: 9fb064b4100378430cf6bb61ec2a43d68bbce462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5002c3711cba6322a1fa72f19322b0a89c8c42cb85dcf430eb830c7e251f1a55328ca50e01f7b7c9ae3b88d1648c59112e202e3f957ec274c4283991b0b5701f
|
7
|
+
data.tar.gz: b38bfb700b90b3ac0f6ee66b78e708ec534a87ce624f76d485943100e336598f7828f22b4d6c82f93c2f45abf1f7ce730988c86e1bc9d82e8da88949c3d25451
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ API Wrapper using [An API Of Ice And Fire](https://anapioficeandfire.com/)
|
|
6
6
|
|
7
7
|
Still In developement. Basic Functionality. Find Books, Characters and Houses.
|
8
8
|
|
9
|
-
##### TODO: Better filtering,
|
9
|
+
##### TODO: Better filtering, fuzzy find for houses, complete API functionality and of course tests.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -35,7 +35,7 @@ GameOfThronesApi.get_books
|
|
35
35
|
|
36
36
|
#### Find a single book
|
37
37
|
```
|
38
|
-
GameOfThronesApi.find_book('A
|
38
|
+
GameOfThronesApi.find_book('A Dance with Dragons')
|
39
39
|
```
|
40
40
|
|
41
41
|
#### Retrieve Characters
|
@@ -53,9 +53,9 @@ GameOfThronesApi.find_book('Jon Snow')
|
|
53
53
|
GameOfThronesApi.get_houses
|
54
54
|
```
|
55
55
|
|
56
|
-
#### Find a
|
56
|
+
#### Find a specific House, must be complete house name. Will implement a fuzzy search in the future.
|
57
57
|
```
|
58
|
-
GameOfThronesApi.find_house('
|
58
|
+
GameOfThronesApi.find_house("House Targaryen of King's Landing")
|
59
59
|
```
|
60
60
|
|
61
61
|
## Contributing
|
data/lib/game_of_thrones_api.rb
CHANGED
@@ -8,31 +8,39 @@ module GameOfThronesApi
|
|
8
8
|
BASE_ENDPOINT = "http://anapioficeandfire.com/api"
|
9
9
|
|
10
10
|
def self.get_books
|
11
|
-
get("#{BASE_ENDPOINT}/books")
|
11
|
+
response = get("#{BASE_ENDPOINT}/books?page=1&pageSize=50")
|
12
|
+
total_pages = get_page_count(response)
|
13
|
+
|
14
|
+
get_all_records('books', response, total_pages)
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.find_book(name)
|
15
|
-
name = name_query(
|
18
|
+
name = name_query(name)
|
16
19
|
get("#{BASE_ENDPOINT}/books#{name}").parsed_response
|
17
20
|
end
|
18
21
|
|
19
22
|
def self.get_characters
|
20
|
-
get("#{BASE_ENDPOINT}/characters")
|
23
|
+
response = get("#{BASE_ENDPOINT}/characters?page=1&pageSize=50")
|
24
|
+
total_pages = get_page_count(response)
|
25
|
+
|
26
|
+
get_all_records('characters', response, total_pages)
|
21
27
|
end
|
22
28
|
|
23
29
|
def self.find_character(name)
|
24
|
-
name = name_query(
|
30
|
+
name = name_query(name)
|
25
31
|
get("#{BASE_ENDPOINT}/characters#{name}").parsed_response
|
26
32
|
end
|
27
33
|
|
28
34
|
def self.get_houses
|
29
|
-
|
30
|
-
|
35
|
+
response = get("#{BASE_ENDPOINT}/houses?page=1&pageSize=50")
|
36
|
+
total_pages = get_page_count(response)
|
37
|
+
|
38
|
+
get_all_records('houses', response, total_pages)
|
31
39
|
end
|
32
40
|
|
33
41
|
def self.find_house(name)
|
34
|
-
|
35
|
-
get("#{BASE_ENDPOINT}/houses#{
|
42
|
+
name = name_query(name)
|
43
|
+
get("#{BASE_ENDPOINT}/houses#{name}").parsed_response
|
36
44
|
end
|
37
45
|
|
38
46
|
module_function
|
@@ -44,4 +52,20 @@ module GameOfThronesApi
|
|
44
52
|
def uri_escape(term)
|
45
53
|
term.gsub(' ', '%20')
|
46
54
|
end
|
55
|
+
|
56
|
+
def get_page_count(response)
|
57
|
+
page_links = response.headers['link'].scan(/<(\S+)>/).flatten
|
58
|
+
/\?page\=(\d+)\&/.match(page_links.last)[1].to_i
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_all_records(category, response, total_pages, page = 1)
|
62
|
+
characters = response.parsed_response
|
63
|
+
|
64
|
+
while total_pages >= page
|
65
|
+
page += 1
|
66
|
+
characters += get("#{BASE_ENDPOINT}/#{category}?page=#{page}&pageSize=50").parsed_response
|
67
|
+
end
|
68
|
+
|
69
|
+
characters
|
70
|
+
end
|
47
71
|
end
|