Class: Cts::Mpx::Driver::Request

Inherits:
Object
  • Object
show all
Includes:
Creatable
Defined in:
lib/cts/mpx/driver/request.rb

Overview

A single request of any type to the services.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersHash

Returns headers to transmit to the services along with the request.

Returns:

  • (Hash)

    headers to transmit to the services along with the request



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cts/mpx/driver/request.rb', line 19

class Request
  include Creatable

  attribute name: 'method', kind_of: Symbol
  attribute name: 'url', kind_of: String
  attribute name: 'query', kind_of: Hash
  attribute name: 'payload', kind_of: String
  attribute name: 'response', kind_of: ::Cts::Mpx::Driver::Response
  attribute name: 'headers', kind_of: Hash

  # Call the built request.
  # @raise [RuntimeException] if the method is not a get, put, post or delete
  # @raise [RuntimeException] if the url is not a valid reference
  # @return [Cts::Mpx::Driver::Response] response from the service
  def call
    @headers ||= {}
    @query ||= {}

    call_exceptions method, url
    socket = Connections[url]
    params = {
      headers: @headers,
      path:    URI.parse(url).path,
      query:   @query
    }
    params[:body] = payload if payload

    r = socket.send method, params

    @response = Response.create original: r
    @response
  end

  private

  def call_exceptions(method, url)
    raise "#{method} is not a valid method" unless %i[get put post delete].include? method.downcase
    raise "#{url} is not a valid reference" unless Cts::Mpx::Validators.reference? url
  end
end

#methodSymbol

Returns type of rest method, GET, PUT, POST, DELETE.

Returns:

  • (Symbol)

    type of rest method, GET, PUT, POST, DELETE



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cts/mpx/driver/request.rb', line 19

class Request
  include Creatable

  attribute name: 'method', kind_of: Symbol
  attribute name: 'url', kind_of: String
  attribute name: 'query', kind_of: Hash
  attribute name: 'payload', kind_of: String
  attribute name: 'response', kind_of: ::Cts::Mpx::Driver::Response
  attribute name: 'headers', kind_of: Hash

  # Call the built request.
  # @raise [RuntimeException] if the method is not a get, put, post or delete
  # @raise [RuntimeException] if the url is not a valid reference
  # @return [Cts::Mpx::Driver::Response] response from the service
  def call
    @headers ||= {}
    @query ||= {}

    call_exceptions method, url
    socket = Connections[url]
    params = {
      headers: @headers,
      path:    URI.parse(url).path,
      query:   @query
    }
    params[:body] = payload if payload

    r = socket.send method, params

    @response = Response.create original: r
    @response
  end

  private

  def call_exceptions(method, url)
    raise "#{method} is not a valid method" unless %i[get put post delete].include? method.downcase
    raise "#{url} is not a valid reference" unless Cts::Mpx::Validators.reference? url
  end
end

#payloadString

Returns payload to be sent to the services.

Returns:

  • (String)

    payload to be sent to the services



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cts/mpx/driver/request.rb', line 19

class Request
  include Creatable

  attribute name: 'method', kind_of: Symbol
  attribute name: 'url', kind_of: String
  attribute name: 'query', kind_of: Hash
  attribute name: 'payload', kind_of: String
  attribute name: 'response', kind_of: ::Cts::Mpx::Driver::Response
  attribute name: 'headers', kind_of: Hash

  # Call the built request.
  # @raise [RuntimeException] if the method is not a get, put, post or delete
  # @raise [RuntimeException] if the url is not a valid reference
  # @return [Cts::Mpx::Driver::Response] response from the service
  def call
    @headers ||= {}
    @query ||= {}

    call_exceptions method, url
    socket = Connections[url]
    params = {
      headers: @headers,
      path:    URI.parse(url).path,
      query:   @query
    }
    params[:body] = payload if payload

    r = socket.send method, params

    @response = Response.create original: r
    @response
  end

  private

  def call_exceptions(method, url)
    raise "#{method} is not a valid method" unless %i[get put post delete].include? method.downcase
    raise "#{url} is not a valid reference" unless Cts::Mpx::Validators.reference? url
  end
end

#queryHash

Returns query to send with the request.

Returns:

  • (Hash)

    query to send with the request



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cts/mpx/driver/request.rb', line 19

class Request
  include Creatable

  attribute name: 'method', kind_of: Symbol
  attribute name: 'url', kind_of: String
  attribute name: 'query', kind_of: Hash
  attribute name: 'payload', kind_of: String
  attribute name: 'response', kind_of: ::Cts::Mpx::Driver::Response
  attribute name: 'headers', kind_of: Hash

  # Call the built request.
  # @raise [RuntimeException] if the method is not a get, put, post or delete
  # @raise [RuntimeException] if the url is not a valid reference
  # @return [Cts::Mpx::Driver::Response] response from the service
  def call
    @headers ||= {}
    @query ||= {}

    call_exceptions method, url
    socket = Connections[url]
    params = {
      headers: @headers,
      path:    URI.parse(url).path,
      query:   @query
    }
    params[:body] = payload if payload

    r = socket.send method, params

    @response = Response.create original: r
    @response
  end

  private

  def call_exceptions(method, url)
    raise "#{method} is not a valid method" unless %i[get put post delete].include? method.downcase
    raise "#{url} is not a valid reference" unless Cts::Mpx::Validators.reference? url
  end
end

#responseCts::Mpx::Driver::Response

Returns response from the service.

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cts/mpx/driver/request.rb', line 19

class Request
  include Creatable

  attribute name: 'method', kind_of: Symbol
  attribute name: 'url', kind_of: String
  attribute name: 'query', kind_of: Hash
  attribute name: 'payload', kind_of: String
  attribute name: 'response', kind_of: ::Cts::Mpx::Driver::Response
  attribute name: 'headers', kind_of: Hash

  # Call the built request.
  # @raise [RuntimeException] if the method is not a get, put, post or delete
  # @raise [RuntimeException] if the url is not a valid reference
  # @return [Cts::Mpx::Driver::Response] response from the service
  def call
    @headers ||= {}
    @query ||= {}

    call_exceptions method, url
    socket = Connections[url]
    params = {
      headers: @headers,
      path:    URI.parse(url).path,
      query:   @query
    }
    params[:body] = payload if payload

    r = socket.send method, params

    @response = Response.create original: r
    @response
  end

  private

  def call_exceptions(method, url)
    raise "#{method} is not a valid method" unless %i[get put post delete].include? method.downcase
    raise "#{url} is not a valid reference" unless Cts::Mpx::Validators.reference? url
  end
end

#urlString

Returns url to make the request against.

Returns:

  • (String)

    url to make the request against



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cts/mpx/driver/request.rb', line 19

class Request
  include Creatable

  attribute name: 'method', kind_of: Symbol
  attribute name: 'url', kind_of: String
  attribute name: 'query', kind_of: Hash
  attribute name: 'payload', kind_of: String
  attribute name: 'response', kind_of: ::Cts::Mpx::Driver::Response
  attribute name: 'headers', kind_of: Hash

  # Call the built request.
  # @raise [RuntimeException] if the method is not a get, put, post or delete
  # @raise [RuntimeException] if the url is not a valid reference
  # @return [Cts::Mpx::Driver::Response] response from the service
  def call
    @headers ||= {}
    @query ||= {}

    call_exceptions method, url
    socket = Connections[url]
    params = {
      headers: @headers,
      path:    URI.parse(url).path,
      query:   @query
    }
    params[:body] = payload if payload

    r = socket.send method, params

    @response = Response.create original: r
    @response
  end

  private

  def call_exceptions(method, url)
    raise "#{method} is not a valid method" unless %i[get put post delete].include? method.downcase
    raise "#{url} is not a valid reference" unless Cts::Mpx::Validators.reference? url
  end
end

Instance Method Details

#callCts::Mpx::Driver::Response

Call the built request.

Returns:

Raises:

  • (RuntimeException)

    if the method is not a get, put, post or delete

  • (RuntimeException)

    if the url is not a valid reference



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cts/mpx/driver/request.rb', line 33

def call
  @headers ||= {}
  @query ||= {}

  call_exceptions method, url
  socket = Connections[url]
  params = {
    headers: @headers,
    path:    URI.parse(url).path,
    query:   @query
  }
  params[:body] = payload if payload

  r = socket.send method, params

  @response = Response.create original: r
  @response
end