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.



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/mockserver/models.rb', line 525

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.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def body
  @body
end

#cookiesObject

Returns the value of attribute cookies.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def cookies
  @cookies
end

#headersObject

Returns the value of attribute headers.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def headers
  @headers
end

#keep_aliveObject

Returns the value of attribute keep_alive.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def keep_alive
  @keep_alive
end

#methodObject

Returns the value of attribute method.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def method
  @method
end

#pathObject

Returns the value of attribute path.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def path
  @path
end

#path_parametersObject

Returns the value of attribute path_parameters.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def path_parameters
  @path_parameters
end

#query_string_parametersObject

Returns the value of attribute query_string_parameters.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def query_string_parameters
  @query_string_parameters
end

#respond_before_bodyObject

Returns the value of attribute respond_before_body.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def respond_before_body
  @respond_before_body
end

#secureObject

Returns the value of attribute secure.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def secure
  @secure
end

#socket_addressObject

Returns the value of attribute socket_address.



521
522
523
# File 'lib/mockserver/models.rb', line 521

def socket_address
  @socket_address
end

Class Method Details

.from_hash(data) ⇒ Object



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/mockserver/models.rb', line 557

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



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

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

Instance Method Details

#to_hObject



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

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



607
608
609
610
# File 'lib/mockserver/models.rb', line 607

def with_body(body)
  @body = body
  self
end


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

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

#with_header(name, *values) ⇒ Object



589
590
591
592
593
# File 'lib/mockserver/models.rb', line 589

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

#with_keep_alive(keep_alive) ⇒ Object



617
618
619
620
# File 'lib/mockserver/models.rb', line 617

def with_keep_alive(keep_alive)
  @keep_alive = keep_alive
  self
end

#with_method(method) ⇒ Object



579
580
581
582
# File 'lib/mockserver/models.rb', line 579

def with_method(method)
  @method = method
  self
end

#with_path(path) ⇒ Object



584
585
586
587
# File 'lib/mockserver/models.rb', line 584

def with_path(path)
  @path = path
  self
end

#with_query_param(name, *values) ⇒ Object



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

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



622
623
624
625
# File 'lib/mockserver/models.rb', line 622

def with_respond_before_body(respond_before_body)
  @respond_before_body = respond_before_body
  self
end

#with_secure(secure) ⇒ Object



612
613
614
615
# File 'lib/mockserver/models.rb', line 612

def with_secure(secure)
  @secure = secure
  self
end