Hyrule-Compendium 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hyrule_compendium.rb +36 -14
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e726e2598a53077e75749f3845280b41386921ae08d9d58785dedfc1d390e90
4
- data.tar.gz: 335d8686b52ed78c8ea2a9595c7ef4729b82eafc636b9a3a53fc6df76936012b
3
+ metadata.gz: 4c8ae2028d9a31146617fa11e95e440fcaf3c09deb62532cecc4285a1dabec7b
4
+ data.tar.gz: a3bfce310743fe6bd4879f1e4fdadf369c87459410b6767491bbc765c19b18ed
5
5
  SHA512:
6
- metadata.gz: b81886b6ea83a022362d92752d55ff962dda29abf66cab07d24c083e2d33c76b1e960a340ea2dc02d651a24337f47fece34c6c1ca1f5380e1734d8bee5b5b891
7
- data.tar.gz: 599a5d2797a58970e66a67935468014951a40145f9867f23c018df5f172bc0773adb0ef99345d52c08f84bdfce36b076a1176fa76ccbe78fab65536b4bde89da
6
+ metadata.gz: 49a53bd1239809009a0f74a09351b957b96498bf2c81d2ab62c4367e3d7a9a1e7bcb545450fc429c70a440d68c3e893d27666cdbe73064e40eb55fcb3ca5c9e0
7
+ data.tar.gz: 136f7deafe9023707740b4e371a29bf3efe4a7d5e9807dece28db3828a65486d1df7dbeaf02856205d62289f70f3f6ee633a18bf5d34d8310c254e386ff15bf7
@@ -31,9 +31,9 @@ class NoCategoryError < StandardError
31
31
  end
32
32
  end
33
33
 
34
- def make_req url
34
+ def make_req url, timeout
35
35
  uri = URI url
36
- res = Net::HTTP.start uri.host, uri.port do |http|
36
+ res = Net::HTTP.start uri.host, uri.port, read_timeout: timeout do |http|
37
37
  req = Net::HTTP::Get.new uri
38
38
  http.request req
39
39
  end
@@ -47,32 +47,40 @@ class Hyrule_Compendium
47
47
  # * `url`: The base URL of the API server
48
48
  # - type: str
49
49
  # - default: "http://botw-compendium.herokuapp.com/api/v2"
50
+ # * `default_timeout`: Default seconds to wait for response for all API calling functions until raising `Net::ReadTimeout`.
51
+ # - type: float, int
52
+ # - default: `nil` (no timeout)
53
+ # - notes: If a API calling function has a parameter `timeout`, it will overide this.
50
54
 
51
- def initialize url="http://botw-compendium.herokuapp.com/api/v2"
55
+ def initialize url: "http://botw-compendium.herokuapp.com/api/v2", default_timeout: nil
52
56
  @base = url
57
+ @default_timeout = default_timeout
53
58
  end
54
59
 
55
- def get_entry entry
60
+ def get_entry entry, timeout=@default_timeout
56
61
  # Gets an entry from the compendium.
57
62
  #
58
63
  # Parameters:
59
64
  # * `entry`: The ID or name of the entry to be retrieved.
60
65
  # - type: str, int
66
+ # * `timeout`: Seconds to wait for response until raising `Net::ReadTimeout`.
67
+ # - type: float, int
68
+ # - default: `@default_timeout`
61
69
  #
62
70
  # Returns: The entry's metadata.
63
- # type: hash
71
+ # - type: hash
64
72
  #
65
73
  # Raises:
66
74
  # * `NoEntryError` when the entry is not found.
67
75
 
68
- res = make_req "#{@base}/entry/#{entry.to_s.gsub " ", "%20"}"
76
+ res = make_req("#{@base}/entry/#{entry.to_s.gsub " ", "%20"}", timeout=timeout)
69
77
  if res == {}
70
78
  raise NoEntryError.new entry
71
79
  end
72
80
  return res
73
81
  end
74
82
 
75
- def get_category category
83
+ def get_category category, timeout=@default_timeout
76
84
  # Gets all entries from a category in the compendium.
77
85
  #
78
86
  # Parameters:
@@ -81,6 +89,12 @@ class Hyrule_Compendium
81
89
  # - notes:
82
90
  # * must be "creatures", "equipment", "materials", "monsters", or "treasure"
83
91
  # * the category "creatures" has two sub-categories, as keys: "food" and "non_food"
92
+ # * `timeout`: Seconds to wait for response until raising `Net::ReadTimeout`.
93
+ # - type: float, int
94
+ # - default: `@default_timeout`
95
+ #
96
+ # Returns: All entries in the category.
97
+ # - type: array, hash (for creatures)
84
98
  #
85
99
  # Raises:
86
100
  # * `NoCategoryError` when the category is not found.
@@ -88,19 +102,24 @@ class Hyrule_Compendium
88
102
  if !(["creatures", "equipment", "materials", "monsters", "treasure"].include? category)
89
103
  raise NoCategoryError.new category
90
104
  end
91
- return make_req "#{@base}/category/#{category}"
105
+ return make_req "#{@base}/category/#{category}", timeout=timeout
92
106
  end
93
107
 
94
- def get_all
108
+ def get_all timeout=@default_timeout
95
109
  # Gets all entries from the compendium.
96
- #
110
+ #
111
+ # Parameters:
112
+ # * `timeout`: Seconds to wait for response until raising `Net::ReadTimeout`.
113
+ # - type: float, int
114
+ # - default: `@default_timeout`
115
+ #
97
116
  # Returns: all items in the compendium with their metadata, nested in categories.
98
- # type: hash
117
+ # - type: hash
99
118
 
100
- return make_req @base
119
+ return make_req @base, timeout
101
120
  end
102
121
 
103
- def download_entry_image entry, output_file
122
+ def download_entry_image entry, output_file, timeout=@default_timeout
104
123
  # Downloads the image of a compendium entry.
105
124
  #
106
125
  # Parameters:
@@ -108,8 +127,11 @@ class Hyrule_Compendium
108
127
  # - type: str, int
109
128
  # * `output_file`: The output file's path.
110
129
  # - type: str
130
+ # * `timeout`: Seconds to wait for server response until raising `Net::ReadTimeout`.
131
+ # - type: float, int
132
+ # - default: `@default_timeout`
111
133
 
112
- open (get_entry entry)["image"] do |image|
134
+ open (get_entry entry, timeout)["image"] do |image|
113
135
  File.open output_file, "wb" do |file|
114
136
  file.write image.read
115
137
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Hyrule-Compendium
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aarav Borthakur
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2021-01-02 00:00:00.000000000 Z
@@ -21,7 +21,7 @@ homepage: https://github.com/Hyrule-Compendium-API/Hyrule-Compendium-ruby-client
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}
24
- post_install_message:
24
+ post_install_message:
25
25
  rdoc_options: []
26
26
  require_paths:
27
27
  - lib
@@ -36,8 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  requirements: []
39
- rubygems_version: 3.0.9
40
- signing_key:
39
+ rubygems_version: 3.0.3
40
+ signing_key:
41
41
  specification_version: 4
42
42
  summary: Hyrule Compendium API
43
43
  test_files: []