Class: Nimbu::Request::ContentLocale
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Nimbu::Request::ContentLocale
- Includes:
- Utils::Url
- Defined in:
- lib/nimbu-api/request/content_locale.rb
Constant Summary collapse
- CONTENT_LOCALE =
'content_locale'.freeze
Constants included from Utils::Url
Utils::Url::DEFAULT_QUERY_SEP, Utils::Url::KEY_VALUE_SEP
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, *args) ⇒ ContentLocale
constructor
A new instance of ContentLocale.
- #query_params(url) ⇒ Object
Methods included from Utils::Url
#build_query, #escape, #parse_query, #parse_query_for_param, #unescape
Constructor Details
#initialize(app, *args) ⇒ ContentLocale
Returns a new instance of ContentLocale.
21 22 23 24 25 |
# File 'lib/nimbu-api/request/content_locale.rb', line 21 def initialize(app, *args) super app @app = app @content_locale = args.shift end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/nimbu-api/request/content_locale.rb', line 12 def call(env) if @content_locale params = { CONTENT_LOCALE => @content_locale }.update query_params(env[:url]) env[:url].query = build_query params end @app.call env end |
#query_params(url) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/nimbu-api/request/content_locale.rb', line 27 def query_params(url) if url.query.nil? or url.query.empty? {} else parse_query url.query end end |