Skip to content

API Lifecycle Logging

Omar Bahareth edited this page Dec 27, 2023 · 1 revision

We have two options for logging, you can choose to use or not use any of them, or both of them.

Verbose Option

This option will simply output to STDOUT without any log levels. This is suitable for a simple printing approach.

This is simply achieved by setting verbose: true on ZATCA::Client

client = ZATCA::Client.new(username: "user", password: "pass", verbose: true)

Hooks

This approach is suitable if you need more advanced logging (e.g. setting context or tags in Sentry or other platforms)

There are two hooks that can be used:

  • before_submitting_request
  • before_parsing_response

Example:

client = ZATCA::Client.new(username: "user", password: "pass")

client.before_submitting_request = proc do |method, url, body, headers|
  # method is a symbol
  # url is a string
  # body and headers are hashes
end

client.before_parsing_response = proc do |response|
  # Response is an instance of HTTPX::Response or HTTPX::ErrorResponse
end

# client.report_invoice(...)