Class: MockServer::HttpRequest

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(method: nil, path: nil, query_string_parameters: nil, headers: nil, cookies: nil, body: nil, secure: nil, keep_alive: nil, respond_before_body: nil, path_parameters: nil, socket_address: nil) ⇒ HttpRequest

Returns a new instance of HttpRequest.



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/mockserver/models.rb', line 505

def initialize(method: nil, path: nil, query_string_parameters: nil, headers: nil,
               cookies: nil, body: nil, secure: nil, keep_alive: nil,
               respond_before_body: nil, path_parameters: nil, socket_address: nil)
  @method = method
  @path = path
  @query_string_parameters = query_string_parameters
  @headers = headers
  @cookies = cookies
  @body = body
  @secure = secure
  @keep_alive = keep_alive
  @respond_before_body = respond_before_body
  @path_parameters = path_parameters
  @socket_address = socket_address
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#cookiesObject

Returns the value of attribute cookies.



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

def cookies
  @cookies
end

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#keep_aliveObject

Returns the value of attribute keep_alive.



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

def keep_alive
  @keep_alive
end

#methodObject

Returns the value of attribute method.



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

def method
  @method
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#path_parametersObject

Returns the value of attribute path_parameters.



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

def path_parameters
  @path_parameters
end

#query_string_parametersObject

Returns the value of attribute query_string_parameters.



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

def query_string_parameters
  @query_string_parameters
end

#respond_before_bodyObject

Returns the value of attribute respond_before_body.



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

def respond_before_body
  @respond_before_body
end

#secureObject

Returns the value of attribute secure.



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

def secure
  @secure
end

#socket_addressObject

Returns the value of attribute socket_address.



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

def socket_address
  @socket_address
end

Class Method Details

.from_hash(data) ⇒ Object



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/mockserver/models.rb', line 537

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

  new(
    method:                  data['method'],
    path:                    data['path'],
    query_string_parameters: MockServer.deserialize_key_multi_values(data['queryStringParameters']),
    headers:                 MockServer.deserialize_key_multi_values(data['headers']),
    cookies:                 MockServer.deserialize_key_multi_values(data['cookies']),
    body:                    MockServer.deserialize_body(data['body']),
    secure:                  data['secure'],
    keep_alive:              data['keepAlive'],
    respond_before_body:     data['respondBeforeBody'],
    path_parameters:         MockServer.deserialize_key_multi_values(data['pathParameters']),
    socket_address:          SocketAddress.from_hash(data['socketAddress'])
  )
end

.request(path: nil) ⇒ Object



555
556
557
# File 'lib/mockserver/models.rb', line 555

def self.request(path: nil)
  new(path: path)
end

Instance Method Details

#to_hObject



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/mockserver/models.rb', line 521

def to_h
  MockServer.strip_none({
    'method'                => @method,
    'path'                  => @path,
    'queryStringParameters' => MockServer.serialize_key_multi_values(@query_string_parameters),
    'headers'               => MockServer.serialize_key_multi_values(@headers),
    'cookies'               => MockServer.serialize_key_multi_values(@cookies),
    'body'                  => MockServer.serialize_body(@body),
    'secure'                => @secure,
    'keepAlive'             => @keep_alive,
    'respondBeforeBody'     => @respond_before_body,
    'pathParameters'        => MockServer.serialize_key_multi_values(@path_parameters),
    'socketAddress'         => @socket_address&.to_h
  })
end

#with_body(body) ⇒ Object



587
588
589
590
# File 'lib/mockserver/models.rb', line 587

def with_body(body)
  @body = body
  self
end


581
582
583
584
585
# File 'lib/mockserver/models.rb', line 581

def with_cookie(name, value)
  @cookies ||= []
  @cookies << KeyToMultiValue.new(name: name, values: [value])
  self
end

#with_header(name, *values) ⇒ Object



569
570
571
572
573
# File 'lib/mockserver/models.rb', line 569

def with_header(name, *values)
  @headers ||= []
  @headers << KeyToMultiValue.new(name: name, values: values.flatten)
  self
end

#with_keep_alive(keep_alive) ⇒ Object



597
598
599
600
# File 'lib/mockserver/models.rb', line 597

def with_keep_alive(keep_alive)
  @keep_alive = keep_alive
  self
end

#with_method(method) ⇒ Object



559
560
561
562
# File 'lib/mockserver/models.rb', line 559

def with_method(method)
  @method = method
  self
end

#with_path(path) ⇒ Object



564
565
566
567
# File 'lib/mockserver/models.rb', line 564

def with_path(path)
  @path = path
  self
end

#with_query_param(name, *values) ⇒ Object



575
576
577
578
579
# File 'lib/mockserver/models.rb', line 575

def with_query_param(name, *values)
  @query_string_parameters ||= []
  @query_string_parameters << KeyToMultiValue.new(name: name, values: values.flatten)
  self
end

#with_respond_before_body(respond_before_body) ⇒ Object



602
603
604
605
# File 'lib/mockserver/models.rb', line 602

def with_respond_before_body(respond_before_body)
  @respond_before_body = respond_before_body
  self
end

#with_secure(secure) ⇒ Object



592
593
594
595
# File 'lib/mockserver/models.rb', line 592

def with_secure(secure)
  @secure = secure
  self
end