flashpi 0.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 +7 -0
- data/CHANGELOG.md +25 -0
- data/LICENSE +21 -0
- data/README.en.md +379 -0
- data/README.md +383 -0
- data/lib/flashpi/api_response.rb +33 -0
- data/lib/flashpi/client.rb +112 -0
- data/lib/flashpi/errors.rb +116 -0
- data/lib/flashpi/internal/engine.rb +355 -0
- data/lib/flashpi/internal/json_text.rb +108 -0
- data/lib/flashpi/internal/multipart.rb +141 -0
- data/lib/flashpi/internal/problems.rb +111 -0
- data/lib/flashpi/internal/request.rb +231 -0
- data/lib/flashpi/internal/resource.rb +125 -0
- data/lib/flashpi/internal/secret.rb +41 -0
- data/lib/flashpi/internal/settings.rb +88 -0
- data/lib/flashpi/internal/transport.rb +432 -0
- data/lib/flashpi/internal/validate.rb +122 -0
- data/lib/flashpi/page.rb +82 -0
- data/lib/flashpi/resources/documents.rb +136 -0
- data/lib/flashpi/resources/events.rb +36 -0
- data/lib/flashpi/resources/issuer_onboardings.rb +47 -0
- data/lib/flashpi/resources/issuers.rb +179 -0
- data/lib/flashpi/resources/webhook_endpoints.rb +110 -0
- data/lib/flashpi/version.rb +6 -0
- data/lib/flashpi/webhooks.rb +223 -0
- data/lib/flashpi.rb +42 -0
- data/sig/flashpi/internal.rbs +376 -0
- data/sig/flashpi/resources.rbs +712 -0
- data/sig/flashpi/sdk_types.rbs +114 -0
- data/sig/flashpi/types.rbs +2495 -0
- data/sig/flashpi.rbs +187 -0
- data/sig/manifest.yaml +8 -0
- metadata +80 -0
data/sig/flashpi.rbs
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# The official Ruby SDK for Flashpi, the electronic invoicing API for Ecuador's SRI.
|
|
2
|
+
module Flashpi
|
|
3
|
+
VERSION: String
|
|
4
|
+
|
|
5
|
+
# The address of the Flashpi API.
|
|
6
|
+
DEFAULT_BASE_URL: String
|
|
7
|
+
|
|
8
|
+
# Seconds each attempt of a request may take, from sending it to reading the whole answer.
|
|
9
|
+
DEFAULT_TIMEOUT: Float
|
|
10
|
+
|
|
11
|
+
# Retries after network errors, timeouts, 429 and 5xx.
|
|
12
|
+
DEFAULT_MAX_RETRIES: Integer
|
|
13
|
+
|
|
14
|
+
# Every error this gem raises extends this class, except for invalid arguments (ArgumentError and
|
|
15
|
+
# TypeError).
|
|
16
|
+
class Error < StandardError
|
|
17
|
+
# The Idempotency-Key a failed POST used, or nil: pass it back to try the same operation again
|
|
18
|
+
# without issuing twice.
|
|
19
|
+
attr_accessor idempotency_key: String?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# The API answered with an error status. Branch on `code`, never on `message`.
|
|
23
|
+
class APIError < Error
|
|
24
|
+
attr_reader status: Integer
|
|
25
|
+
attr_reader code: Types::api_error_code?
|
|
26
|
+
attr_reader title: String?
|
|
27
|
+
attr_reader detail: String?
|
|
28
|
+
attr_reader errors: Array[Types::field_error]
|
|
29
|
+
attr_reader request_id: String?
|
|
30
|
+
attr_reader problem: Types::problem?
|
|
31
|
+
attr_reader headers: Hash[String, String]
|
|
32
|
+
|
|
33
|
+
def initialize: (Integer status, Hash[String, String] headers, Types::problem? problem, ?String body_text) -> void
|
|
34
|
+
|
|
35
|
+
# Seconds the API asked to wait before trying again (`Retry-After`), or nil.
|
|
36
|
+
def retry_after: () -> Integer?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class BadRequestError < APIError
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class AuthenticationError < APIError
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class PermissionDeniedError < APIError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class NotFoundError < APIError
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class ConflictError < APIError
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class UnprocessableEntityError < APIError
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class RateLimitError < APIError
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class InternalServerError < APIError
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# The request never got an answer (DNS, TLS, connection reset, ...).
|
|
64
|
+
class APIConnectionError < Error
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The request took longer than the `timeout` option.
|
|
68
|
+
class APITimeoutError < APIConnectionError
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Why a webhook was rejected.
|
|
72
|
+
type webhook_verification_reason = :missing_headers | :invalid_timestamp | :timestamp_out_of_range
|
|
73
|
+
| :no_matching_signature | :invalid_secret | :invalid_payload
|
|
74
|
+
|
|
75
|
+
# A webhook did not come from Flashpi, was altered, or is too old: answer 400 and ignore it.
|
|
76
|
+
class WebhookVerificationError < Error
|
|
77
|
+
attr_reader reason: webhook_verification_reason
|
|
78
|
+
|
|
79
|
+
def initialize: (webhook_verification_reason reason, String message) -> void
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# The data of a call together with the HTTP answer it came from (`with_response`).
|
|
83
|
+
class APIResponse[out T]
|
|
84
|
+
attr_reader data: T
|
|
85
|
+
attr_reader status: Integer
|
|
86
|
+
attr_reader headers: Hash[String, String]
|
|
87
|
+
attr_reader request_id: String?
|
|
88
|
+
|
|
89
|
+
def initialize: (data: T, status: Integer, headers: Hash[String, String], request_id: String?) -> void
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# One page of a list. Enumerable over every item of this page and the following ones.
|
|
93
|
+
class Page[out T]
|
|
94
|
+
include Enumerable[T]
|
|
95
|
+
|
|
96
|
+
@has_more: bool
|
|
97
|
+
@fetch_page: (^(String cursor) -> Page[T])?
|
|
98
|
+
|
|
99
|
+
attr_reader data: Array[T]
|
|
100
|
+
attr_reader next_cursor: String?
|
|
101
|
+
|
|
102
|
+
def initialize: (untyped body) ?{ (String cursor) -> Page[T] } -> void
|
|
103
|
+
def has_more?: () -> bool
|
|
104
|
+
def has_next_page?: () -> bool
|
|
105
|
+
def next_page: () -> Page[T]?
|
|
106
|
+
def each: () { (T item) -> void } -> self
|
|
107
|
+
| () -> Enumerator[T, self]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# The Flashpi API client.
|
|
111
|
+
class Client
|
|
112
|
+
attr_reader environment: String
|
|
113
|
+
attr_reader invoices: Resources::Invoices
|
|
114
|
+
attr_reader credit_notes: Resources::CreditNotes
|
|
115
|
+
attr_reader debit_notes: Resources::DebitNotes
|
|
116
|
+
attr_reader purchase_settlements: Resources::PurchaseSettlements
|
|
117
|
+
attr_reader waybills: Resources::Waybills
|
|
118
|
+
attr_reader withholdings: Resources::Withholdings
|
|
119
|
+
attr_reader documents: Resources::Documents
|
|
120
|
+
attr_reader issuers: Resources::Issuers
|
|
121
|
+
attr_reader issuer_onboardings: Resources::IssuerOnboardings
|
|
122
|
+
attr_reader webhook_endpoints: Resources::WebhookEndpoints
|
|
123
|
+
attr_reader events: Resources::Events
|
|
124
|
+
attr_reader status: Resources::Status
|
|
125
|
+
|
|
126
|
+
@transport: Internal::Transport
|
|
127
|
+
@engine: Internal::Engine
|
|
128
|
+
|
|
129
|
+
def initialize: (
|
|
130
|
+
?api_key: String?, ?base_url: String?, ?timeout: Types::seconds?, ?max_retries: Integer?,
|
|
131
|
+
?language: Types::request_language?, ?default_headers: Types::headers?
|
|
132
|
+
) -> void
|
|
133
|
+
|
|
134
|
+
# Verify the signature of the webhooks you receive (no API key needed).
|
|
135
|
+
def webhooks: () -> singleton(Webhooks)
|
|
136
|
+
|
|
137
|
+
def base_url: () -> String
|
|
138
|
+
|
|
139
|
+
# Closes the connections kept open for the next requests.
|
|
140
|
+
def close: () -> nil
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Verification of the webhooks Flashpi sends (Standard Webhooks).
|
|
144
|
+
module Webhooks
|
|
145
|
+
TOLERANCE_SECONDS: Integer
|
|
146
|
+
SECRET_PREFIX: String
|
|
147
|
+
MIN_SECRET_BYTES: Integer
|
|
148
|
+
MAX_SECRET_BYTES: Integer
|
|
149
|
+
SIGNATURE_BYTES: Integer
|
|
150
|
+
TIMESTAMP: Regexp
|
|
151
|
+
BASE64: Regexp
|
|
152
|
+
NO_MATCH: String
|
|
153
|
+
|
|
154
|
+
# Request headers: a Hash in any letter case, a Rack env, or anything that yields name and
|
|
155
|
+
# value pairs (Rails' `request.headers`).
|
|
156
|
+
type headers = Hash[untyped, untyped] | _EachPair
|
|
157
|
+
|
|
158
|
+
interface _EachPair
|
|
159
|
+
def each: () { ([untyped, untyped]) -> void } -> untyped
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Checks that a webhook comes from Flashpi and is recent; raises WebhookVerificationError
|
|
163
|
+
# otherwise.
|
|
164
|
+
def self.verify_signature: (
|
|
165
|
+
String payload, headers headers, String secret, ?tolerance: Types::seconds?, ?now: (Time | Types::seconds)?
|
|
166
|
+
) -> nil
|
|
167
|
+
|
|
168
|
+
# Verifies a webhook and returns its parsed body.
|
|
169
|
+
def self.unwrap: (
|
|
170
|
+
String payload, headers headers, String secret, ?tolerance: Types::seconds?, ?now: (Time | Types::seconds)?
|
|
171
|
+
) -> Types::webhook_event
|
|
172
|
+
|
|
173
|
+
private def self.parse: (String payload) -> untyped
|
|
174
|
+
private def self.reject!: (webhook_verification_reason reason, String message) -> bot
|
|
175
|
+
private def self.header: (untyped headers, String name) -> String?
|
|
176
|
+
private def self.signing_key: (untyped secret) -> Internal::Secret[String]
|
|
177
|
+
private def self.key_size: (String secret) -> Integer
|
|
178
|
+
private def self.encoded_key: (String secret) -> String
|
|
179
|
+
private def self.signed?: (Internal::Secret[String] key, String message, String signatures) -> bool
|
|
180
|
+
private def self.v1_signatures: (String signatures) -> Array[String]
|
|
181
|
+
private def self.decode_base64: (String value) -> String?
|
|
182
|
+
private def self.payload_bytes: (untyped payload) -> String
|
|
183
|
+
private def self.verify_options: (untyped tolerance, untyped now) -> [Float, Float]
|
|
184
|
+
private def self.clock: (untyped now) -> Float
|
|
185
|
+
private def self.shown: (Float seconds) -> String
|
|
186
|
+
end
|
|
187
|
+
end
|
data/sig/manifest.yaml
ADDED
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: flashpi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- SIGNIADIGITAL S.A.
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Issue invoices, credit and debit notes, purchase settlements, waybills
|
|
13
|
+
and withholding receipts with Ecuador's SRI through the Flashpi API, manage issuers
|
|
14
|
+
and their .p12 certificates, and verify Flashpi's webhooks. No runtime dependencies.
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- CHANGELOG.md
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.en.md
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/flashpi.rb
|
|
24
|
+
- lib/flashpi/api_response.rb
|
|
25
|
+
- lib/flashpi/client.rb
|
|
26
|
+
- lib/flashpi/errors.rb
|
|
27
|
+
- lib/flashpi/internal/engine.rb
|
|
28
|
+
- lib/flashpi/internal/json_text.rb
|
|
29
|
+
- lib/flashpi/internal/multipart.rb
|
|
30
|
+
- lib/flashpi/internal/problems.rb
|
|
31
|
+
- lib/flashpi/internal/request.rb
|
|
32
|
+
- lib/flashpi/internal/resource.rb
|
|
33
|
+
- lib/flashpi/internal/secret.rb
|
|
34
|
+
- lib/flashpi/internal/settings.rb
|
|
35
|
+
- lib/flashpi/internal/transport.rb
|
|
36
|
+
- lib/flashpi/internal/validate.rb
|
|
37
|
+
- lib/flashpi/page.rb
|
|
38
|
+
- lib/flashpi/resources/documents.rb
|
|
39
|
+
- lib/flashpi/resources/events.rb
|
|
40
|
+
- lib/flashpi/resources/issuer_onboardings.rb
|
|
41
|
+
- lib/flashpi/resources/issuers.rb
|
|
42
|
+
- lib/flashpi/resources/webhook_endpoints.rb
|
|
43
|
+
- lib/flashpi/version.rb
|
|
44
|
+
- lib/flashpi/webhooks.rb
|
|
45
|
+
- sig/flashpi.rbs
|
|
46
|
+
- sig/flashpi/internal.rbs
|
|
47
|
+
- sig/flashpi/resources.rbs
|
|
48
|
+
- sig/flashpi/sdk_types.rbs
|
|
49
|
+
- sig/flashpi/types.rbs
|
|
50
|
+
- sig/manifest.yaml
|
|
51
|
+
homepage: https://flashpi.com.ec
|
|
52
|
+
licenses:
|
|
53
|
+
- MIT
|
|
54
|
+
metadata:
|
|
55
|
+
homepage_uri: https://flashpi.com.ec
|
|
56
|
+
documentation_uri: https://flashpi.com.ec/docs/sdks/
|
|
57
|
+
source_code_uri: https://github.com/flashpi1/flashpi-ruby
|
|
58
|
+
bug_tracker_uri: https://github.com/flashpi1/flashpi-ruby/issues
|
|
59
|
+
changelog_uri: https://github.com/flashpi1/flashpi-ruby/blob/main/CHANGELOG.md
|
|
60
|
+
allowed_push_host: https://rubygems.org
|
|
61
|
+
rubygems_mfa_required: 'true'
|
|
62
|
+
rdoc_options: []
|
|
63
|
+
require_paths:
|
|
64
|
+
- lib
|
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '3.3'
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
requirements: []
|
|
76
|
+
rubygems_version: 4.0.20
|
|
77
|
+
specification_version: 4
|
|
78
|
+
summary: The official Ruby SDK for Flashpi, the electronic invoicing API for Ecuador's
|
|
79
|
+
SRI.
|
|
80
|
+
test_files: []
|