Skip to content

Commit 24c59df

Browse files
committed
added email endpoints
1 parent a887561 commit 24c59df

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

README.rdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ http://developer.pardot.com/kb/api-version-3/using-prospects
5454
puts "#{key} is #{value}"
5555
end
5656

57+
=== Emails
58+
59+
See each individual call's [API reference page](http://developer.pardot.com/kb/api-version-3/introduction-table-of-contents).
60+
61+
# Sample usage
62+
@pardot.emails.read_by_id(email_id)
63+
@pardot.emails.send_to_list(:email_template_id => template_id, 'list_ids[]' => list_id, :campaign_id => campaign_id)
64+
@pardot.emails.send_to_prospect(prospect_id, :campaign_id => campaign_id, :email_template_id => template_id)
65+
5766
=== Output formats
5867

5968
client.format = "simple" # default

lib/pardot/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Client
99
include Authentication
1010
include Http
1111

12+
include Objects::Emails
1213
include Objects::Lists
1314
include Objects::Opportunities
1415
include Objects::Prospects

lib/pardot/objects/emails.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module Pardot
2+
module Objects
3+
4+
module Emails
5+
6+
def emails
7+
@emails ||= Emails.new self
8+
end
9+
10+
class Emails
11+
12+
def initialize client
13+
@client = client
14+
end
15+
16+
def read_by_id id
17+
get "/do/read/id/#{id}"
18+
end
19+
20+
def send_to_prospect prospect_id, params
21+
post "/do/send/prospect_id/#{prospect_id}", params
22+
end
23+
24+
def send_to_list params
25+
post "/do/send", params
26+
end
27+
28+
protected
29+
30+
def get path, params = {}, result = "email"
31+
response = @client.get "email", path, params
32+
result ? response[result] : response
33+
end
34+
35+
def post path, params = {}, result = "email"
36+
response = @client.post "email", path, params
37+
result ? response[result] : response
38+
end
39+
40+
end
41+
42+
end
43+
end
44+
end

lib/ruby-pardot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'pardot/error'
77
require 'pardot/authentication'
88

9+
require 'pardot/objects/emails'
910
require 'pardot/objects/lists'
1011
require 'pardot/objects/opportunities'
1112
require 'pardot/objects/prospects'

spec/pardot/objects/emails_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2+
3+
describe Pardot::Objects::Emails do
4+
5+
before do
6+
@client = create_client
7+
end
8+
9+
def sample_email
10+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
11+
<email>
12+
<name>My Email</name>
13+
</email>
14+
</rsp>)
15+
end
16+
17+
def sample_send_to_prospect
18+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
19+
<email>
20+
<name>My Email</name>
21+
</email>
22+
</rsp>)
23+
end
24+
25+
def sample_send_to_list
26+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
27+
<email>
28+
<name>My Email</name>
29+
</email>
30+
</rsp>)
31+
end
32+
33+
before do
34+
@client = create_client
35+
end
36+
37+
it "should take in the email ID" do
38+
fake_get "/api/email/version/3/do/read/id/12?user_key=bar&api_key=my_api_key&format=simple", sample_email
39+
@client.emails.read_by_id(12).should == {"name" => "My Email"}
40+
end
41+
42+
it 'should send to a prospect' do
43+
fake_post '/api/email/version/3/do/send/prospect_id/42?campaign_id=765&email_template_id=86&user_key=bar&api_key=my_api_key&format=simple', sample_send_to_prospect
44+
@client.emails.send_to_prospect(42, :campaign_id => 765, :email_template_id => 86).should == {"name" => "My Email"}
45+
end
46+
47+
it 'should send to a list' do
48+
fake_post '/api/email/version/3/do/send?email_template_id=200&list_ids[]=235&campaign_id=654&user_key=bar&api_key=my_api_key&format=simple', sample_send_to_list
49+
@client.emails.send_to_list(:email_template_id => 200, 'list_ids[]' => 235, :campaign_id => 654).should == {"name" => "My Email"}
50+
end
51+
52+
end

0 commit comments

Comments
 (0)