From da0b78a9c060cd742e9e7a099dafda2282f01598 Mon Sep 17 00:00:00 2001 From: jonah honeyman Date: Fri, 20 Feb 2015 10:10:38 +0200 Subject: [PATCH 1/2] adds support for campaign creation --- lib/cindy/client.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/cindy/client.rb b/lib/cindy/client.rb index 45d5543..03e9c14 100644 --- a/lib/cindy/client.rb +++ b/lib/cindy/client.rb @@ -10,6 +10,23 @@ def initialize(sendy_url, api_key = nil) @key = api_key || ENV['SENDY_API_KEY'] end + def create_campaign(opts={}) + post_opts = {} + req_opts = %i(from_name from_email reply_to subject html_text) + optional_opts = %i(plain_text list_ids brand_id send_campaign) + + req_opts.each do |opt| + post_opts[opt] = opts.delete(opt) || raise(ArgumentError, "opt :#{opt} required") + end + post_opts.merge!(Hash[optional_opts.zip(opts.values_at(*optional_opts))]) + + response = connection.post "api/campaigns/create.php" do |req| + req.body = post_opts + end + + response.body + end + def subscribe(list_id, email, name = nil) response = connection.post "subscribe" do |req| params = {list: list_id, email: email, boolean: true} From 41ccafbf8743bb3af60883eebd4deb475a4b7c7c Mon Sep 17 00:00:00 2001 From: jonah honeyman Date: Fri, 20 Feb 2015 16:13:53 +0200 Subject: [PATCH 2/2] Need to actually send API key whilst creating campaigns --- lib/cindy/client.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cindy/client.rb b/lib/cindy/client.rb index 03e9c14..0661ddd 100644 --- a/lib/cindy/client.rb +++ b/lib/cindy/client.rb @@ -19,6 +19,7 @@ def create_campaign(opts={}) post_opts[opt] = opts.delete(opt) || raise(ArgumentError, "opt :#{opt} required") end post_opts.merge!(Hash[optional_opts.zip(opts.values_at(*optional_opts))]) + post_opts[:api_key] = @key response = connection.post "api/campaigns/create.php" do |req| req.body = post_opts