class TicketingHub::Collection
Attributes
client[RW]
klass[RW]
options[RW]
path[RW]
Public Class Methods
new(client, path, options = {}, klass = nil)
click to toggle source
Calls superclass method
# File lib/ticketing_hub/collection.rb, line 7 def initialize(client, path, options = {}, klass = nil) self.client = client self.path = path self.options = options self.klass = klass super() do |yielder| response = client.request(:get, path, options) if response.body.is_a?(Array) response.body.each { |value| yielder << _filter_value(value) } else yielder << _filter_value(response.body) end while next_url = links(response)['next'] response = client.request(:get, next_url, options) response.body.each { |value| yielder << _filter_value(value) } end end end
Public Instance Methods
create(options = {})
click to toggle source
# File lib/ticketing_hub/collection.rb, line 33 def create options = {} _filter_value client.request(:post, "#{path}", options).body end
find(id=nil, options = {}, &block)
click to toggle source
Calls superclass method
# File lib/ticketing_hub/collection.rb, line 37 def find(id=nil, options = {}, &block) return super(&block) if block_given? _filter_value client.request(:get, "#{path}/#{id}", options).body end
limit(value)
click to toggle source
# File lib/ticketing_hub/collection.rb, line 25 def limit value options.merge! limit: value.to_i end
links(response)
click to toggle source
# File lib/ticketing_hub/collection.rb, line 42 def links(response) links = ( response.headers["Link"] || "" ).split(', ').map do |link| url, type = link.match(/<(.*?)>; rel="(\w+)"/).captures [ type, url ] end Hash[*links.flatten] end
offset(value)
click to toggle source
# File lib/ticketing_hub/collection.rb, line 29 def offset value options.merge! offset: value.to_i end
Private Instance Methods
_filter_value(value)
click to toggle source
# File lib/ticketing_hub/collection.rb, line 53 def _filter_value value unless klass.nil? return klass.new client, value, path, value.id else value end end