Sha256: 2a4b0355d2c508dc17de2aa65f5a8282870a3ac7594d4256d90c2ff83a1a283f
Contents?: true
Size: 1.05 KB
Versions: 8
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true module Yext module Api module Utils module Middleware # Faraday Middleware for extracting API limits from call responses. class ApiRateLimits < Faraday::Response::Middleware def call(env) @app.call(env).on_complete do |environment| save_rates(environment, Yext::Api::Utils::ApiFinder.new(env[:url], env[:method]).find_api) env.response end end private def save_rates(environment, api_module) return if api_module.blank? response_headers = environment[:response_headers] return unless response_headers.key?("rate-limit-remaining") api_module.send(:update_rates, remaining: response_headers["rate-limit-remaining"].to_i, limit: response_headers["rate-limit-limit"].to_i, reset_at: Time.at(response_headers["rate-limit-reset"].to_i)) end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems