Class: SeatLayer::Charts

Inherits:
Resource show all
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.

Constant Summary

Constants inherited from Resource

Resource::UNSET

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from SeatLayer::Resource

Instance Method Details

#archive(chart_id) ⇒ Object



118
119
120
# File 'lib/seatlayer/resources.rb', line 118

def archive(chart_id)
  @client.post("/v1/charts/#{encode(chart_id)}/archive")
end

#copy(chart_id, idempotency_key: nil, name: nil, external_ref: UNSET, workspace_id: nil) ⇒ Object

Copy a chart — the usual way to provision a venue from a template.



108
109
110
111
112
113
114
115
116
# File 'lib/seatlayer/resources.rb', line 108

def copy(chart_id, idempotency_key: nil, name: nil, external_ref: UNSET,
         workspace_id: nil)
  body = compact({ "name" => name, "workspaceId" => workspace_id })
  body.merge!(supplied({ "externalRef" => external_ref }))
  @client.post(
    "/v1/charts/#{encode(chart_id)}/duplicate", body.empty? ? nil : body,
    idempotency_key: idempotency_key, retry_policy: :header_replay
  )
end

#create(name:, doc: nil, external_ref: nil, workspace_id: nil, idempotency_key: nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/seatlayer/resources.rb', line 65

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, retry_policy: :header_replay
  )
end

#delete(chart_id) ⇒ Object



103
104
105
# File 'lib/seatlayer/resources.rb', line 103

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".



37
38
39
40
41
42
# File 'lib/seatlayer/resources.rb', line 37

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)


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/seatlayer/resources.rb', line 52

def list_all(**options, &block)
  return enum_for(:list_all, **options) unless block_given?

  cursor = nil
  loop do
    page = list(**options, 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.



127
128
129
# File 'lib/seatlayer/resources.rb', line 127

def publish(chart_id)
  @client.post("/v1/charts/#{encode(chart_id)}/publish")
end

#retrieve(chart_id) ⇒ Object



73
74
75
# File 'lib/seatlayer/resources.rb', line 73

def retrieve(chart_id)
  @client.get("/v1/charts/#{encode(chart_id)}")
end

#unarchive(chart_id) ⇒ Object



122
123
124
# File 'lib/seatlayer/resources.rb', line 122

def unarchive(chart_id)
  @client.post("/v1/charts/#{encode(chart_id)}/unarchive")
end

#update(chart_id, doc: UNSET, expected_updated_at: UNSET, name: nil, issues: nil, external_ref: UNSET) ⇒ Object

Replace a chart document or update metadata only.

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.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/seatlayer/resources.rb', line 86

def update(chart_id, doc: UNSET, expected_updated_at: UNSET, name: nil, issues: nil,
           external_ref: UNSET)
  doc_supplied = !doc.equal?(UNSET)
  expected_supplied = !expected_updated_at.equal?(UNSET)
  unless doc_supplied == expected_supplied
    raise ArgumentError, "doc and expected_updated_at must be supplied together"
  end

  body = compact({ "name" => name, "issues" => issues })
  if doc_supplied
    body["doc"] = doc
    body["expectedUpdatedAt"] = expected_updated_at
  end
  body.merge!(supplied({ "externalRef" => external_ref }))
  @client.put("/v1/charts/#{encode(chart_id)}", body)
end