Class: Invoance::Resources::Events
- Inherits:
-
Object
- Object
- Invoance::Resources::Events
- Defined in:
- lib/invoance/resources/events.rb
Overview
Events resource — client.events.*
Instance Method Summary collapse
-
#get(event_id) ⇒ Hash
GET /events/:event_id — Retrieve a single event.
-
#ingest(event_type:, payload:, event_time: nil, trace_id: nil, idempotency_key: nil) ⇒ Hash
POST /events — Ingest a compliance event.
-
#initialize(http) ⇒ Events
constructor
A new instance of Events.
-
#list(page: nil, limit: nil, date_from: nil, date_to: nil, event_type: nil) ⇒ Hash
GET /events — Paginated event listing.
-
#verify(event_id, payload_hash: nil, payload: nil) ⇒ Hash
POST /events/:event_id/verify — Hash verification.
Constructor Details
#initialize(http) ⇒ Events
Returns a new instance of Events.
11 12 13 |
# File 'lib/invoance/resources/events.rb', line 11 def initialize(http) @http = http end |
Instance Method Details
#get(event_id) ⇒ Hash
GET /events/:event_id — Retrieve a single event.
45 46 47 |
# File 'lib/invoance/resources/events.rb', line 45 def get(event_id) @http.get("/events/#{event_id}") end |
#ingest(event_type:, payload:, event_time: nil, trace_id: nil, idempotency_key: nil) ⇒ Hash
POST /events — Ingest a compliance event.
23 24 25 26 27 28 |
# File 'lib/invoance/resources/events.rb', line 23 def ingest(event_type:, payload:, event_time: nil, trace_id: nil, idempotency_key: nil) body = { "event_type" => event_type, "payload" => payload } body["event_time"] = event_time if event_time body["trace_id"] = trace_id if trace_id @http.post("/events", body, idempotency_key) end |
#list(page: nil, limit: nil, date_from: nil, date_to: nil, event_type: nil) ⇒ Hash
GET /events — Paginated event listing.
33 34 35 36 37 38 39 40 41 |
# File 'lib/invoance/resources/events.rb', line 33 def list(page: nil, limit: nil, date_from: nil, date_to: nil, event_type: nil) @http.get("/events", { "page" => page, "limit" => limit, "date_from" => date_from, "date_to" => date_to, "event_type" => event_type }) end |
#verify(event_id, payload_hash: nil, payload: nil) ⇒ Hash
POST /events/:event_id/verify — Hash verification.
Provide EITHER payload_hash (hex SHA-256) OR payload (raw JSON). Passing neither raises ValidationError.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/invoance/resources/events.rb', line 55 def verify(event_id, payload_hash: nil, payload: nil) if payload_hash.nil? && payload.nil? raise ValidationError, "events.verify requires either `payload_hash` or `payload`" end body = {} unless payload_hash.nil? Validate.assert_sha256_hex("payload_hash", payload_hash) body["payload_hash"] = payload_hash end body["payload"] = payload unless payload.nil? @http.post("/events/#{event_id}/verify", body) end |