Class: Yext::Api::Utils::Middleware::DefaultParameters
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Yext::Api::Utils::Middleware::DefaultParameters
- Extended by:
- Memoist
- Defined in:
- lib/yext/api/utils/middleware/default_parameters.rb
Overview
Faraday Middleware for adding Configuration default values to API calls as needed.
Most options can be set via scopes and the soped values will be kept if they are used. i.e. the existing query string values will be kept if they exist.
Because Spyke puts ‘where` options into the body OR the query depending on the type of request being made, we have to move the Yext query options out of the body into the query if there is a body.
The following configuration options are defaulted:
validation_level: Added to query parameters if not already there and is not nil
api_key: Added to query parameters if not already there
api_version: Added to qeury parameters if not already there
account_id: Inserted into the path if the path includes the Account default URI and no
account_id was specified.
The following values will be moved out of the body into the query string if they are found:
account_id * Not used if in body. If set it will already be in the path.
v
api_key
validation
yext_username
yext_user_id
Instance Attribute Summary collapse
-
#body_json ⇒ Object
readonly
Returns the value of attribute body_json.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request_env ⇒ Object
readonly
Returns the value of attribute request_env.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
Instance Attribute Details
#body_json ⇒ Object (readonly)
Returns the value of attribute body_json.
33 34 35 |
# File 'lib/yext/api/utils/middleware/default_parameters.rb', line 33 def body_json @body_json end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
33 34 35 |
# File 'lib/yext/api/utils/middleware/default_parameters.rb', line 33 def configuration @configuration end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
33 34 35 |
# File 'lib/yext/api/utils/middleware/default_parameters.rb', line 33 def params @params end |
#request_env ⇒ Object (readonly)
Returns the value of attribute request_env.
33 34 35 |
# File 'lib/yext/api/utils/middleware/default_parameters.rb', line 33 def request_env @request_env end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
33 34 35 |
# File 'lib/yext/api/utils/middleware/default_parameters.rb', line 33 def url @url end |
Instance Method Details
#call(call_env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yext/api/utils/middleware/default_parameters.rb', line 39 def call(call_env) get_attribute_values(call_env) body_json.delete(:account_id) add_username_headers add_default_query_params save_query_params save_body @app.call(request_env) end |