class BanksApi::Shinsei::FaradayMiddleware
Constants
- USER_AGENT
Public Instance Methods
call(request_env)
click to toggle source
# 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