Class: Cts::Mpx::Driver::Request
- Inherits:
-
Object
- Object
- Cts::Mpx::Driver::Request
- Includes:
- Creatable
- Defined in:
- lib/cts/mpx/driver/request.rb
Overview
A single request of any type to the services.
Instance Attribute Summary collapse
-
#headers ⇒ Hash
Headers to transmit to the services along with the request.
-
#method ⇒ Symbol
Type of rest method, GET, PUT, POST, DELETE.
-
#payload ⇒ String
Payload to be sent to the services.
-
#query ⇒ Hash
Query to send with the request.
-
#response ⇒ Cts::Mpx::Driver::Response
Response from the service.
-
#url ⇒ String
Url to make the request against.
Instance Method Summary collapse
-
#call ⇒ Cts::Mpx::Driver::Response
Call the built request.
Instance Attribute Details
#headers ⇒ Hash
Returns 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 |
#method ⇒ Symbol
Returns 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 |
#payload ⇒ String
Returns 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 |
#query ⇒ Hash
Returns 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 |
#response ⇒ Cts::Mpx::Driver::Response
Returns response from the service.
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 |
#url ⇒ String
Returns 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
#call ⇒ Cts::Mpx::Driver::Response
Call the built request.
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 |