Module: GOBL::Operations
- Included in:
- GOBL
- Defined in:
- lib/gobl/operations.rb,
lib/gobl/operations/service_error.rb,
lib/gobl/operations/validation_result.rb
Overview
Provides the API to execute operations over GOBL structures. It implements them by sending HTTP requests to the bulk endpoint of the service that the GOBL CLI makes available via the ‘gobl serve` command. The server’s host and port must be configured using ‘GOBL.config.service_host` and `GOBL.config.service_port`.
Defined Under Namespace
Classes: ServiceError, ValidationResult
Constant Summary collapse
- VALIDATABLE_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
SIGNABLE_TYPES = BUILDABLE_TYPES = [ GOBL::Envelope, GOBL::Schema::Object ].freeze
Instance Method Summary collapse
-
#build(struct, envelop: nil) ⇒ GOBL::Envelope, GOBL::Schema::Object
Calculates and validates an envelope or document, wrapping it in an envelope if requested.
-
#sign(struct) ⇒ GOBL::Envelope
Signs a document or envelope, calculating, enveloping and validating it first if needed.
-
#validate(struct) ⇒ GOBL::ValidationResult
Checks whether or not a document or envelope is valid according to the GOBL schema and rules.
Instance Method Details
#build(struct, envelop: nil) ⇒ GOBL::Envelope, GOBL::Schema::Object
Calculates and validates an envelope or document, wrapping it in an envelope if requested.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gobl/operations.rb', line 64 def build(struct, envelop: nil) check_struct_type struct, BUILDABLE_TYPES response = request_action(:build, struct: struct, envelop: envelop) raise ServiceError, response['error'] if response['error'].present? GOBL::Struct.from_data response['payload'] end |
#sign(struct) ⇒ GOBL::Envelope
Signs a document or envelope, calculating, enveloping and validating it first if
needed. The signing key will be the one configured in the server.
120 121 122 123 124 125 126 127 128 |
# File 'lib/gobl/operations.rb', line 120 def sign(struct) check_struct_type struct, SIGNABLE_TYPES response = request_action(:sign, struct: struct) raise ServiceError, response['error'] if response['error'].present? GOBL::Struct.from_data response['payload'] end |
#validate(struct) ⇒ GOBL::ValidationResult
Checks whether or not a document or envelope is valid according to the GOBL schema
and rules.
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gobl/operations.rb', line 94 def validate(struct) check_struct_type struct, VALIDATABLE_TYPES response = request_action(:validate, struct: struct) if response['error'].present? ValidationResult.from_service_error(response['error']) elsif response['payload']['ok'] ValidationResult.valid else raise 'Unexpected response from the service' end end |