Class: SeatLayer::Charts
- Defined in:
- lib/seatlayer/resources.rb
Overview
Seat-map definitions that events are created from.
Even when organisers draw their own venues in the embedded Designer you need
this: create_designer_session requires a chart id that already exists, so
the usual platform flow is copy a template here, then hand over a session.
Instance Method Summary collapse
- #archive(chart_id) ⇒ Object
-
#copy(chart_id, idempotency_key: nil) ⇒ Object
Copy a chart — the usual way to provision a venue from a template.
- #create(name:, doc: nil, external_ref: nil, workspace_id: nil, idempotency_key: nil) ⇒ Object
- #delete(chart_id) ⇒ Object
-
#list(workspace_id: nil, external_ref: nil, archived: false, limit: nil, cursor: nil) ⇒ Object
One page of charts.
-
#list_all(**options, &block) ⇒ Object
Every chart, paging transparently.
-
#publish(chart_id) ⇒ Object
Publish the draft.
- #retrieve(chart_id) ⇒ Object
- #unarchive(chart_id) ⇒ Object
-
#update(chart_id, doc:, expected_updated_at:, name: nil) ⇒ Object
Replace a chart document.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from SeatLayer::Resource
Instance Method Details
#archive(chart_id) ⇒ Object
91 92 93 |
# File 'lib/seatlayer/resources.rb', line 91 def archive(chart_id) @client.post("/v1/charts/#{encode(chart_id)}/archive") end |
#copy(chart_id, idempotency_key: nil) ⇒ Object
Copy a chart — the usual way to provision a venue from a template.
87 88 89 |
# File 'lib/seatlayer/resources.rb', line 87 def copy(chart_id, idempotency_key: nil) @client.post("/v1/charts/#{encode(chart_id)}/duplicate", nil, idempotency_key: idempotency_key) end |
#create(name:, doc: nil, external_ref: nil, workspace_id: nil, idempotency_key: nil) ⇒ Object
58 59 60 61 62 |
# File 'lib/seatlayer/resources.rb', line 58 def create(name:, doc: nil, external_ref: nil, workspace_id: nil, idempotency_key: nil) body = compact({ "name" => name, "doc" => doc, "externalRef" => external_ref, "workspaceId" => workspace_id }) @client.post("/v1/charts", body, idempotency_key: idempotency_key) end |
#delete(chart_id) ⇒ Object
82 83 84 |
# File 'lib/seatlayer/resources.rb', line 82 def delete(chart_id) @client.delete("/v1/charts/#{encode(chart_id)}") end |
#list(workspace_id: nil, external_ref: nil, archived: false, limit: nil, cursor: nil) ⇒ Object
One page of charts. Pass cursor from the previous page's "nextCursor".
30 31 32 33 34 35 |
# File 'lib/seatlayer/resources.rb', line 30 def list(workspace_id: nil, external_ref: nil, archived: false, limit: nil, cursor: nil) query = compact({ "workspaceId" => workspace_id, "externalRef" => external_ref, "limit" => limit, "cursor" => cursor }) query["archived"] = "1" if archived @client.get("/v1/charts", query) end |
#list_all(**options, &block) ⇒ Object
Every chart, paging transparently.
Returns an Enumerator when no block is given, so it stays lazy — the point of paginating was to not hold an unbounded result set in memory, and returning an Array would hand that problem straight back.
client.charts.list_all { |chart| ... }
client.charts.list_all.lazy.first(5)
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/seatlayer/resources.rb', line 45 def list_all(**, &block) return enum_for(:list_all, **) unless block_given? cursor = nil loop do page = list(**, cursor: cursor) Array(page["charts"]).each(&block) cursor = page["nextCursor"] # An absent cursor terminates, so a caller looping cannot spin forever. break if cursor.nil? || cursor.empty? end end |
#publish(chart_id) ⇒ Object
Publish the draft. Events can only be created from a published chart.
100 101 102 |
# File 'lib/seatlayer/resources.rb', line 100 def publish(chart_id) @client.post("/v1/charts/#{encode(chart_id)}/publish") end |
#retrieve(chart_id) ⇒ Object
64 65 66 |
# File 'lib/seatlayer/resources.rb', line 64 def retrieve(chart_id) @client.get("/v1/charts/#{encode(chart_id)}") end |
#unarchive(chart_id) ⇒ Object
95 96 97 |
# File 'lib/seatlayer/resources.rb', line 95 def unarchive(chart_id) @client.post("/v1/charts/#{encode(chart_id)}/unarchive") end |
#update(chart_id, doc:, expected_updated_at:, name: nil) ⇒ Object
Replace a chart document.
expected_updated_at is required for optimistic concurrency and is not
optional here either: without it two concurrent writers silently overwrite
each other, and a seat map is exactly the document where that loses work.
Read it from retrieve immediately before writing.
The Designer is the authoring surface. Use this for bulk programmatic edits and migrations, not for drawing.
77 78 79 80 |
# File 'lib/seatlayer/resources.rb', line 77 def update(chart_id, doc:, expected_updated_at:, name: nil) body = compact({ "doc" => doc, "expectedUpdatedAt" => expected_updated_at, "name" => name }) @client.put("/v1/charts/#{encode(chart_id)}", body) end |