class CiscoSpark::Collection
Attributes
collection[RW]
model_klass[RW]
next_params[RW]
Public Class Methods
new(model_klass, collection=[], response=nil)
click to toggle source
# File lib/cisco_spark/collection.rb, line 5 def initialize(model_klass, collection=[], response=nil) @model_klass = model_klass @collection = collection parse_pagination(response) end
Public Instance Methods
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/cisco_spark/collection.rb, line 12 def method_missing(name, *args, &block) if collection.respond_to?(name) collection.send(name, *args, &block) else super end end
next()
click to toggle source
# File lib/cisco_spark/collection.rb, line 20 def next return false unless next_params response = model_klass.fetch_all_raw(next_params) @collection = model_klass.parse_collection(response.body) parse_pagination(response) self end
Private Instance Methods
parse_pagination(response)
click to toggle source
# File lib/cisco_spark/collection.rb, line 32 def parse_pagination(response) @next_params = nil return unless response && response['Link'] matches = /<(?<next>.*)>; rel="next"/.match(response['Link']) next_url = matches[:next] if next_url next_uri = URI.parse(next_url) @next_params = Hash[URI::decode_www_form(next_uri.query)] end end