zatca 1.0.1 → 1.0.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/README.md +3 -3
- data/lib/zatca/client.rb +26 -2
- data/lib/zatca/version.rb +1 -1
- 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: 6174c4fead4e9527ffe5d81c848f928058cc49fe796637c89394b2984c0ab38f
|
4
|
+
data.tar.gz: a64d875110d6df7fd268e3d4ba25eaf08cf1020a427bb1192ea6387ebec2e306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d8d01aafed7d0969ea354cfdc8739383db7a79f762b8df766d60ccf27608fd4807f7e507107777a52c665226ef5a39be2e4c3f8dc4942a7b5ea4146bf3d0e8f
|
7
|
+
data.tar.gz: 8a96413a0f4a40142febc69a8050b987deabdf14a27b215a4f11d63eb2140eb03127bbaefdee8725c3976d23bf6f5f3cee806f1cf3ad4377d90ce484918f605a
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# zatca
|
2
|
-
  
|
3
3
|
|
4
4
|
A Ruby library for generating QR Codes and e-invoices according to the standard created by ZATCA in Saudi Arabia.
|
5
5
|
|
@@ -31,7 +31,7 @@ tags = {
|
|
31
31
|
invoice_total: "115",
|
32
32
|
}
|
33
33
|
|
34
|
-
ZATCA.render_qr_code(tags)
|
34
|
+
ZATCA.render_qr_code(tags: tags)
|
35
35
|
# => data:image/png;base64,...
|
36
36
|
# Hint (Try pasting the above into your web browser's address bar)
|
37
37
|
```
|
@@ -49,7 +49,7 @@ tags = ZATCA::Tags.new({
|
|
49
49
|
invoice_total: "115",
|
50
50
|
})
|
51
51
|
|
52
|
-
generator = ZATCA::QRCodeGenerator.new(tags)
|
52
|
+
generator = ZATCA::QRCodeGenerator.new(tags: tags)
|
53
53
|
generator.render(size: 512)
|
54
54
|
```
|
55
55
|
|
data/lib/zatca/client.rb
CHANGED
@@ -20,13 +20,14 @@ class ZATCA::Client
|
|
20
20
|
DEFAULT_API_VERSION = "V2".freeze
|
21
21
|
LANGUAGES = %w[ar en].freeze
|
22
22
|
|
23
|
-
def initialize(username:, password:, language: "ar", version: DEFAULT_API_VERSION, environment: :production)
|
23
|
+
def initialize(username:, password:, language: "ar", version: DEFAULT_API_VERSION, environment: :production, verbose: false)
|
24
24
|
raise "Invalid language: #{language}, Please use one of: #{LANGUAGES}" unless LANGUAGES.include?(language)
|
25
25
|
|
26
26
|
@username = username
|
27
27
|
@password = password
|
28
28
|
@language = language
|
29
29
|
@version = version
|
30
|
+
@verbose = verbose
|
30
31
|
|
31
32
|
@base_url = ENVIRONMENTS_TO_URLS_MAP[environment.to_sym] || PRODUCTION_BASE_URL
|
32
33
|
end
|
@@ -132,6 +133,8 @@ class ZATCA::Client
|
|
132
133
|
url = "#{@base_url}/#{path}"
|
133
134
|
headers = default_headers.merge(headers)
|
134
135
|
|
136
|
+
log("Requesting #{method} #{url} with\n\nbody: #{body}\n\nheaders: #{headers}\n")
|
137
|
+
|
135
138
|
client = if authenticated
|
136
139
|
authenticated_request_cilent
|
137
140
|
else
|
@@ -139,14 +142,28 @@ class ZATCA::Client
|
|
139
142
|
end
|
140
143
|
|
141
144
|
response = client.send(method, url, json: body, headers: headers)
|
145
|
+
log("Raw response: #{response}")
|
146
|
+
|
147
|
+
if response.instance_of?(HTTPX::ErrorResponse)
|
148
|
+
return {
|
149
|
+
message: response.to_s,
|
150
|
+
response_headers: response.response&.headers&.to_s,
|
151
|
+
response_body: response.response&.body&.to_s,
|
152
|
+
status: response.response&.status
|
153
|
+
}
|
154
|
+
end
|
142
155
|
|
143
156
|
response_body = response.body.to_s
|
144
157
|
|
145
|
-
if response.headers["Content-Type"] == "application/json"
|
158
|
+
parsed_body = if response.headers["Content-Type"] == "application/json"
|
146
159
|
parse_json_or_return_string(response_body)
|
147
160
|
else
|
148
161
|
response_body
|
149
162
|
end
|
163
|
+
|
164
|
+
log("Response body: #{parsed_body}")
|
165
|
+
|
166
|
+
parsed_body
|
150
167
|
end
|
151
168
|
|
152
169
|
def authenticated_request_cilent
|
@@ -170,4 +187,11 @@ class ZATCA::Client
|
|
170
187
|
rescue JSON::ParserError
|
171
188
|
json
|
172
189
|
end
|
190
|
+
|
191
|
+
def log(message)
|
192
|
+
return unless @verbose
|
193
|
+
message = "\n\n---------------------\n\n#{message}\n\n"
|
194
|
+
|
195
|
+
puts message
|
196
|
+
end
|
173
197
|
end
|
data/lib/zatca/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zatca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omar Bahareth
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|