Class: Foobara::CommandConnectors::Http::Request
- Inherits:
-
Foobara::CommandConnector::Request
- Object
- Foobara::CommandConnector::Request
- Foobara::CommandConnectors::Http::Request
- Defined in:
- foobara-http-command-connector-0.0.23/src/http/request.rb
Direct Known Subclasses
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#host ⇒ Object
Returns the value of attribute host.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#query_string ⇒ Object
Returns the value of attribute query_string.
-
#remote_ip ⇒ Object
Returns the value of attribute remote_ip.
-
#response_headers ⇒ Object
Returns the value of attribute response_headers.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
Attributes inherited from Foobara::CommandConnector::Request
#command, #command_class, #command_connector, #error, #response, #serializers
Instance Method Summary collapse
- #action ⇒ Object
- #argument ⇒ Object
- #full_command_name ⇒ Object
-
#initialize(path:, method: nil, headers: {}, query_string: "", body: "", scheme: nil, host: nil, port: nil, cookies: nil, remote_ip: nil, prefix: nil) ⇒ Request
constructor
A new instance of Request.
- #inputs ⇒ Object
- #parsed_body ⇒ Object
- #parsed_query_string ⇒ Object
- #prefixless_path ⇒ Object
- #set_action_and_command_name ⇒ Object
- #set_response_header(name, value) ⇒ Object
- #url ⇒ Object
Methods inherited from Foobara::CommandConnector::Request
#error_collection, #outcome, #response_body, #result, #serializer, #success?
Methods included from TruncatedInspect
Constructor Details
#initialize(path:, method: nil, headers: {}, query_string: "", body: "", scheme: nil, host: nil, port: nil, cookies: nil, remote_ip: nil, prefix: nil) ⇒ Request
Returns a new instance of Request.
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 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 20 def initialize( path:, method: nil, headers: {}, query_string: "", body: "", scheme: nil, host: nil, port: nil, cookies: nil, remote_ip: nil, prefix: nil ) self.path = path self.method = method self.headers = headers self.query_string = query_string self.body = body self.scheme = scheme self.host = host self.port = port self. = self.remote_ip = remote_ip self.prefix = prefix super() end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def body @body end |
#cookies ⇒ Object
Returns the value of attribute cookies.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def @cookies end |
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def headers @headers end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def host @host end |
#method ⇒ Object
Returns the value of attribute method.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def path @path end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def port @port end |
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def prefix @prefix end |
#query_string ⇒ Object
Returns the value of attribute query_string.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def query_string @query_string end |
#remote_ip ⇒ Object
Returns the value of attribute remote_ip.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def remote_ip @remote_ip end |
#response_headers ⇒ Object
Returns the value of attribute response_headers.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def response_headers @response_headers end |
#scheme ⇒ Object
Returns the value of attribute scheme.
7 8 9 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 7 def scheme @scheme end |
Instance Method Details
#action ⇒ Object
83 84 85 86 87 88 89 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 83 def action unless defined?(@action) set_action_and_command_name end @action end |
#argument ⇒ Object
91 92 93 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 91 def argument prefixless_path.split("/")[2] end |
#full_command_name ⇒ Object
62 63 64 65 66 67 68 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 62 def full_command_name unless defined?(@full_command_name) set_action_and_command_name end @full_command_name end |
#inputs ⇒ Object
58 59 60 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 58 def inputs @inputs ||= parsed_body.merge(parsed_query_string) end |
#parsed_body ⇒ Object
70 71 72 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 70 def parsed_body body.empty? ? {} : JSON.parse(body) end |
#parsed_query_string ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 74 def parsed_query_string if query_string.nil? || query_string.empty? {} else # TODO: override this in rack connector to use better rack utils CGI.parse(query_string).transform_values!(&:first) end end |
#prefixless_path ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 101 def prefixless_path return @prefixless_path if defined?(@prefixless_path) prefix = self.prefix @prefixless_path = if prefix path.gsub(/^#{prefix}\//, "/") else path end end |
#set_action_and_command_name ⇒ Object
95 96 97 98 99 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 95 def set_action_and_command_name @action, *full_command_name = prefixless_path[1..].split("/") @full_command_name = full_command_name.join("::").gsub("/", "::") end |
#set_response_header(name, value) ⇒ Object
113 114 115 116 117 118 119 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 113 def set_response_header(name, value) name = name.to_s name = name.downcase self.response_headers ||= {} self.response_headers = response_headers.merge(name => value) end |
#url ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'foobara-http-command-connector-0.0.23/src/http/request.rb', line 48 def url URI::Generic.build( scheme:, host:, port:, path:, query: query_string.nil? || query_string.empty? ? nil : query_string ).to_s end |