Class: MockServer::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, string: nil, json: nil, base64_bytes: nil, not_body: nil, content_type: nil, charset: nil) ⇒ Body

Returns a new instance of Body.



344
345
346
347
348
349
350
351
352
# File 'lib/mockserver/models.rb', line 344

def initialize(type: nil, string: nil, json: nil, base64_bytes: nil, not_body: nil, content_type: nil, charset: nil)
  @type = type
  @string = string
  @json = json
  @base64_bytes = base64_bytes
  @not_body = not_body
  @content_type = content_type
  @charset = charset
end

Instance Attribute Details

#base64_bytesObject

Returns the value of attribute base64_bytes.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def base64_bytes
  @base64_bytes
end

#charsetObject

Returns the value of attribute charset.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def charset
  @charset
end

#content_typeObject

Returns the value of attribute content_type.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def content_type
  @content_type
end

#jsonObject

Returns the value of attribute json.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def json
  @json
end

#not_bodyObject

Returns the value of attribute not_body.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def not_body
  @not_body
end

#stringObject

Returns the value of attribute string.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def string
  @string
end

#typeObject

Returns the value of attribute type.



342
343
344
# File 'lib/mockserver/models.rb', line 342

def type
  @type
end

Class Method Details

.exact(value) ⇒ Object



392
393
394
# File 'lib/mockserver/models.rb', line 392

def self.exact(value)
  new(type: 'STRING', string: value)
end

.from_hash(data) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/mockserver/models.rb', line 366

def self.from_hash(data)
  return nil if data.nil?

  new(
    type:         data['type'],
    string:       data['string'],
    json:         data['json'],
    base64_bytes: data['base64Bytes'],
    not_body:     data['not'],
    content_type: data['contentType'],
    charset:      data['charset']
  )
end

.graphql(query, operation_name: nil, variables_schema: nil) ⇒ Object



404
405
406
# File 'lib/mockserver/models.rb', line 404

def self.graphql(query, operation_name: nil, variables_schema: nil)
  GraphQLBody.new(query: query, operation_name: operation_name, variables_schema: variables_schema)
end

.json(value) ⇒ Object



384
385
386
# File 'lib/mockserver/models.rb', line 384

def self.json(value)
  new(type: 'JSON', json: value)
end

.json_rpc(method_name, params_schema: nil) ⇒ Object



400
401
402
# File 'lib/mockserver/models.rb', line 400

def self.json_rpc(method_name, params_schema: nil)
  JsonRpcBody.new(method_name: method_name, params_schema: params_schema)
end

.regex(value) ⇒ Object



388
389
390
# File 'lib/mockserver/models.rb', line 388

def self.regex(value)
  new(type: 'REGEX', string: value)
end

.string(value) ⇒ Object



380
381
382
# File 'lib/mockserver/models.rb', line 380

def self.string(value)
  new(type: 'STRING', string: value)
end

.xml(value) ⇒ Object



396
397
398
# File 'lib/mockserver/models.rb', line 396

def self.xml(value)
  new(type: 'XML', string: value)
end

Instance Method Details

#to_hObject



354
355
356
357
358
359
360
361
362
363
364
# File 'lib/mockserver/models.rb', line 354

def to_h
  result = {}
  result['type']        = @type        unless @type.nil?
  result['string']      = @string      unless @string.nil?
  result['json']        = @json        unless @json.nil?
  result['base64Bytes'] = @base64_bytes unless @base64_bytes.nil?
  result['not']         = @not_body    unless @not_body.nil?
  result['contentType'] = @content_type unless @content_type.nil?
  result['charset']     = @charset     unless @charset.nil?
  result
end