Class: Mailchimp::Export
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Attributes inherited from Base
#api_key, #options, #throws_exceptions, #timeout
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.
3 4 5 |
# File 'lib/mailchimp/export.rb', line 3 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.
26 27 28 |
# File 'lib/mailchimp/export.rb', line 26 def api_key @api_key end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
28 29 30 |
# File 'lib/mailchimp/export.rb', line 28 def method_missing(sym, *args, &block) new(self.api_key).send(sym, *args, &block) end |
Instance Method Details
#call(method, params = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mailchimp/export.rb', line 11 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 Mailchimp::APIError.new(first_line_object["error"],first_line_object["code"]) if first_line_object.is_a?(Hash) && first_line_object["error"] end lines end |
#export_api_url ⇒ Object
7 8 9 |
# File 'lib/mailchimp/export.rb', line 7 def export_api_url "http://#{dc_from_api_key}api.mailchimp.com/export/1.0/" end |