Sha256: 6c89a5464e80f5412fbc1658c140333fc459e1d2d0cc866e726f760d5d46fbe4

Contents?: true

Size: 625 Bytes

Versions: 11

Compression:

Stored size: 625 Bytes

Contents

require 'net/http'

# Patch the method which retrieves headers for API rate limit dynamically
module NS1::Transport
  class NetHttp
    def process_response(response)
      sleep(response.to_hash["x-ratelimit-period"].first.to_i /
        [1, response.to_hash["x-ratelimit-remaining"].first.to_i].max.to_f)

      body = JSON.parse(response.body)
      case response
      when Net::HTTPOK
        NS1::Response::Success.new(body, response.code.to_i)
      else
        NS1::Response::Error.new(body, response.code.to_i)
      end
    rescue JSON::ParserError
      raise NS1::Transport::ResponseParseError
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
record_store-6.1.0 lib/record_store/provider/ns1/patch_api_header.rb
record_store-6.0.1 lib/record_store/provider/ns1/patch_api_header.rb
record_store-6.0.0 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.11.0 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.10.0 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.9.0 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.8.0 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.7.4 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.7.3 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.7.2 lib/record_store/provider/ns1/patch_api_header.rb
record_store-5.7.1 lib/record_store/provider/ns1/patch_api_header.rb