Exception: Assistly::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/assistly/error.rb

Overview

Custom error class for rescuing from all Assistly errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, http_headers) ⇒ Error

Returns a new instance of Error.



6
7
8
9
10
# File 'lib/assistly/error.rb', line 6

def initialize(message, http_headers)
  http_headers ||= {}
  @http_headers = Hash[http_headers]
  super message
end

Instance Attribute Details

#http_headersObject (readonly)

Returns the value of attribute http_headers.



4
5
6
# File 'lib/assistly/error.rb', line 4

def http_headers
  @http_headers
end

Instance Method Details

#ratelimit_limitObject



16
17
18
# File 'lib/assistly/error.rb', line 16

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

#ratelimit_remainingObject



20
21
22
# File 'lib/assistly/error.rb', line 20

def ratelimit_remaining
  @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect {|value| value }.to_i
end

#ratelimit_resetObject



12
13
14
# File 'lib/assistly/error.rb', line 12

def ratelimit_reset
  Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect {|value| value }.to_i)
end

#retry_afterObject



24
25
26
# File 'lib/assistly/error.rb', line 24

def retry_after
  [(ratelimit_reset - Time.now).ceil, 0].max
end