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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfcfffb30bc80671008a9f4d85bc6300f7bed524f02919a35314be134f6ced61
4
- data.tar.gz: b5fdeac07afe47aabcb05284283a4197ddaf55262961d34dd953a7e9d74f6487
3
+ metadata.gz: 6174c4fead4e9527ffe5d81c848f928058cc49fe796637c89394b2984c0ab38f
4
+ data.tar.gz: a64d875110d6df7fd268e3d4ba25eaf08cf1020a427bb1192ea6387ebec2e306
5
5
  SHA512:
6
- metadata.gz: 9905e39f50b48661abc536d803254b99dbb7aa4c8a200e3b2c80b9292080aa5d5fa64f419ccf2d5e9c368691ce068cfab96a6373dcc42e9fa9dfc037b3639128
7
- data.tar.gz: f3b19d710fce67255bd151bdd1913e900419fddf7343b547a88eb86ebc21b8aaecc40537c1b6a0e58ce0f79b4002667780a3768b95a7042c03b87faca2268038
6
+ metadata.gz: 6d8d01aafed7d0969ea354cfdc8739383db7a79f762b8df766d60ccf27608fd4807f7e507107777a52c665226ef5a39be2e4c3f8dc4942a7b5ea4146bf3d0e8f
7
+ data.tar.gz: 8a96413a0f4a40142febc69a8050b987deabdf14a27b215a4f11d63eb2140eb03127bbaefdee8725c3976d23bf6f5f3cee806f1cf3ad4377d90ce484918f605a
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # zatca
2
- ![](https://img.shields.io/gem/v/zatca) ![](https://img.shields.io/github/workflow/status/mrsool/zatca/Ruby)
2
+ ![](https://img.shields.io/gem/v/zatca) ![](https://img.shields.io/github/actions/workflow/status/mrsool/zatca/test.yml?branch=main)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZATCA
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
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.1
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-06 00:00:00.000000000 Z
11
+ date: 2023-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk