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.



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

def initialize(status, body, result = nil)
  @status = status
  @body   = body
  @result = result
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#eachObject



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

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


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

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

#success?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ecoportal/api/common/batch_response.rb', line 11

def success?
  (0..299).include?(status)
end