Module: Invoq

Defined in:
lib/invoq.rb,
lib/invoq/client.rb,
lib/invoq/errors.rb,
lib/invoq/version.rb,
lib/invoq/webhooks.rb,
lib/invoq/internal/request.rb,
lib/invoq/invoices_resource.rb

Defined Under Namespace

Modules: Internal, Webhooks Classes: ApiError, Client, Error, InvoicesResource, SignatureVerificationError

Constant Summary collapse

DEFAULT_API_ORIGIN =
"https://api.invoq.money"
DEFAULT_TIMEOUT_MS =
10_000
MAX_TIMEOUT_MS =
4_294_967_295
VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.invoice_paid?(event) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/invoq.rb', line 17

def self.invoice_paid?(event)
  Webhooks.invoice_paid?(event)
end

.is_invoice_paid(event) ⇒ Object



21
22
23
# File 'lib/invoq.rb', line 21

def self.is_invoice_paid(event)
  invoice_paid?(event)
end

.new(api_key, api_origin: DEFAULT_API_ORIGIN, timeout_ms: DEFAULT_TIMEOUT_MS) ⇒ Object



9
10
11
# File 'lib/invoq.rb', line 9

def self.new(api_key, api_origin: DEFAULT_API_ORIGIN, timeout_ms: DEFAULT_TIMEOUT_MS)
  Client.new(api_key, api_origin: api_origin, timeout_ms: timeout_ms)
end

.normalize_api_origin(value) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/invoq/client.rb', line 36

def self.normalize_api_origin(value)
  unless value.is_a?(String)
    raise Error, "api_origin must be an absolute http or https origin."
  end

  uri = URI.parse(value)

  unless uri.is_a?(URI::HTTP) && uri.host && !uri.host.empty?
    raise Error, "api_origin must be an absolute http or https origin."
  end

  unless uri.scheme == "http" || uri.scheme == "https"
    raise Error, "api_origin must be an absolute http or https origin."
  end

  if uri.user || uri.password
    raise Error, "api_origin must be an absolute http or https origin."
  end

  if uri.port < 1 || uri.port > 65_535
    raise Error, "api_origin must be an absolute http or https origin."
  end

  if uri.query || uri.fragment
    raise Error, "api_origin must not include query or hash parts."
  end

  pathname = uri.path.to_s.sub(%r{/+\z}, "")
  pathname = "/" if pathname.empty?

  unless pathname == "/"
    raise Error, "api_origin must not include a path."
  end

  uri.path = "/"
  uri.query = nil
  uri.fragment = nil
  uri.to_s
rescue URI::InvalidURIError
  raise Error, "api_origin must be an absolute http or https origin."
end

.normalize_timeout_ms(value) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/invoq/client.rb', line 78

def self.normalize_timeout_ms(value)
  unless value.is_a?(Integer) && value.positive? && value <= MAX_TIMEOUT_MS
    raise Error, "timeout_ms must be a positive integer of at most 4294967295."
  end

  value
end

.verify_webhook(raw_body, headers, webhook_secret) ⇒ Object



13
14
15
# File 'lib/invoq.rb', line 13

def self.verify_webhook(raw_body, headers, webhook_secret)
  Webhooks.verify_webhook(raw_body, headers, webhook_secret)
end