Class: Fassbinder::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fassbinder/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response, locale) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fassbinder/response.rb', line 8

def initialize(response, locale)
  unless response.valid?
    message =
      if response.has_errors?
        response.errors.first['Message']
      else
        response.code
      end

    raise InvalidResponse, message
  end

  @response = response
  @locale   = locale.to_sym
end

Instance Method Details

#each(&block) ⇒ Object

Yields each snapshot to given block.



26
27
28
# File 'lib/fassbinder/response.rb', line 26

def each(&block)
  @response.each('Item') { |doc| block.call(build_book(doc)) }
end

#errorsObject



30
31
32
33
34
# File 'lib/fassbinder/response.rb', line 30

def errors
  @response.errors.map do |error|
    error['Message'].scan(/[0-9A-Z]{10}/).first rescue nil
  end.compact
end