class MyJohnDeere::ListObject
Constants
- OPTION_ATTRIBUTES
Attributes
base_resources[R]
data[R]
last_response_code[R]
listable[R]
options[R]
total[R]
Public Class Methods
new(listable, access_token, json_data, last_response_code, base_resources, options: {})
click to toggle source
Calls superclass method
# File lib/myjohndeere/list_object.rb, line 16 def initialize(listable, access_token, json_data, last_response_code, base_resources, options: {}) @base_resources = base_resources @last_response_code = last_response_code @options = options # Confirm object is listable? @listable = listable json_data = {} if not_modified? @data = (json_data["values"] || []).collect { |i| listable.new(i, access_token) } if self.using_etag? MyJohnDeere.logger.info("Using etag, ignoring any specification about start/count") self.start = 0 self.count = @data.length else MyJohnDeere.logger.info("Etag omitted using start/count") self.start ||= 0 self.count ||= 10 end # Total is the total record count as specified by the john deere response @total = json_data["total"] || data.length super(json_data, access_token) end
Public Instance Methods
each(&blk)
click to toggle source
# File lib/myjohndeere/list_object.rb, line 39 def each(&blk) self.data.each(&blk) end
has_more?()
click to toggle source
# File lib/myjohndeere/list_object.rb, line 56 def has_more?() return !self.using_etag? && self.start + self.data.length < self.total end
next_page!()
click to toggle source
# File lib/myjohndeere/list_object.rb, line 43 def next_page!() list_options = (base_resources || {}).merge({ count: self.count, start: self.start + self.count, etag: self.etag }) return if !self.has_more?() new_list = @listable.list(self.access_token, list_options) new_list.instance_variables.each do |iv| self.instance_variable_set(iv, new_list.instance_variable_get(iv)) end end
not_modified?()
click to toggle source
# File lib/myjohndeere/list_object.rb, line 60 def not_modified? return self.last_response_code == 304 end
using_etag?()
click to toggle source
# File lib/myjohndeere/list_object.rb, line 64 def using_etag? # will be equal "" or some other string return !self.etag.nil? end