Sha256: 41749f908b9912dbc8a543afca7d3b5ee70667830cd426bd2cfbad80fa614d12

Contents?: true

Size: 743 Bytes

Versions: 8

Compression:

Stored size: 743 Bytes

Contents

module Flattr
  # Custom error class for rescuing from all Flattr errors
  class Error < StandardError
    attr_reader :http_headers

    # Private: Initializes a new Error object
    #
    # message - Error message
    # http_headers - Hash with http_headers
    #
    # Returns a Flattr::Error
    def initialize(message, http_headers)
      @http_headers = Hash[http_headers]
      super(message)
    end

    # @return [Integer]
    def ratelimit_limit
      @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
    end

    # @return [Integer]
    def ratelimit_remaining
      @http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
flattr-0.3.7 lib/flattr/error.rb
flattr-0.3.6 lib/flattr/error.rb
flattr-0.3.5 lib/flattr/error.rb
flattr-0.3.4 lib/flattr/error.rb
flattr-0.3.3 lib/flattr/error.rb
flattr-0.3.2 lib/flattr/error.rb
flattr-0.3.1 lib/flattr/error.rb
flattr-0.3.0 lib/flattr/error.rb