Class: UriSigner::RequestParser
- Inherits:
-
Object
- Object
- UriSigner::RequestParser
- Defined in:
- lib/uri_signer/request_parser.rb
Overview
This object takes the raw request from the inbound API call. It takes the http method used to make the request, and the full #raw_uri of the request. This object extracts the pieces necessary to pass it to the signing class. The key components are #http_method, #base_uri, and #query_params. #query_params has the core params extracted (any param starting with an underscore)
Instance Method Summary collapse
-
#base_uri ⇒ String
Returns the base_uri of the request.
-
#http? ⇒ Bool
Returns true if the scheme/protocol used was HTTP.
-
#http_method ⇒ String
Returns the uppercased HTTP Method.
-
#https? ⇒ Bool
Returns true if the scheme/protocol used was HTTPS.
-
#initialize(http_method, raw_uri) ⇒ void
constructor
Create a new RequestParser instance.
-
#parsed_uri ⇒ Addressable
Returns an instance of Addressable::URI that has been parsed.
-
#query_params ⇒ Hash
Returns the query params with the core params removed.
-
#query_params? ⇒ Bool
Returns true if query params were given.
-
#raw_uri ⇒ String
Returns the raw_uri that was provided in the constructor.
-
#signature ⇒ String
This returns the signature that was provided in the query params.
-
#signature? ⇒ Bool
Returns true if a signature was provided in the raw_uri.
Constructor Details
#initialize(http_method, raw_uri) ⇒ void
Create a new RequestParser instance
45 46 47 48 49 50 51 52 53 |
# File 'lib/uri_signer/request_parser.rb', line 45 def initialize(http_method, raw_uri) @http_method = http_method @raw_uri = raw_uri raise UriSigner::Errors::MissingHttpMethodError.new("Please provide an HTTP method") unless http_method? raise UriSigner::Errors::MissingUriError.new("Please provide a URI") unless raw_uri? extract_core_params! end |
Instance Method Details
#base_uri ⇒ String
Returns the base_uri of the request. This is the protocol, host with port, and the path.
108 109 110 |
# File 'lib/uri_signer/request_parser.rb', line 108 def base_uri [self.parsed_uri.normalized_site, self.parsed_uri.normalized_path].join('') end |
#http? ⇒ Bool
Returns true if the scheme/protocol used was HTTP
72 73 74 |
# File 'lib/uri_signer/request_parser.rb', line 72 def http? !self.https? end |
#http_method ⇒ String
Returns the uppercased HTTP Method
58 59 60 |
# File 'lib/uri_signer/request_parser.rb', line 58 def http_method @http_method.upcase end |
#https? ⇒ Bool
Returns true if the scheme/protocol used was HTTPS
65 66 67 |
# File 'lib/uri_signer/request_parser.rb', line 65 def https? 'https' == self.parsed_uri.scheme.downcase end |
#parsed_uri ⇒ Addressable
Returns an instance of Addressable::URI that has been parsed. This allows us to extract the core parts of the raw_uri
87 88 89 |
# File 'lib/uri_signer/request_parser.rb', line 87 def parsed_uri @parsed_uri ||= self.raw_uri.extend(UriSigner::Helpers::String).to_parsed_uri end |
#query_params ⇒ Hash
Returns the query params with the core params removed
94 95 96 |
# File 'lib/uri_signer/request_parser.rb', line 94 def query_params @query_params ||= raw_query_params end |
#query_params? ⇒ Bool
Returns true if query params were given
101 102 103 |
# File 'lib/uri_signer/request_parser.rb', line 101 def query_params? !self.query_params.blank? end |
#raw_uri ⇒ String
Returns the raw_uri that was provided in the constructor
79 80 81 |
# File 'lib/uri_signer/request_parser.rb', line 79 def raw_uri @raw_uri end |
#signature ⇒ String
This returns the signature that was provided in the query params
115 116 117 |
# File 'lib/uri_signer/request_parser.rb', line 115 def signature @_signature.extend(UriSigner::Helpers::String).escaped end |
#signature? ⇒ Bool
Returns true if a signature was provided in the raw_uri
122 123 124 |
# File 'lib/uri_signer/request_parser.rb', line 122 def signature? !@_signature.blank? end |