Class: Ecoportal::API::Common::BatchResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/ecoportal/api/common/batch_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, result = nil) ⇒ BatchResponse

Returns a new instance of BatchResponse.



8
9
10
11
12
# File 'lib/ecoportal/api/common/batch_response.rb', line 8

def initialize(status, body, result = nil)
  @status = HTTP::Response::Status.new(status)
  @body   = body
  @result = result
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/ecoportal/api/common/batch_response.rb', line 6

def body
  @body
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/ecoportal/api/common/batch_response.rb', line 6

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/ecoportal/api/common/batch_response.rb', line 6

def status
  @status
end

Instance Method Details

#eachObject



18
19
20
21
22
# File 'lib/ecoportal/api/common/batch_response.rb', line 18

def each
  [*@result].each do |doc|
    yield doc
  end
end


24
25
26
27
28
29
30
# File 'lib/ecoportal/api/common/batch_response.rb', line 24

def print_pretty
  if success?
    each(&:print_pretty)
  else
    puts "Request failed."
  end
end

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ecoportal/api/common/batch_response.rb', line 14

def success?
  status.success?
end