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.26/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
#authenticated_credential, #authenticated_user, #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
- #url ⇒ Object
Methods inherited from Foobara::CommandConnector::Request
#authenticate, #authenticator, #error_collection, #mutate_request, #outcome, #relevant_entity_classes, #response_body, #result, #serializer, #success?
Methods included from NestedTransactionable
#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction, with_needed_transactions_for_type
Methods included from Foobara::Concern
foobara_class_methods_module_for, foobara_concern?, included
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 47 48 49 50 |
# File 'foobara-http-command-connector-0.0.26/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 ) if = .transform_keys(&:to_s) end 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.26/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.26/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.26/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.26/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.26/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.26/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.26/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.26/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.26/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.26/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.26/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.26/src/http/request.rb', line 7 def scheme @scheme end |
Instance Method Details
#action ⇒ Object
87 88 89 90 91 92 93 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 87 def action unless defined?(@action) set_action_and_command_name end @action end |
#argument ⇒ Object
95 96 97 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 95 def argument prefixless_path.split("/")[2] end |
#full_command_name ⇒ Object
66 67 68 69 70 71 72 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 66 def full_command_name unless defined?(@full_command_name) set_action_and_command_name end @full_command_name end |
#inputs ⇒ Object
62 63 64 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 62 def inputs @inputs ||= parsed_body.merge(parsed_query_string) end |
#parsed_body ⇒ Object
74 75 76 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 74 def parsed_body body.empty? ? {} : JSON.parse(body) end |
#parsed_query_string ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 78 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
105 106 107 108 109 110 111 112 113 114 115 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 105 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
99 100 101 102 103 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 99 def set_action_and_command_name @action, *full_command_name = prefixless_path[1..].split("/") @full_command_name = full_command_name.join("::").gsub("/", "::") end |
#url ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'foobara-http-command-connector-0.0.26/src/http/request.rb', line 52 def url URI::Generic.build( scheme:, host:, port:, path:, query: query_string.nil? || query_string.empty? ? nil : query_string ).to_s end |