lib/contactology/campaign.rb in contactology-0.1.0 vs lib/contactology/campaign.rb in contactology-0.1.1
- old
+ new
@@ -63,23 +63,21 @@
# Returns nil for an unrecognized ID or network error.
#
def self.find(id, options = {})
query('Campaign_Get_Info', options.merge({
'campaignId' => id,
- :on_success => Proc.new { |response|
- Campaign.new(response) if response.kind_of?(Hash)
- }
+ :on_success => Proc.new { |r| new_campaign_from_response(r) }
}))
end
def self.find_by_name(name, options = {})
query('Campaign_Find', options.merge({
'searchParameters' => {
'campaignName' => name
},
- :on_success => Proc.new { |response|
- Campaign.new(response.values.first) unless response.nil?
+ :on_success => Proc.new { |r|
+ new_campaign_from_response(r.values.first) unless r.nil?
}
}))
end
@@ -122,8 +120,23 @@
'campaignId' => id,
:on_error => false,
:on_timeout => false,
:on_success => Proc.new { |response| Preview.new(response) }
}))
+ end
+
+
+ private
+
+
+ def self.new_campaign_from_response(response)
+ case response['type']
+ when 'transactional'
+ Campaigns::Transactional.new(response)
+ when 'standard'
+ Campaigns::Standard.new(response)
+ else
+ Campaign.new(response)
+ end
end
end
end