Class: MyJohnDeere::ListObject
- Inherits:
-
Requestable
- Object
- Requestable
- MyJohnDeere::ListObject
- Includes:
- Enumerable
- Defined in:
- lib/myjohndeere/list_object.rb
Constant Summary collapse
- OPTION_ATTRIBUTES =
[:count, :start, :etag]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#listable ⇒ Object
readonly
Returns the value of attribute listable.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Attributes inherited from Requestable
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #has_more? ⇒ Boolean
-
#initialize(listable, access_token, json_data, options: {}) ⇒ ListObject
constructor
A new instance of ListObject.
- #next_page! ⇒ Object
- #using_etag? ⇒ Boolean
Methods inherited from Requestable
#extract_link_with_rel_from_list, get_created_id_from_response_headers
Constructor Details
#initialize(listable, access_token, json_data, options: {}) ⇒ ListObject
Returns a new instance of ListObject.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/myjohndeere/list_object.rb', line 16 def initialize(listable, access_token, json_data, options: {}) @options = # Confirm object is listable? @listable = listable @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 |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/myjohndeere/list_object.rb', line 4 def data @data end |
#listable ⇒ Object (readonly)
Returns the value of attribute listable.
4 5 6 |
# File 'lib/myjohndeere/list_object.rb', line 4 def listable @listable end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/myjohndeere/list_object.rb', line 4 def @options end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
4 5 6 |
# File 'lib/myjohndeere/list_object.rb', line 4 def total @total end |
Instance Method Details
#each(&blk) ⇒ Object
36 37 38 |
# File 'lib/myjohndeere/list_object.rb', line 36 def each(&blk) self.data.each(&blk) end |
#has_more? ⇒ Boolean
51 52 53 |
# File 'lib/myjohndeere/list_object.rb', line 51 def has_more?() return !self.using_etag? && self.start + self.data.length < self.total end |
#next_page! ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/myjohndeere/list_object.rb', line 40 def next_page!() return if !self.has_more?() new_list = @listable.list(self.access_token, count: self.count, start: self.start + self.count, etag: self.etag) new_list.instance_variables.each do |iv| self.instance_variable_set(iv, new_list.instance_variable_get(iv)) end end |
#using_etag? ⇒ Boolean
55 56 57 58 |
# File 'lib/myjohndeere/list_object.rb', line 55 def using_etag? # will be equal "" or some other string return !self.etag.nil? end |