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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bd6e56b8e7824f68bd7ac7986630639c2390cc3
4
- data.tar.gz: 029801b8def9109f1bebb81596dc88e245baddc3
3
+ metadata.gz: a078977179fabc795d32224b634241e1626bdf99
4
+ data.tar.gz: 9fb064b4100378430cf6bb61ec2a43d68bbce462
5
5
  SHA512:
6
- metadata.gz: ba15cf937e98ce214145f2c52addb9214ab89d20548dd5f089a5dc171c59ff85fda04608c7b8d9c1a50b9f8481a131ac1a03d1d221a9a586baf81913d9b02ed6
7
- data.tar.gz: 0a421f4cb0ffaa6e41ce96e546ae96cd5aaa44b452c5359f3d521a201775d1d05019ebd0be99ca0578e5dcb91461e7cff4e89617aed4e5542273d3020430ed41
6
+ metadata.gz: 5002c3711cba6322a1fa72f19322b0a89c8c42cb85dcf430eb830c7e251f1a55328ca50e01f7b7c9ae3b88d1648c59112e202e3f957ec274c4283991b0b5701f
7
+ data.tar.gz: b38bfb700b90b3ac0f6ee66b78e708ec534a87ce624f76d485943100e336598f7828f22b4d6c82f93c2f45abf1f7ce730988c86e1bc9d82e8da88949c3d25451
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ notes.rb
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, incorporate pagination, complete API functionality and of course tests.
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 Game of Thrones')
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 single book
56
+ #### Find a specific House, must be complete house name. Will implement a fuzzy search in the future.
57
57
  ```
58
- GameOfThronesApi.find_house('targaryen')
58
+ GameOfThronesApi.find_house("House Targaryen of King's Landing")
59
59
  ```
60
60
 
61
61
  ## Contributing
@@ -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").parsed_response
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(filter)
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").parsed_response
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(filter)
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
- filter = name_query(filter) if filter
30
- get("#{BASE_ENDPOINT}/houses#{filter}").parsed_response
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
- filter = name_query(filter) if filter
35
- get("#{BASE_ENDPOINT}/houses#{filter}").parsed_response
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
@@ -1,3 +1,3 @@
1
1
  module GameOfThronesApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: game_of_thrones_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Tam