lib/emaildirect/subscriber.rb in emaildirect-1.0.1 vs lib/emaildirect/subscriber.rb in emaildirect-1.1.0

- old
+ new

@@ -25,13 +25,22 @@ Hashie::Mash.new(response) end def create(email, options = {}) options.merge! :EmailAddress => email + self.convert_custom_fields options response = EmailDirect.post '/Subscribers', :body => options.to_json Hashie::Mash.new(response) end + + protected + + def convert_custom_fields(options) + if options.has_key?(:CustomFields) && options[:CustomFields].is_a?(Hash) + options[:CustomFields] = options[:CustomFields].map { |k, v| { :FieldName => k, :Value => v } } + end + end end attr_reader :email def initialize(email) @@ -53,11 +62,20 @@ Hashie::Mash.new(response) end def update(options) options.merge! :EmailAddress => email + self.class.convert_custom_fields options response = EmailDirect.put uri_for, :body => options.to_json Hashie::Mash.new(response) + end + + def update_custom_field(attribute, value) + self.class.create email, :CustomFields => [ { :FieldName => attribute, :Value => value } ] + end + + def update_custom_fields(attributes) + self.class.create email, :CustomFields => attributes end def delete response = EmailDirect.delete uri_for, {} Hashie::Mash.new(response)