File tree Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 66require 'pardot/error'
77require 'pardot/authentication'
88
9+ require 'pardot/objects/emails'
910require 'pardot/objects/lists'
1011require 'pardot/objects/opportunities'
1112require 'pardot/objects/prospects'
Original file line number Diff line number Diff line change 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_response
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+ before do
18+ @client = create_client
19+ end
20+
21+ it "should take in the email ID" do
22+ fake_get "/api/email/version/3/do/read/id/12?user_key=bar&api_key=my_api_key&format=simple" , sample_response
23+ @client . emails . read_by_id ( 12 ) . should == { "name" => "My Email" }
24+ end
25+
26+ it 'should send to a prospect' do
27+ 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_response
28+ @client . emails . send_to_prospect ( 42 , :campaign_id => 765 , :email_template_id => 86 ) . should == { "name" => "My Email" }
29+ end
30+
31+ it 'should send to a list' do
32+ 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_response
33+ @client . emails . send_to_list ( :email_template_id => 200 , 'list_ids[]' => 235 , :campaign_id => 654 ) . should == { "name" => "My Email" }
34+ end
35+
36+ end
You can’t perform that action at this time.
0 commit comments