class Octobat::ListObject

Attributes

cursors[RW]
filters[RW]
parent_resource[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/octobat/list_object.rb, line 8
def initialize(*args)
  super
  self.filters = {}
  self.cursors = {}
  self.parent_resource = {}
end

Public Instance Methods

[](k) click to toggle source
Calls superclass method
# File lib/octobat/list_object.rb, line 15
def [](k)
  case k
  when String, Symbol
    super
  else
    raise ArgumentError.new("You tried to access the #{k.inspect} index, but ListObject types only support Octobat keys. (HINT: List calls return an object with a 'data' (which is the data array). You likely want to call #data[#{k.inspect}])")
  end
end
create(params={}, opts={}) click to toggle source
# File lib/octobat/list_object.rb, line 53
def create(params={}, opts={})
  api_key, headers = Util.parse_opts(opts)
  api_key ||= @api_key
  response, api_key = Octobat.request(:post, url, api_key, params, headers)
  Util.convert_to_octobat_object(response, api_key)
end
each(&blk) click to toggle source
# File lib/octobat/list_object.rb, line 24
def each(&blk)
  self.data.each(&blk)
end
empty?() click to toggle source
# File lib/octobat/list_object.rb, line 28
def empty?
  self.data.empty?
end
next_page_params(params={}, opts={}) click to toggle source
# File lib/octobat/list_object.rb, line 61
def next_page_params(params={}, opts={})
  return nil if !has_more
  last_id = data.last.id
  
  params = filters.merge({
    starting_after: last_id
  }).merge(params)
end
previous_page_params(params={}, opts={}) click to toggle source
# File lib/octobat/list_object.rb, line 71
def previous_page_params(params={}, opts={})
  return nil if !has_before
  first_id = data.first.id

  params = filters.merge({
    ending_before: first_id
  }).merge(params)
end
retrieve(id, opts={}) click to toggle source
# File lib/octobat/list_object.rb, line 32
def retrieve(id, opts={})
  api_key, headers = Util.parse_opts(opts)
  api_key ||= @api_key
  
  if id.kind_of?(Hash)
    retrieve_options = id.dup
    retrieve_options.delete(:id)
    id = id[:id]
  else
    retrieve_options = {}
  end
  
  headers = {}
  
  retrieve_options.merge!(opts.clone).delete(:api_key)
  headers['Octobat-Version'] = retrieve_options.delete('Octobat-Version') if retrieve_options.has_key?('Octobat-Version')
        
  response, api_key = Octobat.request(:get, "#{url}/#{CGI.escape(id)}", api_key, retrieve_options, headers)
  Util.convert_to_octobat_object(response, api_key, self.parent_resource)
end
url() click to toggle source
# File lib/octobat/list_object.rb, line 81
def url
  self.request_url
end