zatca 1.0.2 → 1.1.0

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: 6174c4fead4e9527ffe5d81c848f928058cc49fe796637c89394b2984c0ab38f
4
- data.tar.gz: a64d875110d6df7fd268e3d4ba25eaf08cf1020a427bb1192ea6387ebec2e306
3
+ metadata.gz: aaa15fcf4e0f8bc1ecdd57277871998c22eb1310294aec57ca297324f8ac2e18
4
+ data.tar.gz: 27e35dae1b305d98573e81e6edcc06eb57013ea145a50614d80889245c302989
5
5
  SHA512:
6
- metadata.gz: 6d8d01aafed7d0969ea354cfdc8739383db7a79f762b8df766d60ccf27608fd4807f7e507107777a52c665226ef5a39be2e4c3f8dc4942a7b5ea4146bf3d0e8f
7
- data.tar.gz: 8a96413a0f4a40142febc69a8050b987deabdf14a27b215a4f11d63eb2140eb03127bbaefdee8725c3976d23bf6f5f3cee806f1cf3ad4377d90ce484918f605a
6
+ metadata.gz: 1d1fc81fd4799d919c0df244327cdffd74cb30aa62b6d906d4b8e422bfe4dd831577d87e55672e403151563055e2ad99be28d482936d19524951c64df586991a
7
+ data.tar.gz: 41db16f2a9dde6111a5fd0d6459e0d3c4910d3ca20cc77a7220b62f3b5dc08b7841130c7e3c334b598e914297e20ec9a7038a1a6e9416ef4f958e058229dcc14
data/lib/zatca/client.rb CHANGED
@@ -4,6 +4,8 @@ require "json"
4
4
  # This wraps the API described here:
5
5
  # https://sandbox.zatca.gov.sa/IntegrationSandbox
6
6
  class ZATCA::Client
7
+ attr_accessor :before_submitting_request, :before_parsing_response
8
+
7
9
  # API URLs are not present in developer portal, they can only be found in a PDF
8
10
  # called Fatoora Portal User Manual, here:
9
11
  # https://zatca.gov.sa/en/E-Invoicing/Introduction/Guidelines/Documents/Fatoora%20portal%20user%20manual.pdf
@@ -20,7 +22,16 @@ class ZATCA::Client
20
22
  DEFAULT_API_VERSION = "V2".freeze
21
23
  LANGUAGES = %w[ar en].freeze
22
24
 
23
- def initialize(username:, password:, language: "ar", version: DEFAULT_API_VERSION, environment: :production, verbose: false)
25
+ def initialize(
26
+ username:,
27
+ password:,
28
+ language: "ar",
29
+ version: DEFAULT_API_VERSION,
30
+ environment: :production,
31
+ verbose: false,
32
+ before_submitting_request: nil,
33
+ before_parsing_response: nil
34
+ )
24
35
  raise "Invalid language: #{language}, Please use one of: #{LANGUAGES}" unless LANGUAGES.include?(language)
25
36
 
26
37
  @username = username
@@ -30,6 +41,9 @@ class ZATCA::Client
30
41
  @verbose = verbose
31
42
 
32
43
  @base_url = ENVIRONMENTS_TO_URLS_MAP[environment.to_sym] || PRODUCTION_BASE_URL
44
+
45
+ @before_submitting_request = before_submitting_request
46
+ @before_parsing_response = before_parsing_response
33
47
  end
34
48
 
35
49
  # Reporting API
@@ -133,6 +147,7 @@ class ZATCA::Client
133
147
  url = "#{@base_url}/#{path}"
134
148
  headers = default_headers.merge(headers)
135
149
 
150
+ before_submitting_request&.call(method, url, body, headers)
136
151
  log("Requesting #{method} #{url} with\n\nbody: #{body}\n\nheaders: #{headers}\n")
137
152
 
138
153
  client = if authenticated
@@ -142,14 +157,13 @@ class ZATCA::Client
142
157
  end
143
158
 
144
159
  response = client.send(method, url, json: body, headers: headers)
160
+ before_parsing_response&.call(response)
145
161
  log("Raw response: #{response}")
146
162
 
147
163
  if response.instance_of?(HTTPX::ErrorResponse)
148
164
  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
165
+ message: response.error&.message,
166
+ details: response.to_s
153
167
  }
154
168
  end
155
169
 
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.2"
4
+ VERSION = "1.1.0"
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.2
4
+ version: 1.1.0
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-20 00:00:00.000000000 Z
11
+ date: 2023-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk