Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge in latest from jordanbrock

  • Loading branch information...
commit da9b929e714216ed8e438026e705230d3df1bb97 2 parents 7fbb455 + 2f7296d
@yyyc514 authored
View
13 README.rdoc
@@ -4,13 +4,24 @@ This RubyGem provides access to the Campaign Monitor API (http://www.campaignmon
Campaign Monitor recently made some changes to their API.
-This fork makes the following changes:
+patientslikeme's fork makes the following changes:
* host changed from http://app.campaignmonitor.com to http://api.createsend.com
* ID values are no longer sent #to_i because they are hex strings
* added support for subscribers with custom fields using SOAP API
* refactored gemspec to build on github
* misc. cleanup and refactoring
+
+This fork integrates the following additional changes:
+
+ * updates Subscriber#is_subscribed? to work with the latest API. (from amiel)
+ * adds support for array values in custom_field_hash (from oferlin)
+ * API key cleanup (from yyyc514)
+ * added ability to get fetch lists by id using List#GetDetails or List#[] (from yyyc514)
+ * added support for adding and deleting clients (from yyyc514)
+ * added support for querying CM for countries and timezones (from yyyc514)
+ * added support for creating campaigns (from yyyc514)
+ * general test and api cleanup (from yyyc514)
== Pre-requisites
View
4 campaign_monitor.gemspec
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'campaign_monitor'
- s.version = "1.3.2.3"
+ s.version = "1.3.3"
s.summary = 'Provides access to the Campaign Monitor API.'
s.description = <<-EOF
A simple wrapper class that provides basic access to the Campaign Monitor API.
EOF
s.author = 'Jeremy Weiskotten'
s.email = 'jweiskotten@patientslikeme.com'
- s.homepage = 'http://github.com/patientslikeme/campaign_monitor/'
+ s.homepage = 'http://github.com/reidab/campaign_monitor/'
s.has_rdoc = true
s.requirements << 'none'
View
46 lib/campaign_monitor.rb
@@ -47,7 +47,7 @@
# client.GetLists
# client.lists.build # to create a new unsaved list for a client
# client.campaigns # OR
-# client.GetCampaigns
+# client.GetCampaigns
#
# == LIST
# list = List[list_id] # find an existing list
@@ -88,15 +88,15 @@
#
class CampaignMonitor
include CampaignMonitor::Helpers
-
+
class InvalidAPIKey < StandardError
end
class ApiError < StandardError
end
-
+
attr_reader :api_key, :api_url
-
+
# Replace this API key with your own (http://www.campaignmonitor.com/api/)
def initialize(api_key=CAMPAIGN_MONITOR_API_KEY)
@api_key = api_key
@@ -124,11 +124,11 @@ def request(method, params)
# Takes a CampaignMonitor API method name and set of parameters; returns the correct URL for the REST API.
def request_url(method, params={})
params.merge!('ApiKey' => api_key)
-
+
query = params.collect do |key, value|
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
end.sort * '&'
-
+
"#{api_url}/#{method}?#{query}"
end
@@ -161,11 +161,11 @@ def clients
response["Client"].collect{|c| Client.new({"ClientID" => c["ClientID"], "CompanyName" => c["Name"]})}
end
end
-
+
def new_client
Client.new(nil)
end
-
+
def system_date
User_GetSystemDate()
end
@@ -173,19 +173,19 @@ def system_date
def parsed_system_date
DateTime.strptime(system_date, timestamp_format)
end
-
+
def countries
handle_response(User_GetCountries()) do | response |
response["string"]
end
end
-
+
def timezones
handle_response(User_GetTimezones()) do | response |
response["string"]
end
end
-
+
# Returns an array of Campaign objects associated with the specified Client ID
#
# Example
@@ -228,13 +228,26 @@ def lists(client_id)
def add_subscriber(list_id, email, name)
Result.new(Subscriber_Add("ListID" => list_id, "Email" => email, "Name" => name))
end
-
+
+ # A quick method of removing a subscriber from a list. Returns a Result object
+ #
+ # Example
+ # @cm = CampaignMonitor.new()
+ # result = @cm.remove_subscriber(12345, "ralph.wiggum@simpsons.net")
+ #
+ # if result.succeeded?
+ # puts "Subscriber Added to List"
+ # end
+ def remove_subscriber(list_id, email)
+ Result.new(Subscriber_Add("ListID" => list_id, "Email" => email))
+ end
+
def using_soap
driver = wsdl_driver_factory.create_rpc_driver
driver.wiredump_dev = STDERR if $debug
response = yield(driver)
driver.reset_stream
-
+
response
end
@@ -243,11 +256,11 @@ def using_soap
def wsdl_driver_factory
SOAP::WSDLDriverFactory.new("#{api_url}?WSDL")
end
-
+
end
# If libxml is installed, we use the FasterXmlSimple library, that provides most of the functionality of XmlSimple
-# except it uses the xml/libxml library for xml parsing (rather than REXML).
+# except it uses the xml/libxml library for xml parsing (rather than REXML).
# If libxml isn't installed, we just fall back on XmlSimple.
PARSER =
@@ -257,8 +270,7 @@ def wsdl_driver_factory
# have to use a version greater than '0.3.8.2'.
raise LoadError unless XML::Parser::VERSION > '0.3.8.2'
$:.push(File.join(File.dirname(__FILE__), '..', 'support', 'faster-xml-simple', 'lib'))
- require 'faster_xml_simple'
-# p 'Using libxml-ruby'
+ require 'faster_xml_simple'
FasterXmlSimple
rescue LoadError
begin
View
8 lib/campaign_monitor/list.rb
@@ -202,7 +202,13 @@ def bounced(date)
def custom_fields_array(custom_fields)
arr = []
custom_fields.each do |key, value|
- arr << { "Key" => key, "Value" => value }
+ if value.is_a? Array
+ value.each do |array_value|
+ arr << { "Key" => key, "Value" => array_value }
+ end
+ else
+ arr << { "Key" => key, "Value" => value }
+ end
end
arr
end
View
4 lib/campaign_monitor/subscriber.rb
@@ -35,8 +35,8 @@ def unsubscribe(list_id)
def is_subscribed?(list_id)
result = cm_client.Subscribers_GetIsSubscribed("ListID" => list_id, "Email" => @email_address)
- return true if result == 'True'
- return false if result == 'False'
+ return true if result['__content__'] == 'True'
+ return false if result['__content__'] == 'False'
raise "Invalid value for is_subscribed?: #{result}"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.