Class: LinkIO::Request
- Inherits:
-
Object
- Object
- LinkIO::Request
- Defined in:
- lib/linkio/request.rb
Overview
A framework-agnostic view of an incoming HTTP request, containing only what Client#handle_deep_link needs. Build one directly, from a Rack env with Request.from_rack, or let the Rails engine construct it for you.
Instance Attribute Summary collapse
-
#client_ip ⇒ Object
readonly
Returns the value of attribute client_ip.
-
#device_id ⇒ Object
readonly
Returns the value of attribute device_id.
-
#full_url ⇒ Object
readonly
Returns the value of attribute full_url.
-
#path_params ⇒ Object
readonly
Returns the value of attribute path_params.
-
#query_params ⇒ Object
readonly
Returns the value of attribute query_params.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Class Method Summary collapse
-
.from_rack(env, path_params: {}) ⇒ LinkIO::Request
Build a Request from a Rack environment hash.
Instance Method Summary collapse
-
#initialize(full_url:, client_ip:, user_agent: nil, query_params: {}, path_params: {}, device_id: nil) ⇒ Request
constructor
A new instance of Request.
-
#params ⇒ Hash{String => Object}
Merged query + path params (path params win), matching the Node backend's behaviour of overlaying
req.paramsonto the parsed query params.
Constructor Details
#initialize(full_url:, client_ip:, user_agent: nil, query_params: {}, path_params: {}, device_id: nil) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 21 22 23 |
# File 'lib/linkio/request.rb', line 16 def initialize(full_url:, client_ip:, user_agent: nil, query_params: {}, path_params: {}, device_id: nil) @user_agent = user_agent.to_s @full_url = full_url @query_params = stringify(query_params) @path_params = stringify(path_params) @client_ip = client_ip @device_id = device_id end |
Instance Attribute Details
#client_ip ⇒ Object (readonly)
Returns the value of attribute client_ip.
8 9 10 |
# File 'lib/linkio/request.rb', line 8 def client_ip @client_ip end |
#device_id ⇒ Object (readonly)
Returns the value of attribute device_id.
8 9 10 |
# File 'lib/linkio/request.rb', line 8 def device_id @device_id end |
#full_url ⇒ Object (readonly)
Returns the value of attribute full_url.
8 9 10 |
# File 'lib/linkio/request.rb', line 8 def full_url @full_url end |
#path_params ⇒ Object (readonly)
Returns the value of attribute path_params.
8 9 10 |
# File 'lib/linkio/request.rb', line 8 def path_params @path_params end |
#query_params ⇒ Object (readonly)
Returns the value of attribute query_params.
8 9 10 |
# File 'lib/linkio/request.rb', line 8 def query_params @query_params end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
8 9 10 |
# File 'lib/linkio/request.rb', line 8 def user_agent @user_agent end |
Class Method Details
.from_rack(env, path_params: {}) ⇒ LinkIO::Request
Build a Request from a Rack environment hash.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/linkio/request.rb', line 40 def self.from_rack(env, path_params: {}) user_agent = env["HTTP_USER_AGENT"] full_url = rack_full_url(env) query = Utils.parse_query_params(full_url) ip = Utils.client_ip( forwarded_for: env["HTTP_X_FORWARDED_FOR"], remote_address: env["REMOTE_ADDR"] ) device_id = query["deviceId"] || env["HTTP_X_DEVICE_ID"] new( user_agent: user_agent, full_url: full_url, query_params: query, path_params: path_params, client_ip: ip, device_id: device_id ) end |
Instance Method Details
#params ⇒ Hash{String => Object}
Merged query + path params (path params win), matching the Node backend's
behaviour of overlaying req.params onto the parsed query params.
29 30 31 32 33 |
# File 'lib/linkio/request.rb', line 29 def params merged = query_params.dup path_params.each { |k, v| merged[k] = v unless v.nil? || v.to_s.empty? } merged end |