Class: Attune::ParamFlattener

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/attune/param_flattener.rb

Overview

Faraday 0.8 can't make resuests like /?ids=123&ids=456 and forces the form /?ids[]=123&ids[]=456 (this is fixed in faraday 0.9)

Fortunately faraday's middleware is quite powerful. This just strips the array syntax from the request.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/attune/param_flattener.rb', line 8

def call(env)
  url = env[:url]

  # replaces ?foo[]=123 with ?foo=123
  url.query = url.query.gsub('%5B%5D', '') if url.query

  @app.call(env)
end