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
12
13
14
15
16
17
|
# File 'lib/mailchimp_api_v3/instance.rb', line 12
def initialize(client, data, collection_path = '')
@client = client
@collection_path = collection_path
@data = data
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, options = {}) ⇒ Object
50
51
52
53
54
|
# File 'lib/mailchimp_api_v3/instance.rb', line 50
def method_missing(symbol, options = {})
key = symbol.id2name
fail_unless_exists key, options
@data[key]
end
|
Class Method Details
.get(client, collection_path, id) ⇒ Object
5
6
7
8
|
# File 'lib/mailchimp_api_v3/instance.rb', line 5
def self.get(client, collection_path, id)
data = client.get "#{collection_path}/#{id}"
new client, data, collection_path
end
|
Instance Method Details
#matches?(match_data) ⇒ Boolean
28
29
30
31
32
33
|
# File 'lib/mailchimp_api_v3/instance.rb', line 28
def matches?(match_data)
match_data.each do |k, v|
break false unless __send__(k).casecmp(v).zero? true
end
end
|
#path ⇒ Object
24
25
26
|
# File 'lib/mailchimp_api_v3/instance.rb', line 24
def path
@path ||= "#{@collection_path}/#{@data['id']}"
end
|
#subclass_from(collection_class, options = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/mailchimp_api_v3/instance.rb', line 35
def subclass_from(collection_class, options = {})
if options.is_a? String
child_path = "#{path}/#{collection_class::PATH_KEY}"
collection_class::CHILD_CLASS.get @client, child_path, options
else
collection_class.new @client, path, options
end
end
|
#update(new_data) ⇒ Object
19
20
21
22
|
# File 'lib/mailchimp_api_v3/instance.rb', line 19
def update(new_data)
@data = @client.patch(new_data, path)
self
end
|