Class: Lotr::Sdk::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/lotr/sdk/dataset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Dataset

Returns a new instance of Dataset.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lotr/sdk/dataset.rb', line 6

def initialize(response)
  if response.code < 300
    list = response.parse
    @data = list['docs']
    @meta = {
      total_count: list['total'],
      current_page: list['page'],
      total_pages: list['pages']
    }
  else
    @error = {
      error_code: response.code,
      error_message: response.to_s
    }
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/lotr/sdk/dataset.rb', line 5

def data
  @data
end

#errorObject

Returns the value of attribute error.



5
6
7
# File 'lib/lotr/sdk/dataset.rb', line 5

def error
  @error
end

#metaObject

Returns the value of attribute meta.



5
6
7
# File 'lib/lotr/sdk/dataset.rb', line 5

def meta
  @meta
end

Instance Method Details

#next_page_numberObject



23
24
25
26
# File 'lib/lotr/sdk/dataset.rb', line 23

def next_page_number
  return nil if @error
  @meta[:current_page] < @meta[:total_pages] ? @meta[:current_page] + 1 : nil
end