Class: Mailchimp::Export
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #call(method, params = {}) ⇒ Object
- #export_api_url ⇒ Object
-
#initialize(api_key = nil, default_parameters = {}) ⇒ Export
constructor
A new instance of Export.
Methods inherited from Base
#dc_from_api_key, #valid_api_key?
Constructor Details
#initialize(api_key = nil, default_parameters = {}) ⇒ Export
Returns a new instance of Export.
6 7 8 |
# File 'lib/mailchimp/export.rb', line 6 def initialize(api_key = nil, default_parameters = {}) super(api_key, {:apikey => api_key}.merge(default_parameters)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mailchimp::Base
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
29 30 31 |
# File 'lib/mailchimp/export.rb', line 29 def api_key @api_key end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
31 32 33 |
# File 'lib/mailchimp/export.rb', line 31 def method_missing(sym, *args, &block) new(self.api_key).send(sym, *args, &block) end |
Instance Method Details
#call(method, params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mailchimp/export.rb', line 14 def call(method, params = {}) api_url = export_api_url + method + "/" params = @default_params.merge(params) timeout = params.delete(:timeout) || @timeout response = self.class.post(api_url, :body => params, :timeout => timeout) lines = response.body.lines if @throws_exceptions first_line_object = JSON.parse(lines.first) if lines.first raise "Error from MailChimp Export API: #{first_line_object["error"]} (code #{first_line_object["code"]})" if first_line_object.is_a?(Hash) && first_line_object["error"] end lines end |
#export_api_url ⇒ Object
10 11 12 |
# File 'lib/mailchimp/export.rb', line 10 def export_api_url "http://#{dc_from_api_key}api.mailchimp.com/export/1.0/" end |