seatschart 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -10
  3. data/lib/seatschart/api/audit_api.rb +2 -2
  4. data/lib/seatschart/api/auth_api.rb +4 -4
  5. data/lib/seatschart/api/billing_api.rb +93 -12
  6. data/lib/seatschart/api/charts_api.rb +52 -52
  7. data/lib/seatschart/api/embed_origins_api.rb +55 -0
  8. data/lib/seatschart/api/events_api.rb +110 -104
  9. data/lib/seatschart/api/orders_api.rb +6 -6
  10. data/lib/seatschart/api/seasons_api.rb +88 -88
  11. data/lib/seatschart/api/seats_api.rb +8 -8
  12. data/lib/seatschart/api/usage_api.rb +4 -4
  13. data/lib/seatschart/api/workspace_api.rb +52 -40
  14. data/lib/seatschart/models/{api_error.rb → api_error_body.rb} +7 -7
  15. data/lib/seatschart/models/delete_api_workspaces_by_workspace_id_members_by_user_id200_response.rb +221 -0
  16. data/lib/seatschart/models/get_api_workspaces_by_workspace_id_invitations200_response.rb +239 -0
  17. data/lib/seatschart/models/get_api_workspaces_by_workspace_id_invitations200_response_invitations_inner.rb +286 -0
  18. data/lib/seatschart/models/get_api_workspaces_by_workspace_id_members200_response.rb +239 -0
  19. data/lib/seatschart/models/get_api_workspaces_by_workspace_id_members200_response_members_inner.rb +288 -0
  20. data/lib/seatschart/models/get_api_workspaces_overview200_response.rb +288 -0
  21. data/lib/seatschart/models/get_api_workspaces_overview200_response_account.rb +270 -0
  22. data/lib/seatschart/models/get_api_workspaces_overview200_response_account_charts.rb +233 -0
  23. data/lib/seatschart/models/get_api_workspaces_overview200_response_account_plan.rb +237 -0
  24. data/lib/seatschart/models/get_api_workspaces_overview200_response_items_inner.rb +439 -0
  25. data/lib/seatschart/models/get_api_workspaces_overview200_response_items_inner_revenue.rb +234 -0
  26. data/lib/seatschart/models/get_api_workspaces_overview200_response_items_inner_usage.rb +271 -0
  27. data/lib/seatschart/models/get_api_workspaces_overview200_response_seats.rb +431 -0
  28. data/lib/seatschart/models/get_api_workspaces_overview200_response_seats_overage.rb +233 -0
  29. data/lib/seatschart/models/get_api_workspaces_overview200_response_seats_projected.rb +237 -0
  30. data/lib/seatschart/models/get_api_workspaces_overview200_response_totals.rb +318 -0
  31. data/lib/seatschart/models/get_api_workspaces_overview200_response_totals_revenue.rb +238 -0
  32. data/lib/seatschart/models/get_api_workspaces_overview200_response_totals_seats.rb +253 -0
  33. data/lib/seatschart/models/post_api_billing_actions_change_plan_request.rb +256 -0
  34. data/lib/seatschart/models/post_api_events_by_event_id_actions_update_extra_data_request_objects_inner.rb +0 -2
  35. data/lib/seatschart/models/post_api_orders_by_order_id_cancel_request.rb +44 -4
  36. data/lib/seatschart/models/post_api_sandboxes201_response.rb +0 -4
  37. data/lib/seatschart/models/post_api_sandboxes_by_sandbox_id_actions_reset200_response.rb +0 -2
  38. data/lib/seatschart/models/post_api_seats_confirm_request.rb +26 -4
  39. data/lib/seatschart/models/post_api_workspaces200_response.rb +0 -4
  40. data/lib/seatschart/models/post_api_workspaces_by_workspace_id_invitations201_response.rb +238 -0
  41. data/lib/seatschart/models/post_api_workspaces_by_workspace_id_invitations201_response_invitation.rb +286 -0
  42. data/lib/seatschart/version.rb +1 -1
  43. data/lib/seatschart/workspaces.rb +172 -0
  44. data/lib/seatschart.rb +23 -3
  45. metadata +25 -5
  46. data/lib/seatschart/models/get_api_workspaces_created_by_api_parameter.rb +0 -103
  47. data/lib/seatschart/models/get_api_workspaces_overview_created_by_api_parameter.rb +0 -103
@@ -0,0 +1,238 @@
1
+ =begin
2
+ #SeatsChart API
3
+
4
+ #Seat inventory and locking API for B2B2C integrations. Authenticate using `x-api-key` (partners) or `Authorization: Bearer` with an HS256 JWT.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.11.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module SeatsChart
17
+ class PostApiWorkspacesByWorkspaceIdInvitations201Response
18
+ attr_accessor :invitation
19
+
20
+ # One-time token of the accept link (`/accept-invite?token=…`), returned once.
21
+ attr_accessor :invite_token
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :'invitation' => :'invitation',
27
+ :'invite_token' => :'inviteToken'
28
+ }
29
+ end
30
+
31
+ # Returns all the JSON keys this model knows about
32
+ def self.acceptable_attributes
33
+ attribute_map.values
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.openapi_types
38
+ {
39
+ :'invitation' => :'PostApiWorkspacesByWorkspaceIdInvitations201ResponseInvitation',
40
+ :'invite_token' => :'String'
41
+ }
42
+ end
43
+
44
+ # List of attributes with nullable: true
45
+ def self.openapi_nullable
46
+ Set.new([
47
+ ])
48
+ end
49
+
50
+ # Initializes the object
51
+ # @param [Hash] attributes Model attributes in the form of hash
52
+ def initialize(attributes = {})
53
+ if (!attributes.is_a?(Hash))
54
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SeatsChart::PostApiWorkspacesByWorkspaceIdInvitations201Response` initialize method"
55
+ end
56
+
57
+ # check to see if the attribute exists and convert string to symbol for hash key
58
+ attributes = attributes.each_with_object({}) { |(k, v), h|
59
+ if (!self.class.attribute_map.key?(k.to_sym))
60
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SeatsChart::PostApiWorkspacesByWorkspaceIdInvitations201Response`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
61
+ end
62
+ h[k.to_sym] = v
63
+ }
64
+
65
+ if attributes.key?(:'invitation')
66
+ self.invitation = attributes[:'invitation']
67
+ else
68
+ self.invitation = nil
69
+ end
70
+
71
+ if attributes.key?(:'invite_token')
72
+ self.invite_token = attributes[:'invite_token']
73
+ else
74
+ self.invite_token = nil
75
+ end
76
+ end
77
+
78
+ # Show invalid properties with the reasons. Usually used together with valid?
79
+ # @return Array for valid properties with the reasons
80
+ def list_invalid_properties
81
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
82
+ invalid_properties = Array.new
83
+ if @invitation.nil?
84
+ invalid_properties.push('invalid value for "invitation", invitation cannot be nil.')
85
+ end
86
+
87
+ if @invite_token.nil?
88
+ invalid_properties.push('invalid value for "invite_token", invite_token cannot be nil.')
89
+ end
90
+
91
+ invalid_properties
92
+ end
93
+
94
+ # Check to see if the all the properties in the model are valid
95
+ # @return true if the model is valid
96
+ def valid?
97
+ warn '[DEPRECATED] the `valid?` method is obsolete'
98
+ return false if @invitation.nil?
99
+ return false if @invite_token.nil?
100
+ true
101
+ end
102
+
103
+ # Checks equality by comparing each attribute.
104
+ # @param [Object] Object to be compared
105
+ def ==(o)
106
+ return true if self.equal?(o)
107
+ self.class == o.class &&
108
+ invitation == o.invitation &&
109
+ invite_token == o.invite_token
110
+ end
111
+
112
+ # @see the `==` method
113
+ # @param [Object] Object to be compared
114
+ def eql?(o)
115
+ self == o
116
+ end
117
+
118
+ # Calculates hash code according to all attributes.
119
+ # @return [Integer] Hash code
120
+ def hash
121
+ [invitation, invite_token].hash
122
+ end
123
+
124
+ # Builds the object from hash
125
+ # @param [Hash] attributes Model attributes in the form of hash
126
+ # @return [Object] Returns the model itself
127
+ def self.build_from_hash(attributes)
128
+ return nil unless attributes.is_a?(Hash)
129
+ attributes = attributes.transform_keys(&:to_sym)
130
+ transformed_hash = {}
131
+ openapi_types.each_pair do |key, type|
132
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
133
+ transformed_hash["#{key}"] = nil
134
+ elsif type =~ /\AArray<(.*)>/i
135
+ # check to ensure the input is an array given that the attribute
136
+ # is documented as an array but the input is not
137
+ if attributes[attribute_map[key]].is_a?(Array)
138
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
139
+ end
140
+ elsif !attributes[attribute_map[key]].nil?
141
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
142
+ end
143
+ end
144
+ new(transformed_hash)
145
+ end
146
+
147
+ # Deserializes the data based on type
148
+ # @param string type Data type
149
+ # @param string value Value to be deserialized
150
+ # @return [Object] Deserialized data
151
+ def self._deserialize(type, value)
152
+ case type.to_sym
153
+ when :Time
154
+ Time.parse(value)
155
+ when :Date
156
+ Date.parse(value)
157
+ when :String
158
+ value.to_s
159
+ when :Integer
160
+ value.to_i
161
+ when :Float
162
+ value.to_f
163
+ when :Boolean
164
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
165
+ true
166
+ else
167
+ false
168
+ end
169
+ when :Object
170
+ # generic object (usually a Hash), return directly
171
+ value
172
+ when /\AArray<(?<inner_type>.+)>\z/
173
+ inner_type = Regexp.last_match[:inner_type]
174
+ value.map { |v| _deserialize(inner_type, v) }
175
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
176
+ k_type = Regexp.last_match[:k_type]
177
+ v_type = Regexp.last_match[:v_type]
178
+ {}.tap do |hash|
179
+ value.each do |k, v|
180
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
181
+ end
182
+ end
183
+ else # model
184
+ # models (e.g. Pet) or oneOf
185
+ klass = SeatsChart.const_get(type)
186
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
187
+ end
188
+ end
189
+
190
+ # Returns the string representation of the object
191
+ # @return [String] String presentation of the object
192
+ def to_s
193
+ to_hash.to_s
194
+ end
195
+
196
+ # to_body is an alias to to_hash (backward compatibility)
197
+ # @return [Hash] Returns the object in the form of hash
198
+ def to_body
199
+ to_hash
200
+ end
201
+
202
+ # Returns the object in the form of hash
203
+ # @return [Hash] Returns the object in the form of hash
204
+ def to_hash
205
+ hash = {}
206
+ self.class.attribute_map.each_pair do |attr, param|
207
+ value = self.send(attr)
208
+ if value.nil?
209
+ is_nullable = self.class.openapi_nullable.include?(attr)
210
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
211
+ end
212
+
213
+ hash[param] = _to_hash(value)
214
+ end
215
+ hash
216
+ end
217
+
218
+ # Outputs non-array value in the form of hash
219
+ # For object, use to_hash. Otherwise, just return the value
220
+ # @param [Object] value Any valid value
221
+ # @return [Hash] Returns the value in the form of hash
222
+ def _to_hash(value)
223
+ if value.is_a?(Array)
224
+ value.compact.map { |v| _to_hash(v) }
225
+ elsif value.is_a?(Hash)
226
+ {}.tap do |hash|
227
+ value.each { |k, v| hash[k] = _to_hash(v) }
228
+ end
229
+ elsif value.respond_to? :to_hash
230
+ value.to_hash
231
+ else
232
+ value
233
+ end
234
+ end
235
+
236
+ end
237
+
238
+ end
@@ -0,0 +1,286 @@
1
+ =begin
2
+ #SeatsChart API
3
+
4
+ #Seat inventory and locking API for B2B2C integrations. Authenticate using `x-api-key` (partners) or `Authorization: Bearer` with an HS256 JWT.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.11.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module SeatsChart
17
+ class PostApiWorkspacesByWorkspaceIdInvitations201ResponseInvitation
18
+ attr_accessor :id
19
+
20
+ attr_accessor :email
21
+
22
+ # Workspace role: `admin`, `map_editor` or `viewer`.
23
+ attr_accessor :role
24
+
25
+ attr_accessor :expires_at
26
+
27
+ attr_accessor :workspace_name
28
+
29
+ # Attribute mapping from ruby-style variable name to JSON key.
30
+ def self.attribute_map
31
+ {
32
+ :'id' => :'id',
33
+ :'email' => :'email',
34
+ :'role' => :'role',
35
+ :'expires_at' => :'expiresAt',
36
+ :'workspace_name' => :'workspaceName'
37
+ }
38
+ end
39
+
40
+ # Returns all the JSON keys this model knows about
41
+ def self.acceptable_attributes
42
+ attribute_map.values
43
+ end
44
+
45
+ # Attribute type mapping.
46
+ def self.openapi_types
47
+ {
48
+ :'id' => :'String',
49
+ :'email' => :'String',
50
+ :'role' => :'String',
51
+ :'expires_at' => :'Time',
52
+ :'workspace_name' => :'String'
53
+ }
54
+ end
55
+
56
+ # List of attributes with nullable: true
57
+ def self.openapi_nullable
58
+ Set.new([
59
+ ])
60
+ end
61
+
62
+ # Initializes the object
63
+ # @param [Hash] attributes Model attributes in the form of hash
64
+ def initialize(attributes = {})
65
+ if (!attributes.is_a?(Hash))
66
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SeatsChart::PostApiWorkspacesByWorkspaceIdInvitations201ResponseInvitation` initialize method"
67
+ end
68
+
69
+ # check to see if the attribute exists and convert string to symbol for hash key
70
+ attributes = attributes.each_with_object({}) { |(k, v), h|
71
+ if (!self.class.attribute_map.key?(k.to_sym))
72
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SeatsChart::PostApiWorkspacesByWorkspaceIdInvitations201ResponseInvitation`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
73
+ end
74
+ h[k.to_sym] = v
75
+ }
76
+
77
+ if attributes.key?(:'id')
78
+ self.id = attributes[:'id']
79
+ else
80
+ self.id = nil
81
+ end
82
+
83
+ if attributes.key?(:'email')
84
+ self.email = attributes[:'email']
85
+ else
86
+ self.email = nil
87
+ end
88
+
89
+ if attributes.key?(:'role')
90
+ self.role = attributes[:'role']
91
+ else
92
+ self.role = nil
93
+ end
94
+
95
+ if attributes.key?(:'expires_at')
96
+ self.expires_at = attributes[:'expires_at']
97
+ else
98
+ self.expires_at = nil
99
+ end
100
+
101
+ if attributes.key?(:'workspace_name')
102
+ self.workspace_name = attributes[:'workspace_name']
103
+ else
104
+ self.workspace_name = nil
105
+ end
106
+ end
107
+
108
+ # Show invalid properties with the reasons. Usually used together with valid?
109
+ # @return Array for valid properties with the reasons
110
+ def list_invalid_properties
111
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
112
+ invalid_properties = Array.new
113
+ if @id.nil?
114
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
115
+ end
116
+
117
+ if @email.nil?
118
+ invalid_properties.push('invalid value for "email", email cannot be nil.')
119
+ end
120
+
121
+ if @role.nil?
122
+ invalid_properties.push('invalid value for "role", role cannot be nil.')
123
+ end
124
+
125
+ if @expires_at.nil?
126
+ invalid_properties.push('invalid value for "expires_at", expires_at cannot be nil.')
127
+ end
128
+
129
+ if @workspace_name.nil?
130
+ invalid_properties.push('invalid value for "workspace_name", workspace_name cannot be nil.')
131
+ end
132
+
133
+ invalid_properties
134
+ end
135
+
136
+ # Check to see if the all the properties in the model are valid
137
+ # @return true if the model is valid
138
+ def valid?
139
+ warn '[DEPRECATED] the `valid?` method is obsolete'
140
+ return false if @id.nil?
141
+ return false if @email.nil?
142
+ return false if @role.nil?
143
+ return false if @expires_at.nil?
144
+ return false if @workspace_name.nil?
145
+ true
146
+ end
147
+
148
+ # Checks equality by comparing each attribute.
149
+ # @param [Object] Object to be compared
150
+ def ==(o)
151
+ return true if self.equal?(o)
152
+ self.class == o.class &&
153
+ id == o.id &&
154
+ email == o.email &&
155
+ role == o.role &&
156
+ expires_at == o.expires_at &&
157
+ workspace_name == o.workspace_name
158
+ end
159
+
160
+ # @see the `==` method
161
+ # @param [Object] Object to be compared
162
+ def eql?(o)
163
+ self == o
164
+ end
165
+
166
+ # Calculates hash code according to all attributes.
167
+ # @return [Integer] Hash code
168
+ def hash
169
+ [id, email, role, expires_at, workspace_name].hash
170
+ end
171
+
172
+ # Builds the object from hash
173
+ # @param [Hash] attributes Model attributes in the form of hash
174
+ # @return [Object] Returns the model itself
175
+ def self.build_from_hash(attributes)
176
+ return nil unless attributes.is_a?(Hash)
177
+ attributes = attributes.transform_keys(&:to_sym)
178
+ transformed_hash = {}
179
+ openapi_types.each_pair do |key, type|
180
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
181
+ transformed_hash["#{key}"] = nil
182
+ elsif type =~ /\AArray<(.*)>/i
183
+ # check to ensure the input is an array given that the attribute
184
+ # is documented as an array but the input is not
185
+ if attributes[attribute_map[key]].is_a?(Array)
186
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
187
+ end
188
+ elsif !attributes[attribute_map[key]].nil?
189
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
190
+ end
191
+ end
192
+ new(transformed_hash)
193
+ end
194
+
195
+ # Deserializes the data based on type
196
+ # @param string type Data type
197
+ # @param string value Value to be deserialized
198
+ # @return [Object] Deserialized data
199
+ def self._deserialize(type, value)
200
+ case type.to_sym
201
+ when :Time
202
+ Time.parse(value)
203
+ when :Date
204
+ Date.parse(value)
205
+ when :String
206
+ value.to_s
207
+ when :Integer
208
+ value.to_i
209
+ when :Float
210
+ value.to_f
211
+ when :Boolean
212
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
213
+ true
214
+ else
215
+ false
216
+ end
217
+ when :Object
218
+ # generic object (usually a Hash), return directly
219
+ value
220
+ when /\AArray<(?<inner_type>.+)>\z/
221
+ inner_type = Regexp.last_match[:inner_type]
222
+ value.map { |v| _deserialize(inner_type, v) }
223
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
224
+ k_type = Regexp.last_match[:k_type]
225
+ v_type = Regexp.last_match[:v_type]
226
+ {}.tap do |hash|
227
+ value.each do |k, v|
228
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
229
+ end
230
+ end
231
+ else # model
232
+ # models (e.g. Pet) or oneOf
233
+ klass = SeatsChart.const_get(type)
234
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
235
+ end
236
+ end
237
+
238
+ # Returns the string representation of the object
239
+ # @return [String] String presentation of the object
240
+ def to_s
241
+ to_hash.to_s
242
+ end
243
+
244
+ # to_body is an alias to to_hash (backward compatibility)
245
+ # @return [Hash] Returns the object in the form of hash
246
+ def to_body
247
+ to_hash
248
+ end
249
+
250
+ # Returns the object in the form of hash
251
+ # @return [Hash] Returns the object in the form of hash
252
+ def to_hash
253
+ hash = {}
254
+ self.class.attribute_map.each_pair do |attr, param|
255
+ value = self.send(attr)
256
+ if value.nil?
257
+ is_nullable = self.class.openapi_nullable.include?(attr)
258
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
259
+ end
260
+
261
+ hash[param] = _to_hash(value)
262
+ end
263
+ hash
264
+ end
265
+
266
+ # Outputs non-array value in the form of hash
267
+ # For object, use to_hash. Otherwise, just return the value
268
+ # @param [Object] value Any valid value
269
+ # @return [Hash] Returns the value in the form of hash
270
+ def _to_hash(value)
271
+ if value.is_a?(Array)
272
+ value.compact.map { |v| _to_hash(v) }
273
+ elsif value.is_a?(Hash)
274
+ {}.tap do |hash|
275
+ value.each { |k, v| hash[k] = _to_hash(v) }
276
+ end
277
+ elsif value.respond_to? :to_hash
278
+ value.to_hash
279
+ else
280
+ value
281
+ end
282
+ end
283
+
284
+ end
285
+
286
+ end
@@ -11,5 +11,5 @@ Generator version: 7.11.0
11
11
  =end
12
12
 
13
13
  module SeatsChart
14
- VERSION = '0.4.0'
14
+ VERSION = '0.6.0'
15
15
  end
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ # One workspace per organizer (ticketing platforms) for the SeatsChart Ruby client.
4
+ # Copied into the generated gem (lib/seatschart/workspaces.rb) and required from lib/seatschart.rb by
5
+ # scripts/generate-server-sdks.sh.
6
+ #
7
+ # A platform operates every organizer workspace it administers with one workspace admin key:
8
+ #
9
+ # org = SeatsChart.for_workspace('org-1042') # every call sends X-Workspace-Key: org-1042
10
+ # SeatsChart::EmbedApi.new(org).post_api_embed_tokens(...)
11
+ # workspaces = SeatsChart::Workspaces.new
12
+ # created = workspaces.create({ displayName: 'Teatro Aurora', externalId: 'org-1042',
13
+ # templateWorkspaceId: 'org-template', issueKey: { name: 'Server key' } },
14
+ # idempotency_key: 'provision-org-1042')
15
+ # workspaces.list_all_overview(created_by_api: true).each { |row| puts row.external_id }
16
+ #
17
+ # Bodies are the generated request models or hashes with the API's JSON field names. Every workspace_id argument also
18
+ # takes the external id you gave the workspace.
19
+ require 'securerandom'
20
+
21
+ module SeatsChart
22
+ WORKSPACE_KEY_HEADER = 'X-Workspace-Key'
23
+
24
+ # A copy of api_client (default: ApiClient.default) whose every call carries X-Workspace-Key and acts exactly as that
25
+ # workspace's own full-access key would (its rate limits, usage and audit trail). The original is unchanged; both
26
+ # share the configuration and the retry policy. Ordinary keys get 403 ERR_WORKSPACE_HEADER_NOT_ALLOWED; a workspace of
27
+ # another account answers 404.
28
+ def self.for_workspace(id_or_external_id, api_client = nil)
29
+ workspace = id_or_external_id.to_s.strip
30
+ raise ArgumentError, 'for_workspace needs a workspace id or external id' if workspace.empty?
31
+
32
+ client = api_client || ApiClient.default
33
+ scoped = client.dup
34
+ scoped.default_headers = client.default_headers.merge(WORKSPACE_KEY_HEADER => workspace)
35
+ scoped
36
+ end
37
+
38
+ # The organizer workspace calls named like the TypeScript SDK (workspaces.create, getByExternalId, keys, members,
39
+ # invitations, overview). The generated WorkspaceApi stays available for every other workspace route.
40
+ class Workspaces
41
+ attr_reader :keys, :members, :invitations
42
+
43
+ def initialize(api_client = nil, api: nil)
44
+ @api = api || WorkspaceApi.new(api_client || ApiClient.default)
45
+ @keys = Keys.new(@api)
46
+ @members = Members.new(@api)
47
+ @invitations = Invitations.new(@api)
48
+ end
49
+
50
+ # POST /api/workspaces: displayName and, for an organizer, externalId, templateWorkspaceId and issueKey. Always
51
+ # sent with an Idempotency-Key (yours, or a fresh one the retries reuse): a replay returns the same workspace with
52
+ # idempotent_replay true and every secret nil.
53
+ def create(body, idempotency_key: nil)
54
+ key = idempotency_key.to_s.strip.empty? ? SecureRandom.uuid : idempotency_key
55
+ @api.post_api_workspaces(Workspaces.model(:PostApiWorkspacesRequest, body), idempotency_key: key)
56
+ end
57
+
58
+ def get(workspace_id)
59
+ @api.get_api_workspaces_by_workspace_id(workspace_id)
60
+ end
61
+
62
+ # The workspace with this external id among the workspaces you belong to (404 otherwise).
63
+ def get_by_external_id(external_id)
64
+ @api.get_api_workspaces_by_external_id_by_external_id(external_id)
65
+ end
66
+
67
+ # Consolidated overview per workspace and in total. Filters: external_id, status, created_by_api, created_from,
68
+ # created_to, month, limit, cursor.
69
+ def overview(**query)
70
+ @api.get_api_workspaces_overview(query)
71
+ end
72
+
73
+ # Every overview item matching the filters, page after page (walks next_cursor). Without a block: an Enumerator.
74
+ def list_all_overview(**query, &block)
75
+ return enum_for(:list_all_overview, **query) unless block
76
+
77
+ query.delete(:cursor)
78
+ cursor = nil
79
+ loop do
80
+ page = overview(**query, **(cursor ? { cursor: cursor } : {}))
81
+ Array(Workspaces.field(page, :items)).each(&block)
82
+ cursor = Workspaces.field(page, :next_cursor)
83
+ break if cursor.nil? || cursor.to_s.empty?
84
+ end
85
+ end
86
+
87
+ # A hash body (JSON field names) becomes the generated model `name`; a model passes through.
88
+ def self.model(name, body)
89
+ return body unless body.is_a?(Hash)
90
+
91
+ SeatsChart.const_get(name).build_from_hash(body)
92
+ end
93
+
94
+ # Reads a field of a generated model (snake_case reader) or a hash (camelCase JSON name or symbol).
95
+ def self.field(value, name)
96
+ return value.public_send(name) if value.respond_to?(name)
97
+ return nil unless value.is_a?(Hash)
98
+
99
+ camel = name.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
100
+ [name, name.to_s, camel, camel.to_sym].each { |k| return value[k] if value.key?(k) }
101
+ nil
102
+ end
103
+
104
+ # API keys of a workspace you administer (workspace admin keys are read only here).
105
+ class Keys
106
+ def initialize(api)
107
+ @api = api
108
+ end
109
+
110
+ def list(workspace_id)
111
+ @api.get_api_workspaces_by_workspace_id_keys(workspace_id)
112
+ end
113
+
114
+ # New ordinary key (full access by default, or scopes); its secret is returned once.
115
+ def create(workspace_id, body)
116
+ @api.post_api_workspaces_by_workspace_id_keys(workspace_id, Workspaces.model(:PostApiWorkspacesByWorkspaceIdKeysRequest, body))
117
+ end
118
+
119
+ # Renames or rescopes a key (next request).
120
+ def update(workspace_id, key_id, body)
121
+ @api.patch_api_workspaces_by_workspace_id_keys_by_key_id(workspace_id, key_id,
122
+ Workspaces.model(:PatchApiWorkspacesByWorkspaceIdKeysByKeyIdRequest, body))
123
+ end
124
+
125
+ # New secret for the same key (returned once); the old one stops at once.
126
+ def rotate(workspace_id, key_id)
127
+ @api.post_api_workspaces_by_workspace_id_keys_by_key_id_actions_rotate(workspace_id, key_id)
128
+ end
129
+
130
+ def revoke(workspace_id, key_id)
131
+ @api.delete_api_workspaces_by_workspace_id_keys_by_key_id(workspace_id, key_id)
132
+ end
133
+ end
134
+
135
+ # Dashboard members of a workspace you administer.
136
+ class Members
137
+ def initialize(api)
138
+ @api = api
139
+ end
140
+
141
+ def list(workspace_id)
142
+ @api.get_api_workspaces_by_workspace_id_members(workspace_id)
143
+ end
144
+
145
+ # Removes a member (not the last admin, not yourself).
146
+ def remove(workspace_id, user_id)
147
+ @api.delete_api_workspaces_by_workspace_id_members_by_user_id(workspace_id, user_id)
148
+ end
149
+ end
150
+
151
+ # Invitations of an organizer's team to the dashboard of its workspace.
152
+ class Invitations
153
+ def initialize(api)
154
+ @api = api
155
+ end
156
+
157
+ def list(workspace_id)
158
+ @api.get_api_workspaces_by_workspace_id_invitations(workspace_id)
159
+ end
160
+
161
+ # Invites { email:, role: } (admin, map_editor or viewer); invite_token is returned once.
162
+ def create(workspace_id, body)
163
+ @api.post_api_workspaces_by_workspace_id_invitations(workspace_id,
164
+ Workspaces.model(:PostApiWorkspacesByWorkspaceIdInvitationsRequest, body))
165
+ end
166
+
167
+ def revoke(workspace_id, invitation_id)
168
+ @api.delete_api_workspaces_by_workspace_id_invitations_by_invitation_id(workspace_id, invitation_id)
169
+ end
170
+ end
171
+ end
172
+ end