wave-dispatch 0.4.1 → 0.4.2
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/wave_dispatch.rb +6 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1fd26b4979ac3ed427931f9c252e36a4b95baeb7e791bda8de0794828f40695a
|
|
4
|
+
data.tar.gz: 903f7c9da83728d1bb489f4af52b27763fee4be2c7739a4e0121d43d4a44107a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72ac4dda805c6cc4df28108070b2e1d2ed73cd106248fc70f0aac6046564550ec3efa22787a42029cea39ab894ab3fb804364702c9869c5bba1a906b672f6acf
|
|
7
|
+
data.tar.gz: 41cfb28c916af48ff7e0f120d1d2b06de3accba7174f6c464b78399237bd3013489bc031dea96c8f6d8fba97a15ee3c7bb62452bd9956ad4d26632aa4df34724
|
data/lib/wave_dispatch.rb
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "json"
|
|
5
5
|
require "uri"
|
|
6
|
+
require "openssl"
|
|
6
7
|
|
|
7
8
|
module WaveDispatch
|
|
8
|
-
VERSION = "0.2
|
|
9
|
+
VERSION = "0.4.2"
|
|
9
10
|
|
|
10
11
|
class Client
|
|
11
12
|
def initialize(license = ENV["WAVE_LICENSE"], endpoint: "https://dispatch.wave.online",
|
|
@@ -42,9 +43,12 @@ module WaveDispatch
|
|
|
42
43
|
req = (method == :post ? Net::HTTP::Post : Net::HTTP::Get).new(uri, "content-type" => "application/json")
|
|
43
44
|
req["authorization"] = "Bearer #{@license}" if @license
|
|
44
45
|
req.body = body.to_json if body
|
|
45
|
-
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https"
|
|
46
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https",
|
|
47
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER) { |h| h.request(req) }
|
|
46
48
|
raise "dispatch: 402 payment required (x402)" if res.code == "402"
|
|
47
49
|
raise "dispatch: 401 unauthorized — set a valid license" if res.code == "401"
|
|
50
|
+
# any other non-2xx must raise — never JSON.parse an error body and return it as a success result
|
|
51
|
+
raise "dispatch: #{res.code} #{res.body.to_s[0, 160]}" unless res.code.start_with?("2")
|
|
48
52
|
JSON.parse(res.body)
|
|
49
53
|
end
|
|
50
54
|
end
|