Class: Hcp::Answer

Inherits:
Object
  • Object
show all
Defined in:
lib/hcp/answer.rb

Overview

What Housecall Pro answered: the body it carries, or the refusal it stands for.

Constant Summary collapse

RESET_HEADER =

The header Housecall Pro names the epoch a rate limit lifts at.

'RateLimit-Reset'

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Answer

Returns a new instance of Answer.

Parameters:

  • response (Net::HTTPResponse)

    what Housecall Pro sent back.



8
9
10
# File 'lib/hcp/answer.rb', line 8

def initialize(response)
  @response = response
end

Instance Method Details

#bodyHash

Returns the record or page Housecall Pro answered with.

Returns:

  • (Hash)

    the record or page Housecall Pro answered with.



13
14
15
16
17
18
19
20
# File 'lib/hcp/answer.rb', line 13

def body
  case @response
    when Net::HTTPSuccess then parsed
    when Net::HTTPNotFound then raise NotFound, message
    when Net::HTTPTooManyRequests then raise TooManyRequests.new(message, reset_at)
    else raise Error, message
  end
end