Class: Mailchimp::Instance
- Inherits:
-
Object
- Object
- Mailchimp::Instance
show all
- Defined in:
- lib/mailchimp_api_v3/instance.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, data, collection_path = '') ⇒ Instance
14
15
16
17
18
19
|
# File 'lib/mailchimp_api_v3/instance.rb', line 14
def initialize(client, data, collection_path = '')
@client = client
@data = data
@collection_path = collection_path
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, options = {}) ⇒ Object
56
57
58
59
60
|
# File 'lib/mailchimp_api_v3/instance.rb', line 56
def method_missing(symbol, options = {})
key = symbol.id2name
return @data[key] if @data.key? key
super
end
|
Class Method Details
.get(client, collection_path, id) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/mailchimp_api_v3/instance.rb', line 5
def self.get(client, collection_path, id)
data = client.get "#{collection_path}/#{id}"
data ? new(client, data, collection_path) : nil
rescue Mailchimp::Exception::NotFound
nil
end
|
Instance Method Details
#delete ⇒ Object
26
27
28
|
# File 'lib/mailchimp_api_v3/instance.rb', line 26
def delete
@client.delete(path)
end
|
#matches?(match_data) ⇒ Boolean
34
35
36
37
38
39
|
# File 'lib/mailchimp_api_v3/instance.rb', line 34
def matches?(match_data)
match_data.each do |k, v|
break false unless __send__(k).casecmp(v).zero?
true
end
end
|
#path ⇒ Object
30
31
32
|
# File 'lib/mailchimp_api_v3/instance.rb', line 30
def path
@path ||= "#{@collection_path}/#{@data['id']}"
end
|
#subclass_from(collection_class, *args) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/mailchimp_api_v3/instance.rb', line 41
def subclass_from(collection_class, *args)
id, name, options = parse_args(*args)
return subclass_instance_from(collection_class, id) if id
paging_options = options.divide_on('start', 'page_size') if options
collection = collection_class.new @client, path, paging_options
return collection.find_by collection.name_field => name if name
options.nil? || options.empty? ? collection : collection.where(options)
end
|
#update(new_data) ⇒ Object
21
22
23
24
|
# File 'lib/mailchimp_api_v3/instance.rb', line 21
def update(new_data)
@data = @client.patch(path, new_data)
self
end
|