Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Add methods for delete_list #64

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 118 additions & 97 deletions lib/constantcontact/api.rb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ActivityError < Component
# @return [ActivityError]
def self.create(props)
obj = ActivityError.new
if props
if props.present?
props.each do |key, value|
obj.send("#{key}=", value) if obj.respond_to? key
end
Expand Down
2 changes: 1 addition & 1 deletion lib/constantcontact/components/contacts/contact_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module ConstantContact
module Components
class ContactList < Component
attr_accessor :id, :name, :status, :contact_count
attr_accessor :id, :name, :status, :contact_count, :created_date, :modified_date

# Factory method to create a ContactList object from a json string
# @param [Hash] props - properties to create object from
Expand Down
42 changes: 20 additions & 22 deletions lib/constantcontact/services/account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@
module ConstantContact
module Services
class AccountService < BaseService
class << self

# Get a summary of account information
# @return [AccountInfo]
def get_account_info()
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_info')
url = build_url(url)
response = RestClient.get(url, get_headers())
Components::AccountInfo.create(JSON.parse(response.body))
end
# Get a summary of account information
# @return [AccountInfo]
def get_account_info()
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_info')
url = build_url(url)
response = RestClient.get(url, get_headers())
Components::AccountInfo.create(JSON.parse(response.body))
end


# Get all verified email addresses associated with an account
# @param [Hash] params - hash of query parameters/values to append to the request
# @return [Array<VerifiedEmailAddress>]
def get_verified_email_addresses(params)
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_verified_addresses')
url = build_url(url, params)
response = RestClient.get(url, get_headers())
email_addresses = []
JSON.parse(response.body).each do |email_address|
email_addresses << Components::VerifiedEmailAddress.create(email_address)
end
email_addresses
# Get all verified email addresses associated with an account
# @param [Hash] params - hash of query parameters/values to append to the request
# @return [Array<VerifiedEmailAddress>]
def get_verified_email_addresses(params)
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_verified_addresses')
url = build_url(url, params)
response = RestClient.get(url, get_headers())
email_addresses = []
JSON.parse(response.body).each do |email_address|
email_addresses << Components::VerifiedEmailAddress.create(email_address)
end

email_addresses
end

end
end
end
198 changes: 98 additions & 100 deletions lib/constantcontact/services/activity_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,130 +7,128 @@
module ConstantContact
module Services
class ActivityService < BaseService
class << self

# Get a set of activities
# @param [Hash] params - query parameters to be appended to the url
# @return [Array<Activity>]
def get_activities(params = {})
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.activities')
url = build_url(url, params)
response = RestClient.get(url, get_headers())

activities = []
JSON.parse(response.body).each do |activity|
activities << Components::Activity.create(activity)
end

activities

# Get a set of activities
# @param [Hash] params - query parameters to be appended to the url
# @return [Array<Activity>]
def get_activities(params = {})
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.activities')
url = build_url(url, params)
response = RestClient.get(url, get_headers())

activities = []
JSON.parse(response.body).each do |activity|
activities << Components::Activity.create(activity)
end

activities
end

# Get an array of activities
# @param [String] activity_id - Activity id
# @return [Activity]
def get_activity(activity_id)
url = Util::Config.get('endpoints.base_url') +
sprintf(Util::Config.get('endpoints.activity'), activity_id)
url = build_url(url)
response = RestClient.get(url, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Get an array of activities
# @param [String] activity_id - Activity id
# @return [Activity]
def get_activity(activity_id)
url = Util::Config.get('endpoints.base_url') +
sprintf(Util::Config.get('endpoints.activity'), activity_id)
url = build_url(url)
response = RestClient.get(url, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create an Add Contacts Activity
# @param [AddContacts] add_contacts
# @return [Activity]
def create_add_contacts_activity(add_contacts)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.add_contacts_activity')
url = build_url(url)
payload = add_contacts.to_json
response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create an Add Contacts Activity
# @param [AddContacts] add_contacts
# @return [Activity]
def create_add_contacts_activity(add_contacts)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.add_contacts_activity')
url = build_url(url)
payload = add_contacts.to_json
response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
# @param [String] file_name - The name of the file (ie: contacts.csv)
# @param [String] contents - The content of the file
# @param [String] lists - Comma separated list of ContactList id's to add the contacts to
# @return [Activity]
def create_add_contacts_activity_from_file(file_name, contents, lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.add_contacts_activity')
url = build_url(url)

payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }
# Create an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
# @param [String] file_name - The name of the file (ie: contacts.csv)
# @param [String] contents - The content of the file
# @param [String] lists - Comma separated list of ContactList id's to add the contacts to
# @return [Activity]
def create_add_contacts_activity_from_file(file_name, contents, lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.add_contacts_activity')
url = build_url(url)

response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end
payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }

response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create a Clear Lists Activity
# @param [Array<lists>] lists - array of list id's to be cleared
# @return [Activity]
def add_clear_lists_activity(lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.clear_lists_activity')
url = build_url(url)
payload = {'lists' => lists}.to_json
response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create a Clear Lists Activity
# @param [Array<lists>] lists - array of list id's to be cleared
# @return [Activity]
def add_clear_lists_activity(lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.clear_lists_activity')
url = build_url(url)
payload = {'lists' => lists}.to_json
response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create an Export Contacts Activity
# @param [ExportContacts] export_contacts
# @return [Activity]
def add_export_contacts_activity(export_contacts)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.export_contacts_activity')
url = build_url(url)
payload = export_contacts.to_json
response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create an Export Contacts Activity
# @param [ExportContacts] export_contacts
# @return [Activity]
def add_export_contacts_activity(export_contacts)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.export_contacts_activity')
url = build_url(url)
payload = export_contacts.to_json
response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create a Remove Contacts From Lists Activity
# @param [<Array>EmailAddress] email_addresses
# @param [<Array>RemoveFromLists] lists
# @return [Activity]
def add_remove_contacts_from_lists_activity(email_addresses, lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.remove_from_lists_activity')
url = build_url(url)

payload = { 'import_data' => [], 'lists' => lists }
email_addresses.each do |email_address|
payload['import_data'] << { 'email_addresses' => [email_address] }
end
payload = payload.to_json
# Create a Remove Contacts From Lists Activity
# @param [<Array>EmailAddress] email_addresses
# @param [<Array>RemoveFromLists] lists
# @return [Activity]
def add_remove_contacts_from_lists_activity(email_addresses, lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.remove_from_lists_activity')
url = build_url(url)

response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
payload = { 'import_data' => [], 'lists' => lists }
email_addresses.each do |email_address|
payload['import_data'] << { 'email_addresses' => [email_address] }
end
payload = payload.to_json

response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

# Create an Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
# @param [String] file_name - The name of the file (ie: contacts.csv)
# @param [String] contents - The content of the file
# @param [String] lists - Comma separated list of ContactList id' to add the contacts too
# @return [Activity]
def add_remove_contacts_from_lists_activity_from_file(file_name, contents, lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.remove_from_lists_activity')
url = build_url(url)

payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }
# Create an Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
# @param [String] file_name - The name of the file (ie: contacts.csv)
# @param [String] contents - The content of the file
# @param [String] lists - Comma separated list of ContactList id' to add the contacts too
# @return [Activity]
def add_remove_contacts_from_lists_activity_from_file(file_name, contents, lists)
url = Util::Config.get('endpoints.base_url') +
Util::Config.get('endpoints.remove_from_lists_activity')
url = build_url(url)

response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end
payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }

response = RestClient.post(url, payload, get_headers())
Components::Activity.create(JSON.parse(response.body))
end

end
end
end
Loading