zatca 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zatca/client.rb +19 -5
- 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: aaa15fcf4e0f8bc1ecdd57277871998c22eb1310294aec57ca297324f8ac2e18
|
4
|
+
data.tar.gz: 27e35dae1b305d98573e81e6edcc06eb57013ea145a50614d80889245c302989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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.
|
150
|
-
|
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
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.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-
|
11
|
+
date: 2023-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|