Class: Stage::StageApi

Inherits:
Object
  • Object
show all
Defined in:
lib/stage-ruby/api/stage_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ StageApi

Returns a new instance of StageApi.



18
19
20
# File 'lib/stage-ruby/api/stage_api.rb', line 18

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



16
17
18
# File 'lib/stage-ruby/api/stage_api.rb', line 16

def api_client
  @api_client
end

Instance Method Details

#access(user_identifier, feature_identifier, opts = {}) ⇒ AccessForm

If the user has access to the feature, this marks that feature as accessed.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifier

    The feature_identifier of the feature being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



215
216
217
218
# File 'lib/stage-ruby/api/stage_api.rb', line 215

def access(user_identifier, feature_identifier, opts = {})
  data, _status_code, _headers = access_with_http_info(user_identifier, [feature_identifier], opts)
  data
end

#access_with_http_info(user_identifier, feature_identifiers, opts = {}) ⇒ Array<(AccessForm, Integer, Hash)>

If the user has access to the features, this marks those features as accessed.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifiers

    The identifiers of the features being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(AccessForm, Integer, Hash)>)

    AccessForm data, response status code and response headers



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/stage-ruby/api/stage_api.rb', line 235

def access_with_http_info(user_identifier, feature_identifiers, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: StageApi.access ...'
  end
  # verify the required parameter 'feature_identifiers' is set
  if @api_client.config.client_side_validation && feature_identifiers.nil?
    fail ArgumentError, "Missing the required parameter 'feature_identifiers' when calling StageApi.access"
  end
  # verify the required parameter 'user_identifier' is set
  if @api_client.config.client_side_validation && user_identifier.nil?
    fail ArgumentError, "Missing the required parameter 'user_identifier' when calling StageApi.access"
  end
  # resource path
  local_var_path = '/sdk-api/v1/users/{userIdentifier}/features'.sub('{' + 'userIdentifier' + '}', user_identifier.to_s)

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'identifiers'] = @api_client.build_collection_param(feature_identifiers, :multi)

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  return_type = opts[:return_type] || 'AccessForm'

  auth_names = opts[:auth_names] || ['stage-api-token', 'stage-read-only-api-token']
  data, status_code, headers = @api_client.call_api(:POST, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: StageApi#access\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#accessAll(user_identifier, feature_identifiers, opts = {}) ⇒ AccessForm

If the user has access to the features, this marks those features as accessed.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifiers

    The feature_identifiers of the features being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



225
226
227
228
# File 'lib/stage-ruby/api/stage_api.rb', line 225

def accessAll(user_identifier, feature_identifiers, opts = {})
  data, _status_code, _headers = access_with_http_info(user_identifier, feature_identifiers, opts)
  data
end

#create_user(user_identifier, plan_identifier) ⇒ ClientUserForm

Creates a user and assigning it to a pre-defined role.

Parameters:

  • user_identifier

    The identifier of the user.

  • plan_identifier

    The plan identifier.

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stage-ruby/api/stage_api.rb', line 26

def create_user(user_identifier, plan_identifier)
  body = Stage::ClientUserForm.new({
    client_users: [
      Stage::ClientUserObjectForm.new({
        identifier: user_identifier,
        plan_identifier: plan_identifier
      })
    ]
  })
  data, _status_code, _headers = create_user_with_http_info(body, {})
  data
end

#create_user_with_http_info(body, opts = {}) ⇒ Array<(ClientUserForm, Integer, Hash)>

Creates a user and assigning it to a pre-defined role.

Parameters:

  • body

    The payload containing the information to create a user.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(ClientUserForm, Integer, Hash)>)

    ClientUserForm data, response status code and response headers



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/stage-ruby/api/stage_api.rb', line 43

def create_user_with_http_info(body, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: StageApi.create_user ...'
  end
  # verify the required parameter 'body' is set
  if @api_client.config.client_side_validation && body.nil?
    fail ArgumentError, "Missing the required parameter 'body' when calling StageApi.create_user"
  end
  # resource path
  local_var_path = CREATE_USER_PATH

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body] || @api_client.object_to_http_body(body) 

  return_type = opts[:return_type] || 'ClientUserForm' 

  auth_names = opts[:auth_names] || ['stage-api-token']
  data, status_code, headers = @api_client.call_api(:POST, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: StageApi#create_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#credit(user_identifier, feature_identifier, as_credit, opts = {}) ⇒ AccessForm

If the user has access to a feature, this decrements the access count of that feature.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifier

    The identifier of the feature being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



307
308
309
310
# File 'lib/stage-ruby/api/stage_api.rb', line 307

def credit(user_identifier, feature_identifier, as_credit, opts = {})
  data, _status_code, _headers = un_access_with_http_info(user_identifier, [feature_identifier], true, opts)
  data
end

#credit_all(user_identifier, feature_identifiers, as_credit, opts = {}) ⇒ AccessForm

If the user has access to the features, this decrements the access counts of those features.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifiers

    The identifiers of the features being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



317
318
319
320
# File 'lib/stage-ruby/api/stage_api.rb', line 317

def credit_all(user_identifier, feature_identifiers, as_credit, opts = {})
  data, _status_code, _headers = un_access_with_http_info(user_identifier, feature_identifiers, true, opts)
  data
end

#decrement_access_count(user_identifier, feature_identifier, opts = {}) ⇒ AccessForm

If the user has access to a feature, this decrements the access count of that feature.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifier

    The identifier of the feature being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



287
288
289
290
# File 'lib/stage-ruby/api/stage_api.rb', line 287

def decrement_access_count(user_identifier, feature_identifier, opts = {})
  data, _status_code, _headers = un_access_with_http_info(user_identifier, [feature_identifier], false, opts)
  data
end

#decrement_access_count_all(user_identifier, feature_identifiers, as_credit, opts = {}) ⇒ AccessForm

If the user has access to the features, this decrements the access counts of those features.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifiers

    The identifiers of the features being accessed.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



297
298
299
300
# File 'lib/stage-ruby/api/stage_api.rb', line 297

def decrement_access_count_all(user_identifier, feature_identifiers, as_credit, opts = {})
  data, _status_code, _headers = un_access_with_http_info(user_identifier, feature_identifiers, false, opts)
  data
end

#decrement_access_count_or_credit_usage_with_http_info(user_identifier, feature_identifiers, as_credit, opts = {}) ⇒ Array<(AccessForm, Integer, Hash)>

Either decrements the access count or credits the one usage for each of the accessible features.

Parameters:

  • as_credit

    When set to true, this un-accessing of a feature is treated as a credit instead of decrementing the access count.

  • feature_identifiers

    The identifiers of the features being accessed.

  • user_identifier

    The identifier of the user who is accessing the feature.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(AccessForm, Integer, Hash)>)

    AccessForm data, response status code and response headers



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/stage-ruby/api/stage_api.rb', line 328

def decrement_access_count_or_credit_usage_with_http_info(user_identifier, feature_identifiers, as_credit, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: StageApi.un_access ...'
  end
  # verify the required parameter 'as_credit' is set
  if @api_client.config.client_side_validation && as_credit.nil?
    fail ArgumentError, "Missing the required parameter 'as_credit' when calling StageApi.un_access"
  end
  # verify the required parameter 'feature_identifiers' is set
  if @api_client.config.client_side_validation && feature_identifiers.nil?
    fail ArgumentError, "Missing the required parameter 'feature_identifiers' when calling StageApi.un_access"
  end
  # verify the required parameter 'user_identifier' is set
  if @api_client.config.client_side_validation && user_identifier.nil?
    fail ArgumentError, "Missing the required parameter 'user_identifier' when calling StageApi.un_access"
  end
  # resource path
  local_var_path = '/sdk-api/v1/users/{userIdentifier}/features'.sub('{' + 'userIdentifier' + '}', user_identifier.to_s)

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'asCredit'] = as_credit
  query_params[:'identifiers'] = @api_client.build_collection_param(feature_identifiers, :multi)

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  return_type = opts[:return_type] || 'AccessForm'

  auth_names = opts[:auth_names] || ['stage-api-token', 'stage-read-only-api-token']
  data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: StageApi#un_access\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_plansArray<PlanObjectForm>

Gets all plans.

Returns:



89
90
91
92
# File 'lib/stage-ruby/api/stage_api.rb', line 89

def get_plans()
  data, _status_code, _headers = get_plans_with_http_info({})
  data
end

#get_plans_with_http_info(opts = {}) ⇒ Array<(Array<PlanObjectForm>, Integer, Hash)>

Gets all plans.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Array<PlanObjectForm>, Integer, Hash)>)

    Array<PlanObjectForm> data, response status code and response headers



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/stage-ruby/api/stage_api.rb', line 97

def get_plans_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: StageApi.get_plans ...'
  end
  # resource path
  local_var_path = PLANS_PATH

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  return_type = opts[:return_type] || 'Array<PlanObjectForm>'

  auth_names = opts[:auth_names] || ['stage-api-token']
  data, status_code, headers = @api_client.call_api(:GET, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: StageApi#get_plans\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#has_access(user_identifier, feature_identifier) ⇒ Object



144
145
146
# File 'lib/stage-ruby/api/stage_api.rb', line 144

def has_access(user_identifier, feature_identifier)
  has_access_to_all(user_identifier, [feature_identifier])
end

#has_access_to_all(user_identifier, feature_identifiers) ⇒ Object



153
154
155
156
# File 'lib/stage-ruby/api/stage_api.rb', line 153

def has_access_to_all(user_identifier, feature_identifiers)
  data, _status_code, _headers = has_access_with_http_info(user_identifier, feature_identifiers, {})
  data.features.map { |feature| feature[:hasAccess] }.all?
end

#has_access_to_any(user_identifier, feature_identifiers) ⇒ Object



148
149
150
151
# File 'lib/stage-ruby/api/stage_api.rb', line 148

def has_access_to_any(user_identifier, feature_identifiers)
  data, _status_code, _headers = has_access_with_http_info(user_identifier, feature_identifiers, {})
  data.features.map { |feature| feature[:hasAccess] }.any?
end

#has_access_verbose(user_identifier, feature_identifiers) ⇒ AccessForm

Checks if a user has access to the identified feature.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifiers

    identifiers

Returns:



139
140
141
142
# File 'lib/stage-ruby/api/stage_api.rb', line 139

def has_access_verbose(user_identifier, feature_identifiers)
  data, _status_code, _headers = has_access_with_http_info(user_identifier, feature_identifiers, {})
  data
end

#has_access_with_http_info(user_identifier, feature_identifiers, opts = {}) ⇒ Array<(AccessForm, Integer, Hash)>

Checks if a user has access to the identified feature.

Parameters:

  • user_identifier

    The identifier of the user who is accessing the feature.

  • feature_identifiers

    identifiers

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(AccessForm, Integer, Hash)>)

    AccessForm data, response status code and response headers



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/stage-ruby/api/stage_api.rb', line 163

def has_access_with_http_info(user_identifier, feature_identifiers, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: StageApi.has_access ...'
  end
  # verify the required parameter 'feature_identifiers' is set
  if @api_client.config.client_side_validation && feature_identifiers.nil?
    fail ArgumentError, "Missing the required parameter 'feature_identifiers' when calling StageApi.has_access"
  end
  # verify the required parameter 'user_identifier' is set
  if @api_client.config.client_side_validation && user_identifier.nil?
    fail ArgumentError, "Missing the required parameter 'user_identifier' when calling StageApi.has_access"
  end
  # resource path
  local_var_path = has_access_path(user_identifier)

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'identifiers'] = @api_client.build_collection_param(feature_identifiers, :csv)

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body] 

  return_type = opts[:return_type] || 'AccessForm' 

  auth_names = opts[:auth_names] || ['stage-api-token']
  data, status_code, headers = @api_client.call_api(:GET, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: StageApi#has_access\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#update_user_plan(user_identifier, plan_identifier) ⇒ ClientUserForm

Updates a user’s plan.

Parameters:

  • user_identifier

    The identifier of the user.

  • plan_identifier

    The plan identifier.

Returns:



384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/stage-ruby/api/stage_api.rb', line 384

def update_user_plan(user_identifier, plan_identifier)
  body = Stage::ClientUserForm.new({
     client_users: [
       Stage::ClientUserObjectForm.new({
         identifier: user_identifier,
         plan_identifier: plan_identifier
       })
     ]
  })
  data, _status_code, _headers = update_user_plan_with_http_info(user_identifier, body, {})
  data
end

#update_user_plan_with_http_info(user_identifier, body, opts = {}) ⇒ Array<(ClientUserForm, Integer, Hash)>

Updates a user&#x27;s plan.

Parameters:

  • user_identifier

    The identifier of the user.

  • body

    The payload containing the information to update a user&#x27;s plan. Only identifier and planIdentifier fields are required.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(ClientUserForm, Integer, Hash)>)

    ClientUserForm data, response status code and response headers



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/stage-ruby/api/stage_api.rb', line 402

def update_user_plan_with_http_info(user_identifier, body, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: StageApi.update_user_plan ...'
  end
  # verify the required parameter 'body' is set
  if @api_client.config.client_side_validation && body.nil?
    fail ArgumentError, "Missing the required parameter 'body' when calling StageApi.update_user_plan"
  end
  # verify the required parameter 'user_identifier' is set
  if @api_client.config.client_side_validation && user_identifier.nil?
    fail ArgumentError, "Missing the required parameter 'user_identifier' when calling StageApi.update_user_plan"
  end
  # resource path
  local_var_path = update_user_plan_path(user_identifier)

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body] || @api_client.object_to_http_body(body) 

  return_type = opts[:return_type] || 'ClientUserForm' 

  auth_names = opts[:auth_names] || ['stage-api-token']
  data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: StageApi#update_user_plan\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end