fetch-api 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c17efb152e74853bef394109a4f6012247e44e17277f22b49569249bb4ec01f
4
- data.tar.gz: d1451560f1fc8a26a0a381d7c7fe1c69a5e0cdff9a3641706aeacea801ef724c
3
+ metadata.gz: 4c44fa15b798e01607f5c81e771ad55d24c56abea4aaa1829de0046aa2a761a2
4
+ data.tar.gz: d8f8c324b7685c23d613ea1f00f5621bc23ef6e682aa66c0c181bb57c035d094
5
5
  SHA512:
6
- metadata.gz: 480a9fba5b2d4ccb972122507dd907d2fae0ffe941d470e7bfb2f20cb39e0e81440c879d87d43192a7b67ff2673bc4e41c1c1237cbd2c8a5baeedc0ed2abcdee
7
- data.tar.gz: b497f558eab4796ecc87a89cdfe696eb8ec68dc2b417215f1e2d0f34fa350b31965460ed2a810e50668bfa92a2c8f71329764a556141b990b4e826f44948ab80
6
+ metadata.gz: 89fc2a039bac8f9dea78f86a6af9d195dff47f1e47fdfbf86026364a916be5dba60961daccd4d24a56f321f95823e24148c9e32df58b50736b7aba03e9ae24cf
7
+ data.tar.gz: d60ae6beb1b1736cb4a5e71b5049742771a8905565475121f02e5d23b0691905575cb6f1ab55afcc8f7a97f2ed38fee6d169aa6f1f4220a9513ab01c3b97adc3
data/README.md CHANGED
@@ -129,6 +129,18 @@ Fetch.configure do |config|
129
129
  end
130
130
  ```
131
131
 
132
+ ### Parsing JSON
133
+
134
+ By default, `Fetch::Response#json` calls `JSON.parse` without options. Additional options can be specified in `Fetch.config.json_parse_options`.
135
+
136
+ ``` ruby
137
+ Fetch.configure do |config|
138
+ config.json_parse_options = {
139
+ symbolize_names: true
140
+ }
141
+ end
142
+ ```
143
+
132
144
  ## Development
133
145
 
134
146
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/fetch/config.rb CHANGED
@@ -1,3 +1,7 @@
1
1
  module Fetch
2
- Config = Struct.new(:connection_max_idle_time, :on_connection_create)
2
+ Config = Struct.new(
3
+ :connection_max_idle_time,
4
+ :on_connection_create,
5
+ :json_parse_options
6
+ )
3
7
  end
@@ -21,10 +21,10 @@ module Fetch
21
21
  Rack::Utils::HTTP_STATUS_CODES[status]
22
22
  end
23
23
 
24
- def json(...)
24
+ def json(**json_parse_options)
25
25
  return nil unless body
26
26
 
27
- JSON.parse(body, ...)
27
+ JSON.parse(body, **Fetch.config.json_parse_options, **json_parse_options)
28
28
  end
29
29
  end
30
30
  end
data/lib/fetch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fetch
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/fetch.rb CHANGED
@@ -12,5 +12,6 @@ module Fetch
12
12
  configure do |config|
13
13
  config.connection_max_idle_time = 30
14
14
  config.on_connection_create = -> (*) {}
15
+ config.json_parse_options = {}
15
16
  end
16
17
  end
data/sig/fetch/config.rbs CHANGED
@@ -2,5 +2,6 @@ module Fetch
2
2
  class Config
3
3
  attr_accessor connection_max_idle_time: Integer
4
4
  attr_accessor on_connection_create: ^(Net::HTTP, URI::HTTP) -> void
5
+ attr_accessor json_parse_options: json_options
5
6
  end
6
7
  end
@@ -9,6 +9,6 @@ module Fetch
9
9
  def initialize: (url: String, status: Integer, headers: Headers, body: String?, redirected: bool) -> void
10
10
  def ok: () -> bool
11
11
  def status_text: () -> String
12
- def json: (json_options) -> untyped
12
+ def json: (**json_options) -> untyped
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-03 00:00:00.000000000 Z
11
+ date: 2024-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.5.11
152
+ rubygems_version: 3.5.16
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: Something like the Fetch API for Ruby