Class: MailChimp3::Endpoint
- Inherits:
-
Object
- Object
- MailChimp3::Endpoint
show all
- Defined in:
- lib/mailchimp3/endpoint.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(oauth_access_token: nil, basic_auth_key: nil, dc: nil, url: nil) ⇒ Endpoint
Returns a new instance of Endpoint.
8
9
10
11
12
13
14
15
16
|
# File 'lib/mailchimp3/endpoint.rb', line 8
def initialize(oauth_access_token: nil, basic_auth_key: nil, dc: nil, url: nil)
@oauth_access_token = oauth_access_token
@basic_auth_key = basic_auth_key
@dc = dc
@dc ||= @basic_auth_key.split('-').last if @basic_auth_key
@url = url || _build_url
fail Errors::DataCenterRequiredError, 'You must pass dc.' unless @dc || @url
@cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
18
19
20
|
# File 'lib/mailchimp3/endpoint.rb', line 18
def method_missing(method_name, *_args)
_build_endpoint(method_name.to_s)
end
|
Instance Attribute Details
#last_result ⇒ Object
Returns the value of attribute last_result.
6
7
8
|
# File 'lib/mailchimp3/endpoint.rb', line 6
def last_result
@last_result
end
|
#url ⇒ Object
Returns the value of attribute url.
6
7
8
|
# File 'lib/mailchimp3/endpoint.rb', line 6
def url
@url
end
|
Instance Method Details
#[](id) ⇒ Object
22
23
24
|
# File 'lib/mailchimp3/endpoint.rb', line 22
def [](id)
_build_endpoint(id.to_s)
end
|
#delete ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/mailchimp3/endpoint.rb', line 45
def delete
@last_result = _connection.delete(@url)
if @last_result.status == 204
true
else
_build_response(@last_result)
end
end
|
#get(params = {}) ⇒ Object
26
27
28
29
|
# File 'lib/mailchimp3/endpoint.rb', line 26
def get(params = {})
@last_result = _connection.get(@url, params)
_build_response(@last_result)
end
|
#patch(body = {}) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/mailchimp3/endpoint.rb', line 38
def patch(body = {})
@last_result = _connection.patch(@url) do |req|
req.body = body.to_json
end
_build_response(@last_result)
end
|
#post(body = {}) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/mailchimp3/endpoint.rb', line 31
def post(body = {})
@last_result = _connection.post(@url) do |req|
req.body = body.to_json
end
_build_response(@last_result)
end
|