Class: Zendesk::Collection
- Inherits:
-
Object
- Object
- Zendesk::Collection
show all
- Includes:
- Connection, Paginator
- Defined in:
- lib/zendesk/collection.rb
Instance Attribute Summary
Attributes included from Paginator
#query
Instance Method Summary
(collapse)
Methods included from Paginator
#[], #clear_cache, #each, #fetch, #method_missing, #page, #per_page
Constructor Details
- (Collection) initialize(client, resource, *args)
A new instance of Collection
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/zendesk/collection.rb', line 11
def initialize(client, resource, *args)
clear_cache
@client = client
@resource = resource.to_s
@path = resource_path(@resource)
@query = args.last.is_a?(Hash) ? args.pop : {}
case selection = args.shift
when nil
@query[:path] = @path
when Integer
@query[:path] = "#{@path}/#{selection}"
when String
@query[:path] = @path
@query[:query] = selection
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Zendesk::Paginator
Instance Method Details
- (Object) create(data = {}) {|data| ... }
42
43
44
45
|
# File 'lib/zendesk/collection.rb', line 42
def create(data={})
yield data if block_given?
request(:post, @query.delete(:path), @query.merge(@resource.to_sym => data))
end
|
- (Object) delete(options = {})
52
53
54
|
# File 'lib/zendesk/collection.rb', line 52
def delete(options={})
request(:delete, @query.delete(:path), options)
end
|
- (Object) get(path, options = {})
30
31
32
|
# File 'lib/zendesk/collection.rb', line 30
def get(path, options={})
request(:get, path, options)
end
|
- (Object) post(path, options = {})
38
39
40
|
# File 'lib/zendesk/collection.rb', line 38
def post(path, options={})
request(:post, path, options)
end
|
- (Object) put(path, options = {})
34
35
36
|
# File 'lib/zendesk/collection.rb', line 34
def put(path, options={})
request(:put, path, options)
end
|
- (Object) update(data = {}) {|data| ... }
47
48
49
50
|
# File 'lib/zendesk/collection.rb', line 47
def update(data={})
yield data if block_given?
request(:put, @query.delete(:path), @query.merge(@resource.to_sym => data))
end
|