Class: Seatsio::ChartsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/seatsio/charts.rb

Overview

Seatsio Charts client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_client) ⇒ ChartsClient

Returns a new instance of ChartsClient.



14
15
16
17
# File 'lib/seatsio/charts.rb', line 14

def initialize(http_client)
  @http_client = http_client
  @archive = Pagination::Cursor.new(Chart, 'charts/archive', @http_client)
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



12
13
14
# File 'lib/seatsio/charts.rb', line 12

def archive
  @archive
end

Instance Method Details

#add_category(key, category) ⇒ Object



41
42
43
# File 'lib/seatsio/charts.rb', line 41

def add_category(key, category)
  @http_client.post("charts/#{key}/categories", category)
end

#add_tag(key, tag) ⇒ Object



62
63
64
# File 'lib/seatsio/charts.rb', line 62

def add_tag(key, tag)
  @http_client.post("charts/#{key}/tags/#{CGI::escape(tag)}")
end

#copy(key) ⇒ Object



70
71
72
73
# File 'lib/seatsio/charts.rb', line 70

def copy(key)
  response = @http_client.post("charts/#{key}/version/published/actions/copy")
  Chart.new(response)
end

#copy_draft_version(key) ⇒ Object



87
88
89
90
# File 'lib/seatsio/charts.rb', line 87

def copy_draft_version(key)
  response = @http_client.post("charts/#{key}/version/draft/actions/copy")
  Chart.new(response)
end

#copy_from_workspace_to(chart_key, from_workspace_key, to_workspace_key) ⇒ Object



81
82
83
84
85
# File 'lib/seatsio/charts.rb', line 81

def copy_from_workspace_to(chart_key, from_workspace_key, to_workspace_key)
  url = "charts/#{chart_key}/version/published/actions/copy/from/#{from_workspace_key}/to/#{to_workspace_key}"
  response = @http_client.post url
  Chart.new(response)
end

#copy_to_workspace(chart_key, to_workspace_key) ⇒ Object



75
76
77
78
79
# File 'lib/seatsio/charts.rb', line 75

def copy_to_workspace(chart_key, to_workspace_key)
  url = "charts/#{chart_key}/version/published/actions/copy-to-workspace/#{to_workspace_key}"
  response = @http_client.post url
  Chart.new(response)
end

#create(name: nil, venue_type: nil, categories: nil) ⇒ Object



30
31
32
33
34
# File 'lib/seatsio/charts.rb', line 30

def create(name: nil, venue_type: nil, categories: nil)
  payload = build_chart_request name, venue_type, categories
  response = @http_client.post('charts', payload)
  Chart.new(response)
end

#discard_draft_version(key) ⇒ Object



108
109
110
# File 'lib/seatsio/charts.rb', line 108

def discard_draft_version(key)
  @http_client.post("charts/#{key}/version/draft/actions/discard")
end

#list(chart_filter: nil, tag: nil, expand_events: false, expand_validation: false, expand_venue_type: false, expand_zones: false) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/seatsio/charts.rb', line 116

def list(chart_filter: nil, tag: nil, expand_events: false, expand_validation: false, expand_venue_type: false, expand_zones: false)
  cursor = Pagination::Cursor.new(Chart, 'charts', @http_client)
  cursor.set_query_param('filter', chart_filter)
  cursor.set_query_param('tag', tag)

  expand_params = list_expand_params(expand_events, expand_validation, expand_venue_type, expand_zones)
  cursor.set_query_param('expand', expand_params) unless expand_params.empty?
  cursor
end

#list_all_tagsObject



148
149
150
151
# File 'lib/seatsio/charts.rb', line 148

def list_all_tags
  response = @http_client.get('charts/tags')
  response['tags']
end

#list_categories(chart_key) ⇒ Object



49
50
51
52
# File 'lib/seatsio/charts.rb', line 49

def list_categories(chart_key)
  response = @http_client.get("charts/#{chart_key}/categories")
  Category.create_list(response['categories'])
end

#list_expand_params(expand_events, expand_validation, expand_venue_type, expand_zones) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/seatsio/charts.rb', line 126

def list_expand_params(expand_events, expand_validation, expand_venue_type, expand_zones)
  result = []

  if expand_events
    result.push('events')
  end

  if expand_validation
    result.push('validation')
  end

  if expand_venue_type
    result.push('venueType')
  end

  if expand_zones
    result.push('zones')
  end

  result
end

#move_out_of_archive(chart_key) ⇒ Object



157
158
159
# File 'lib/seatsio/charts.rb', line 157

def move_out_of_archive(chart_key)
  @http_client.post("charts/#{chart_key}/actions/move-out-of-archive")
end

#move_to_archive(chart_key) ⇒ Object



153
154
155
# File 'lib/seatsio/charts.rb', line 153

def move_to_archive(chart_key)
  @http_client.post("charts/#{chart_key}/actions/move-to-archive")
end

#publish_draft_version(chart_key) ⇒ Object



112
113
114
# File 'lib/seatsio/charts.rb', line 112

def publish_draft_version(chart_key)
  @http_client.post("charts/#{chart_key}/version/draft/actions/publish")
end

#remove_category(key, category_key) ⇒ Object



45
46
47
# File 'lib/seatsio/charts.rb', line 45

def remove_category(key, category_key)
  @http_client.delete("charts/#{key}/categories/#{category_key}")
end

#remove_tag(key, tag) ⇒ Object



66
67
68
# File 'lib/seatsio/charts.rb', line 66

def remove_tag(key, tag)
  @http_client.delete("charts/#{key}/tags/#{tag}")
end

#retrieve(chart_key) ⇒ Seatsio::Chart

Returns:



20
21
22
23
# File 'lib/seatsio/charts.rb', line 20

def retrieve(chart_key)
  response = @http_client.get("charts/#{chart_key}")
  Chart.new(response)
end

#retrieve_draft_version(key) ⇒ Object



96
97
98
# File 'lib/seatsio/charts.rb', line 96

def retrieve_draft_version(key)
  @http_client.get("charts/#{key}/version/draft")
end

#retrieve_draft_version_thumbnail(key) ⇒ Object



100
101
102
# File 'lib/seatsio/charts.rb', line 100

def retrieve_draft_version_thumbnail(key)
  @http_client.get_raw("charts/#{key}/version/draft/thumbnail")
end

#retrieve_published_version(key) ⇒ Object



92
93
94
# File 'lib/seatsio/charts.rb', line 92

def retrieve_published_version(key)
  @http_client.get("charts/#{key}/version/published")
end

#retrieve_published_version_thumbnail(key) ⇒ Object



104
105
106
# File 'lib/seatsio/charts.rb', line 104

def retrieve_published_version_thumbnail(key)
  @http_client.get_raw("charts/#{key}/version/published/thumbnail")
end

#retrieve_with_events(chart_key) ⇒ Object



25
26
27
28
# File 'lib/seatsio/charts.rb', line 25

def retrieve_with_events(chart_key)
  response = @http_client.get("charts/#{chart_key}?expand=events")
  Chart.new(response)
end

#update(key:, new_name: nil, categories: nil) ⇒ Object



36
37
38
39
# File 'lib/seatsio/charts.rb', line 36

def update(key:, new_name: nil, categories: nil)
  payload = build_chart_request new_name, nil, categories
  @http_client.post("charts/#{key}", payload)
end

#update_category(chart_key:, category_key:, label: nil, color: nil, accessible: nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/seatsio/charts.rb', line 54

def update_category(chart_key:, category_key:, label: nil, color: nil, accessible: nil)
  payload = {}
  payload['label'] = label if label != nil
  payload['color'] = color if color != nil
  payload['accessible'] = accessible if accessible != nil
  @http_client.post("/charts/#{chart_key}/categories/#{category_key}", payload)
end

#validate_draft_version(chart_key) ⇒ Object



166
167
168
169
# File 'lib/seatsio/charts.rb', line 166

def validate_draft_version(chart_key)
  response = @http_client.post("charts/#{chart_key}/version/draft/actions/validate")
  Seatsio::ChartValidationResult.new(response)
end

#validate_published_version(chart_key) ⇒ Object



161
162
163
164
# File 'lib/seatsio/charts.rb', line 161

def validate_published_version(chart_key)
  response = @http_client.post("charts/#{chart_key}/version/published/actions/validate")
  Seatsio::ChartValidationResult.new(response)
end