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, file_path: nil, template_type: nil) ⇒ Body

Returns a new instance of Body.



426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/mockserver/models.rb', line 426

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

Instance Attribute Details

#base64_bytesObject

Returns the value of attribute base64_bytes.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def base64_bytes
  @base64_bytes
end

#charsetObject

Returns the value of attribute charset.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def charset
  @charset
end

#content_typeObject

Returns the value of attribute content_type.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def content_type
  @content_type
end

#file_pathObject

Returns the value of attribute file_path.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def file_path
  @file_path
end

#jsonObject

Returns the value of attribute json.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def json
  @json
end

#not_bodyObject

Returns the value of attribute not_body.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def not_body
  @not_body
end

#stringObject

Returns the value of attribute string.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def string
  @string
end

#template_typeObject

Returns the value of attribute template_type.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def template_type
  @template_type
end

#typeObject

Returns the value of attribute type.



423
424
425
# File 'lib/mockserver/models.rb', line 423

def type
  @type
end

Class Method Details

.exact(value) ⇒ Object



481
482
483
# File 'lib/mockserver/models.rb', line 481

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

.file(file_path, content_type: nil, template_type: nil) ⇒ Object



489
490
491
# File 'lib/mockserver/models.rb', line 489

def self.file(file_path, content_type: nil, template_type: nil)
  new(type: 'FILE', file_path: file_path, content_type: content_type, template_type: template_type)
end

.from_hash(data) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/mockserver/models.rb', line 453

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'],
    file_path:     data['filePath'],
    template_type: data['templateType']
  )
end

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



497
498
499
# File 'lib/mockserver/models.rb', line 497

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



473
474
475
# File 'lib/mockserver/models.rb', line 473

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

.json_rpc(method_name, params_schema: nil) ⇒ Object



493
494
495
# File 'lib/mockserver/models.rb', line 493

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

.regex(value) ⇒ Object



477
478
479
# File 'lib/mockserver/models.rb', line 477

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

.string(value) ⇒ Object



469
470
471
# File 'lib/mockserver/models.rb', line 469

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

.xml(value) ⇒ Object



485
486
487
# File 'lib/mockserver/models.rb', line 485

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

Instance Method Details

#to_hObject



439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/mockserver/models.rb', line 439

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['filePath']     = @file_path     unless @file_path.nil?
  result['templateType'] = @template_type unless @template_type.nil?
  result
end

#with_template_type(template_type) ⇒ Object



501
502
503
504
# File 'lib/mockserver/models.rb', line 501

def with_template_type(template_type)
  @template_type = template_type
  self
end