Class: Countir::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/countir/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, resource_class = nil) ⇒ Result

Returns a new instance of Result.



7
8
9
10
# File 'lib/countir/result.rb', line 7

def initialize(response, resource_class = nil)
  @response       = response
  @resource_class = resource_class
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/countir/result.rb', line 5

def response
  @response
end

Instance Method Details

#dataObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/countir/result.rb', line 18

def data
  @data ||= begin
    if data?
      data = JSON.parse(self.body)

      if @resource_class
        @resource_class.response_schema(data)
      else
        data
      end
    end
  end
end

#data?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/countir/result.rb', line 14

def data?
  !(self.body.nil? || self.body.empty?)
end

#next_offsetObject



32
33
34
35
36
# File 'lib/countir/result.rb', line 32

def next_offset
  if data?
    JSON.parse(self.body)["next_offset"] rescue nil
  end
end