Class: Octobat::ListObject
Instance Attribute Summary collapse
#api_key, #parent_obj
Instance Method Summary
collapse
#list, #set_parent_resource
#[]=, #_dump, _load, #as_json, construct_from, #inspect, #keys, #refresh_from, #respond_to?, #to_hash, #to_json, #to_s, #values
Constructor Details
#initialize(*args) ⇒ ListObject
Returns a new instance of ListObject.
8
9
10
11
12
13
|
# File 'lib/octobat/list_object.rb', line 8
def initialize(*args)
super
self.filters = {}
self.cursors = {}
self.parent_resource = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Octobat::OctobatObject
Instance Attribute Details
#cursors ⇒ Object
Returns the value of attribute cursors.
6
7
8
|
# File 'lib/octobat/list_object.rb', line 6
def cursors
@cursors
end
|
#filters ⇒ Object
Returns the value of attribute filters.
6
7
8
|
# File 'lib/octobat/list_object.rb', line 6
def filters
@filters
end
|
#parent_resource ⇒ Object
Returns the value of attribute parent_resource.
6
7
8
|
# File 'lib/octobat/list_object.rb', line 6
def parent_resource
@parent_resource
end
|
Instance Method Details
#[](k) ⇒ Object
15
16
17
18
19
20
21
22
|
# 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 = {}) ⇒ Object
#each(&blk) ⇒ Object
24
25
26
|
# File 'lib/octobat/list_object.rb', line 24
def each(&blk)
self.data.each(&blk)
end
|
#empty? ⇒ Boolean
28
29
30
|
# File 'lib/octobat/list_object.rb', line 28
def empty?
self.data.empty?
end
|
#next_page_params(params = {}, opts = {}) ⇒ Object
61
62
63
64
65
66
67
68
|
# 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 = {}) ⇒ Object
71
72
73
74
75
76
77
78
|
# 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 = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/octobat/list_object.rb', line 32
def retrieve(id, opts={})
api_key, = 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
= {}
retrieve_options.merge!(opts.clone).delete(:api_key)
['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, )
Util.convert_to_octobat_object(response, api_key, self.parent_resource)
end
|
#url ⇒ Object
81
82
83
|
# File 'lib/octobat/list_object.rb', line 81
def url
self.request_url
end
|