Hyrule-Compendium 2.0.1 → 3.0.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/lib/hyrule_compendium.rb +93 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e726e2598a53077e75749f3845280b41386921ae08d9d58785dedfc1d390e90
|
4
|
+
data.tar.gz: 335d8686b52ed78c8ea2a9595c7ef4729b82eafc636b9a3a53fc6df76936012b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b81886b6ea83a022362d92752d55ff962dda29abf66cab07d24c083e2d33c76b1e960a340ea2dc02d651a24337f47fece34c6c1ca1f5380e1734d8bee5b5b891
|
7
|
+
data.tar.gz: 599a5d2797a58970e66a67935468014951a40145f9867f23c018df5f172bc0773adb0ef99345d52c08f84bdfce36b076a1176fa76ccbe78fab65536b4bde89da
|
data/lib/hyrule_compendium.rb
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
require "json"
|
2
2
|
require "uri"
|
3
3
|
require "net/http"
|
4
|
+
require "open-uri"
|
5
|
+
|
6
|
+
class NoEntryError < StandardError
|
7
|
+
# Raised when a given entry does not exist in the compendium
|
8
|
+
#
|
9
|
+
# Parameters:
|
10
|
+
# * `target_entry`: Non-existant input entry that causes error.
|
11
|
+
# - type: str, int
|
12
|
+
|
13
|
+
def initialize(target_entry)
|
14
|
+
if target_entry.is_a? String
|
15
|
+
super "Entry with name '#{target_entry}' not in compendium."
|
16
|
+
elsif target_entry.is_a? Integer
|
17
|
+
super "Entry with ID '#{target_entry}' not in compendium."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NoCategoryError < StandardError
|
23
|
+
# Raised when a given category does not exist in the compendium
|
24
|
+
#
|
25
|
+
# Parameters:
|
26
|
+
# * `target_category`: Non-existant input category that causes error.
|
27
|
+
# - type: str
|
28
|
+
|
29
|
+
def initialize(target_category)
|
30
|
+
super "Category '#{target_category}' not in compendium. Categories are 'creatures', 'equipment', 'materials', 'monsters', and 'treaure'."
|
31
|
+
end
|
32
|
+
end
|
4
33
|
|
5
34
|
def make_req url
|
6
35
|
uri = URI url
|
@@ -8,23 +37,82 @@ def make_req url
|
|
8
37
|
req = Net::HTTP::Get.new uri
|
9
38
|
http.request req
|
10
39
|
end
|
11
|
-
return JSON.parse res.body
|
40
|
+
return (JSON.parse res.body)["data"]
|
12
41
|
end
|
13
42
|
|
14
43
|
class Hyrule_Compendium
|
15
|
-
|
16
|
-
|
44
|
+
# Base class for the Hyrule-Compendium
|
45
|
+
#
|
46
|
+
# Parameters:
|
47
|
+
# * `url`: The base URL of the API server
|
48
|
+
# - type: str
|
49
|
+
# - default: "http://botw-compendium.herokuapp.com/api/v2"
|
50
|
+
|
51
|
+
def initialize url="http://botw-compendium.herokuapp.com/api/v2"
|
52
|
+
@base = url
|
17
53
|
end
|
18
54
|
|
19
55
|
def get_entry entry
|
20
|
-
|
56
|
+
# Gets an entry from the compendium.
|
57
|
+
#
|
58
|
+
# Parameters:
|
59
|
+
# * `entry`: The ID or name of the entry to be retrieved.
|
60
|
+
# - type: str, int
|
61
|
+
#
|
62
|
+
# Returns: The entry's metadata.
|
63
|
+
# type: hash
|
64
|
+
#
|
65
|
+
# Raises:
|
66
|
+
# * `NoEntryError` when the entry is not found.
|
67
|
+
|
68
|
+
res = make_req "#{@base}/entry/#{entry.to_s.gsub " ", "%20"}"
|
69
|
+
if res == {}
|
70
|
+
raise NoEntryError.new entry
|
71
|
+
end
|
72
|
+
return res
|
21
73
|
end
|
22
74
|
|
23
75
|
def get_category category
|
24
|
-
|
76
|
+
# Gets all entries from a category in the compendium.
|
77
|
+
#
|
78
|
+
# Parameters:
|
79
|
+
# * `category`: The name of the category to be retrieved. Must be one of the compendium categories.
|
80
|
+
# - type: string
|
81
|
+
# - notes:
|
82
|
+
# * must be "creatures", "equipment", "materials", "monsters", or "treasure"
|
83
|
+
# * the category "creatures" has two sub-categories, as keys: "food" and "non_food"
|
84
|
+
#
|
85
|
+
# Raises:
|
86
|
+
# * `NoCategoryError` when the category is not found.
|
87
|
+
|
88
|
+
if !(["creatures", "equipment", "materials", "monsters", "treasure"].include? category)
|
89
|
+
raise NoCategoryError.new category
|
90
|
+
end
|
91
|
+
return make_req "#{@base}/category/#{category}"
|
25
92
|
end
|
26
93
|
|
27
94
|
def get_all
|
95
|
+
# Gets all entries from the compendium.
|
96
|
+
#
|
97
|
+
# Returns: all items in the compendium with their metadata, nested in categories.
|
98
|
+
# type: hash
|
99
|
+
|
28
100
|
return make_req @base
|
29
101
|
end
|
102
|
+
|
103
|
+
def download_entry_image entry, output_file
|
104
|
+
# Downloads the image of a compendium entry.
|
105
|
+
#
|
106
|
+
# Parameters:
|
107
|
+
# * `entry`: The ID or name of the entry of the image to be downloaded.
|
108
|
+
# - type: str, int
|
109
|
+
# * `output_file`: The output file's path.
|
110
|
+
# - type: str
|
111
|
+
|
112
|
+
open (get_entry entry)["image"] do |image|
|
113
|
+
File.open output_file, "wb" do |file|
|
114
|
+
file.write image.read
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
30
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Hyrule-Compendium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aarav Borthakur
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: The official ruby wrapper for the Hyrule Compendium API
|
14
14
|
email: gadhaguy13@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|