Class: Mailchimp::API
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#throws_exceptions ⇒ Object
Returns the value of attribute throws_exceptions.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #base_api_url ⇒ Object
-
#initialize(api_key = nil, extra_params = {}) ⇒ API
constructor
A new instance of API.
- #valid_api_key?(*args) ⇒ Boolean
Constructor Details
#initialize(api_key = nil, extra_params = {}) ⇒ API
Returns a new instance of API.
9 10 11 12 13 |
# File 'lib/mailchimp/api.rb', line 9 def initialize(api_key = nil, extra_params = {}) @api_key = api_key || ENV['MAILCHIMP_API_KEY'] || self.class.api_key @default_params = {:apikey => @api_key}.merge(extra_params) @throws_exceptions = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (protected)
49 50 51 52 53 |
# File 'lib/mailchimp/api.rb', line 49 def method_missing(method, *args) method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM') call(method, *args) end |
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
56 57 58 |
# File 'lib/mailchimp/api.rb', line 56 def api_key @api_key end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/mailchimp/api.rb', line 7 def api_key @api_key end |
#throws_exceptions ⇒ Object
Returns the value of attribute throws_exceptions.
7 8 9 |
# File 'lib/mailchimp/api.rb', line 7 def throws_exceptions @throws_exceptions end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/mailchimp/api.rb', line 7 def timeout @timeout end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
58 59 60 |
# File 'lib/mailchimp/api.rb', line 58 def method_missing(sym, *args, &block) new(self.api_key).send(sym, *args, &block) end |
Instance Method Details
#base_api_url ⇒ Object
20 21 22 |
# File 'lib/mailchimp/api.rb', line 20 def base_api_url "https://#{dc_from_api_key}api.mailchimp.com/1.3/?method=" end |
#valid_api_key?(*args) ⇒ Boolean
24 25 26 |
# File 'lib/mailchimp/api.rb', line 24 def valid_api_key?(*args) %q{"Everything's Chimpy!"} == call("#{base_api_url}ping") end |