Class: BanksApi::Shinsei::FaradayMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- BanksApi::Shinsei::FaradayMiddleware
- Defined in:
- lib/banks_api/shinsei/faraday_middleware.rb
Instance Method Summary collapse
Instance Method Details
#call(request_env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/banks_api/shinsei/faraday_middleware.rb', line 6 def call(request_env) request_env.body.force_encoding(Encoding::ASCII_8BIT) request_env.request_headers["User-Agent"] = USER_AGENT @app.call(request_env).on_complete do |response_env| # #toutf8 converts half-width Katakana to full-width (???) # As recommended in the official Ruby documentation (see link below), # we'll use this instead. # https://docs.ruby-lang.org/ja/2.4.0/method/Kconv/m/toutf8.html response_env.body = NKF.nkf("-wxm0", response_env.body) if response_env.response_headers["content-type"]&.match?(/text\/html/) response_env.body = JsParser.data_for(response_env.body) end end end |