lib/list.rb in createsend-0.0.1 vs lib/list.rb in createsend-0.0.2

- old
+ new

@@ -1,75 +1,117 @@ require 'createsend' require 'json' +# Represents a subscriber list and associated functionality. class List attr_reader :list_id def initialize(list_id) @list_id = list_id end + # Creates a new list for a client. def self.create(client_id, title, unsubscribe_page, confirmed_opt_in, confirmation_success_page) options = { :body => { :Title => title, :UnsubscribePage => unsubscribe_page, :ConfirmedOptIn => confirmed_opt_in, :ConfirmationSuccessPage => confirmation_success_page }.to_json } response = CreateSend.post "/lists/#{client_id}.json", options response.parsed_response end + # Deletes this list. def delete response = CreateSend.delete "/lists/#{list_id}.json", {} end - + + # Creates a new custom field for this list. def create_custom_field(field_name, data_type, options=[]) options = { :body => { :FieldName => field_name, :DataType => data_type, :Options => options }.to_json } response = post "customfields", options response.parsed_response end + # Deletes a custom field associated with this list. def delete_custom_field(custom_field_key) custom_field_key = CGI.escape(custom_field_key) response = CreateSend.delete "/lists/#{list_id}/customfields/#{custom_field_key}.json", {} end - + + # Updates the options of a multi-optioned custom field on this list. + def update_custom_field_options(custom_field_key, new_options, keep_existing_options) + custom_field_key = CGI.escape(custom_field_key) + options = { :body => { + :Options => new_options, + :KeepExistingOptions => keep_existing_options }.to_json } + response = put "customfields/#{custom_field_key}/options", options + end + + # Gets the details of this list. def details response = CreateSend.get "/lists/#{list_id}.json", {} Hashie::Mash.new(response) end - + + # Gets the custom fields for this list. def custom_fields response = get "customfields" response.map{|item| Hashie::Mash.new(item)} end - + + # Gets the segments for this list. + def segments + response = get "segments" + response.map{|item| Hashie::Mash.new(item)} + end + + # Gets the stats for this list. def stats response = get "stats" Hashie::Mash.new(response) end - def active(date) - options = { :query => { :date => date } } + # Gets the active subscribers for this list. + def active(date, page=1, page_size=1000, order_field="email", order_direction="asc") + options = { :query => { + :date => date, + :page => page, + :pagesize => page_size, + :orderfield => order_field, + :orderdirection => order_direction } } response = get "active", options - response.map{|item| Hashie::Mash.new(item)} + Hashie::Mash.new(response) end - def bounced(date) - options = { :query => { :date => date } } + # Gets the bounced subscribers for this list. + def bounced(date, page=1, page_size=1000, order_field="email", order_direction="asc") + options = { :query => { + :date => date, + :page => page, + :pagesize => page_size, + :orderfield => order_field, + :orderdirection => order_direction } } response = get "bounced", options - response.map{|item| Hashie::Mash.new(item)} + Hashie::Mash.new(response) end - def unsubscribed(date) - options = { :query => { :date => date } } + # Gets the unsubscribed subscribers for this list. + def unsubscribed(date, page=1, page_size=1000, order_field="email", order_direction="asc") + options = { :query => { + :date => date, + :page => page, + :pagesize => page_size, + :orderfield => order_field, + :orderdirection => order_direction } } response = get "unsubscribed", options - response.map{|item| Hashie::Mash.new(item)} + Hashie::Mash.new(response) end + # Updates this list. def update(title, unsubscribe_page, confirmed_opt_in, confirmation_success_page) options = { :body => { :Title => title, :UnsubscribePage => unsubscribe_page, :ConfirmedOptIn => confirmed_opt_in, \ No newline at end of file