ruby-pardot 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +9 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +5 -5
- data/README.rdoc +19 -17
- data/Rakefile +2 -3
- data/lib/pardot/authentication.rb +23 -12
- data/lib/pardot/client.rb +17 -6
- data/lib/pardot/error.rb +6 -2
- data/lib/pardot/http.rb +47 -44
- data/lib/pardot/objects/custom_fields.rb +13 -17
- data/lib/pardot/objects/emails.rb +9 -14
- data/lib/pardot/objects/list_memberships.rb +8 -12
- data/lib/pardot/objects/lists.rb +20 -25
- data/lib/pardot/objects/opportunities.rb +21 -26
- data/lib/pardot/objects/prospect_accounts.rb +6 -7
- data/lib/pardot/objects/prospects.rb +26 -30
- data/lib/pardot/objects/users.rb +17 -21
- data/lib/pardot/objects/visitor_activities.rb +15 -19
- data/lib/pardot/objects/visitors.rb +17 -21
- data/lib/pardot/objects/visits.rb +15 -19
- data/lib/pardot/version.rb +1 -1
- data/ruby-pardot.gemspec +14 -12
- data/spec/pardot/authentication_spec.rb +78 -44
- data/spec/pardot/client_spec.rb +50 -15
- data/spec/pardot/error_spec.rb +6 -4
- data/spec/pardot/http_spec.rb +83 -92
- data/spec/pardot/objects/custom_fields_spec.rb +48 -53
- data/spec/pardot/objects/emails_spec.rb +34 -36
- data/spec/pardot/objects/lists_spec.rb +34 -38
- data/spec/pardot/objects/opportunities_spec.rb +58 -61
- data/spec/pardot/objects/prospect_accounts_spec.rb +72 -75
- data/spec/pardot/objects/prospects_spec.rb +56 -56
- data/spec/pardot/objects/users_spec.rb +58 -61
- data/spec/pardot/objects/visitor_activities_spec.rb +57 -61
- data/spec/pardot/objects/visitors_spec.rb +56 -61
- data/spec/pardot/objects/visits_spec.rb +56 -61
- data/spec/spec_helper.rb +2 -0
- data/spec/support/client_support.rb +40 -4
- data/spec/support/fakeweb.rb +13 -8
- metadata +8 -7
data/spec/pardot/error_spec.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
describe Pardot::ResponseError do
|
3
5
|
before do
|
4
6
|
@res = {
|
5
|
-
|
6
|
-
|
7
|
+
'code' => '9',
|
8
|
+
'__content__' => 'A prospect with the specified email address already exists'
|
7
9
|
}
|
8
10
|
end
|
9
11
|
|
@@ -21,10 +23,10 @@ describe Pardot::ResponseError do
|
|
21
23
|
described_class.new(@res)
|
22
24
|
end
|
23
25
|
specify do
|
24
|
-
expect(subject.to_s).to eq(@res[
|
26
|
+
expect(subject.to_s).to eq(@res['__content__'])
|
25
27
|
end
|
26
28
|
specify do
|
27
|
-
expect(subject.message).to eq(@res[
|
29
|
+
expect(subject.message).to eq(@res['__content__'])
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
data/spec/pardot/http_spec.rb
CHANGED
@@ -1,133 +1,124 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Http do
|
4
|
-
|
5
6
|
before do
|
6
7
|
@client = create_client
|
7
|
-
fake_authenticate @client,
|
8
|
+
fake_authenticate @client, 'my_api_key'
|
8
9
|
end
|
9
|
-
|
10
|
+
|
10
11
|
def create_client
|
11
|
-
@client = Pardot::Client.new
|
12
|
+
@client = Pardot::Client.new 'user@test.com', 'foo', 'bar'
|
12
13
|
end
|
13
|
-
|
14
|
-
describe
|
15
|
-
|
16
|
-
def get object = "foo", path = "/bar", params = {}
|
14
|
+
|
15
|
+
describe 'get' do
|
16
|
+
def get(object = 'foo', path = '/bar', params = {})
|
17
17
|
@client.get object, path, params
|
18
18
|
end
|
19
|
-
|
20
|
-
it "should notice errors and raise them as Pardot::ResponseError" do
|
21
|
-
fake_get "/api/foo/version/3/bar?format=simple",
|
22
|
-
%(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
|
23
|
-
|
24
19
|
|
25
|
-
|
20
|
+
it 'should notice errors and raise them as Pardot::ResponseError' do
|
21
|
+
fake_get '/api/foo/version/3/bar?format=simple',
|
22
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
|
23
|
+
|
24
|
+
expect(-> { get }).to raise_error(Pardot::ResponseError)
|
26
25
|
end
|
27
|
-
|
28
|
-
it
|
26
|
+
|
27
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
29
28
|
expect(Pardot::Client).to receive(:get).and_raise(SocketError)
|
30
|
-
|
31
|
-
expect(
|
32
|
-
end
|
33
|
-
|
34
|
-
it
|
35
|
-
fake_get
|
36
|
-
%(
|
37
|
-
|
29
|
+
|
30
|
+
expect(-> { get }).to raise_error(Pardot::NetError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should call handle_expired_api_key when the api key expires' do
|
34
|
+
fake_get '/api/foo/version/3/bar?format=simple',
|
35
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n)
|
36
|
+
|
38
37
|
expect(@client).to receive(:handle_expired_api_key)
|
39
38
|
get
|
40
39
|
end
|
41
|
-
|
42
40
|
end
|
43
|
-
|
44
|
-
describe
|
45
|
-
|
46
|
-
def post object = "foo", path = "/bar", params = {}
|
41
|
+
|
42
|
+
describe 'post' do
|
43
|
+
def post(object = 'foo', path = '/bar', params = {})
|
47
44
|
@client.post object, path, params
|
48
45
|
end
|
49
|
-
|
50
|
-
it
|
51
|
-
fake_post
|
52
|
-
%(
|
53
|
-
|
54
|
-
expect(
|
46
|
+
|
47
|
+
it 'should notice errors and raise them as Pardot::ResponseError' do
|
48
|
+
fake_post '/api/foo/version/3/bar?format=simple',
|
49
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
|
50
|
+
|
51
|
+
expect(-> { post }).to raise_error(Pardot::ResponseError)
|
55
52
|
end
|
56
|
-
|
57
|
-
it
|
53
|
+
|
54
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
58
55
|
expect(Pardot::Client).to receive(:post).and_raise(SocketError)
|
59
|
-
|
60
|
-
expect(
|
61
|
-
end
|
62
|
-
|
63
|
-
it
|
64
|
-
fake_post
|
65
|
-
%(
|
66
|
-
|
56
|
+
|
57
|
+
expect(-> { post }).to raise_error(Pardot::NetError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should call handle_expired_api_key when the api key expires' do
|
61
|
+
fake_post '/api/foo/version/3/bar?format=simple',
|
62
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n)
|
63
|
+
|
67
64
|
expect(@client).to receive(:handle_expired_api_key)
|
68
65
|
post
|
69
66
|
end
|
70
|
-
|
71
67
|
end
|
72
68
|
|
73
|
-
describe
|
74
|
-
|
75
|
-
|
76
|
-
@client.version = "4"
|
69
|
+
describe 'getV4' do
|
70
|
+
def get(object = 'foo', path = '/bar', params = {})
|
71
|
+
@client.version = '4'
|
77
72
|
@client.get object, path, params
|
78
73
|
end
|
79
|
-
|
80
|
-
it
|
81
|
-
fake_get
|
82
|
-
%(
|
83
|
-
|
84
|
-
expect(
|
74
|
+
|
75
|
+
it 'should notice errors and raise them as Pardot::ResponseError' do
|
76
|
+
fake_get '/api/foo/version/4/bar?format=simple',
|
77
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
|
78
|
+
|
79
|
+
expect(-> { get }).to raise_error(Pardot::ResponseError)
|
85
80
|
end
|
86
|
-
|
87
|
-
it
|
81
|
+
|
82
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
88
83
|
expect(Pardot::Client).to receive(:get).and_raise(SocketError)
|
89
|
-
|
90
|
-
expect(
|
91
|
-
end
|
92
|
-
|
93
|
-
it
|
94
|
-
fake_get
|
95
|
-
%(
|
96
|
-
|
84
|
+
|
85
|
+
expect(-> { get }).to raise_error(Pardot::NetError)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should call handle_expired_api_key when the api key expires' do
|
89
|
+
fake_get '/api/foo/version/4/bar?format=simple',
|
90
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n)
|
91
|
+
|
97
92
|
expect(@client).to receive(:handle_expired_api_key)
|
98
93
|
get
|
99
94
|
end
|
100
|
-
|
101
95
|
end
|
102
|
-
|
103
|
-
describe
|
104
|
-
|
105
|
-
|
106
|
-
@client.version = "4"
|
96
|
+
|
97
|
+
describe 'postV4' do
|
98
|
+
def post(object = 'foo', path = '/bar', params = {})
|
99
|
+
@client.version = '4'
|
107
100
|
@client.post object, path, params
|
108
101
|
end
|
109
|
-
|
110
|
-
it
|
111
|
-
fake_post
|
112
|
-
%(
|
113
|
-
|
114
|
-
expect(
|
102
|
+
|
103
|
+
it 'should notice errors and raise them as Pardot::ResponseError' do
|
104
|
+
fake_post '/api/foo/version/4/bar?format=simple',
|
105
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
|
106
|
+
|
107
|
+
expect(-> { post }).to raise_error(Pardot::ResponseError)
|
115
108
|
end
|
116
|
-
|
117
|
-
it
|
109
|
+
|
110
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
118
111
|
expect(Pardot::Client).to receive(:post).and_raise(SocketError)
|
119
|
-
|
120
|
-
expect(
|
121
|
-
end
|
122
|
-
|
123
|
-
it
|
124
|
-
fake_post
|
125
|
-
%(
|
126
|
-
|
112
|
+
|
113
|
+
expect(-> { post }).to raise_error(Pardot::NetError)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should call handle_expired_api_key when the api key expires' do
|
117
|
+
fake_post '/api/foo/version/4/bar?format=simple',
|
118
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n)
|
119
|
+
|
127
120
|
expect(@client).to receive(:handle_expired_api_key)
|
128
121
|
post
|
129
122
|
end
|
130
|
-
|
131
123
|
end
|
132
|
-
|
133
|
-
end
|
124
|
+
end
|
@@ -1,58 +1,53 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Objects::CustomFields do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
</
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
"created_at"=>"2019-11-26 13:40:37",
|
50
|
-
"updated_at"=>"2019-11-26 13:40:37"
|
51
|
-
}
|
52
|
-
})
|
53
|
-
assert_authorization_header
|
6
|
+
create_auth_managers.each do |auth_manager|
|
7
|
+
context auth_manager.test_name_suffix do
|
8
|
+
let(:client) { auth_manager.create_client }
|
9
|
+
|
10
|
+
describe 'query' do
|
11
|
+
def sample_results
|
12
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
|
13
|
+
<result>
|
14
|
+
<total_results>1</total_results>
|
15
|
+
<customField>
|
16
|
+
<created_at>2019-11-26 13:40:37</created_at>
|
17
|
+
<crm_id null="true" />
|
18
|
+
<field_id>CustomObject1574793618883</field_id>
|
19
|
+
<id>8932</id>
|
20
|
+
<is_record_multiple_responses>false</is_record_multiple_responses>
|
21
|
+
<is_use_values>false</is_use_values>
|
22
|
+
<name>Ω≈ç√∫˜µ≤≥÷</name>
|
23
|
+
<type>Text</type>
|
24
|
+
<type_id>1</type_id>
|
25
|
+
<updated_at>2019-11-26 13:40:37</updated_at>
|
26
|
+
</customField>
|
27
|
+
</result>
|
28
|
+
</rsp>)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should take in some arguments' do
|
32
|
+
fake_get '/api/customField/version/3/do/query?id_greater_than=200&format=simple', sample_results
|
33
|
+
|
34
|
+
expect(client.custom_fields.query(id_greater_than: 200)).to eq({ 'total_results' => 1,
|
35
|
+
'customField' =>
|
36
|
+
{
|
37
|
+
'id' => '8932',
|
38
|
+
'name' => 'Ω≈ç√∫˜µ≤≥÷',
|
39
|
+
'field_id' => 'CustomObject1574793618883',
|
40
|
+
'type' => 'Text',
|
41
|
+
'type_id' => '1',
|
42
|
+
'crm_id' => { 'null' => 'true' },
|
43
|
+
'is_record_multiple_responses' => 'false',
|
44
|
+
'is_use_values' => 'false',
|
45
|
+
'created_at' => '2019-11-26 13:40:37',
|
46
|
+
'updated_at' => '2019-11-26 13:40:37'
|
47
|
+
} })
|
48
|
+
assert_authorization_header auth_manager
|
49
|
+
end
|
50
|
+
end
|
54
51
|
end
|
55
|
-
|
56
52
|
end
|
57
|
-
|
58
53
|
end
|
@@ -1,39 +1,37 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
20
4
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
5
|
+
describe Pardot::Objects::Emails do
|
6
|
+
create_auth_managers.each do |auth_manager|
|
7
|
+
context auth_manager.test_name_suffix do
|
8
|
+
let(:client) { auth_manager.create_client }
|
9
|
+
|
10
|
+
def sample_response
|
11
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
|
12
|
+
<email>
|
13
|
+
<name>My Email</name>
|
14
|
+
</email>
|
15
|
+
</rsp>)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should take in the email ID' do
|
19
|
+
fake_get '/api/email/version/3/do/read/id/12?format=simple', sample_response
|
20
|
+
expect(client.emails.read_by_id(12)).to eq({ 'name' => 'My Email' })
|
21
|
+
assert_authorization_header auth_manager
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should send to a prospect' do
|
25
|
+
fake_post '/api/email/version/3/do/send/prospect_id/42?campaign_id=765&email_template_id=86&format=simple', sample_response
|
26
|
+
expect(client.emails.send_to_prospect(42, campaign_id: 765, email_template_id: 86)).to eq({ 'name' => 'My Email' })
|
27
|
+
assert_authorization_header auth_manager
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should send to a list' do
|
31
|
+
fake_post '/api/email/version/3/do/send?email_template_id=200&list_ids%5B%5D=235&campaign_id=654&format=simple', sample_response
|
32
|
+
expect(client.emails.send_to_list(:email_template_id => 200, 'list_ids[]' => 235, :campaign_id => 654)).to eq({ 'name' => 'My Email' })
|
33
|
+
assert_authorization_header auth_manager
|
34
|
+
end
|
35
|
+
end
|
37
36
|
end
|
38
|
-
|
39
|
-
end
|
37
|
+
end
|
@@ -1,42 +1,38 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Objects::Lists do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
</
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
{"name"=>"Asdf List"},
|
35
|
-
{"name"=>"Qwerty List"}
|
36
|
-
]})
|
37
|
-
assert_authorization_header
|
6
|
+
create_auth_managers.each do |auth_manager|
|
7
|
+
context auth_manager.test_name_suffix do
|
8
|
+
let(:client) { auth_manager.create_client }
|
9
|
+
|
10
|
+
describe 'query' do
|
11
|
+
def sample_results
|
12
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
|
13
|
+
<result>
|
14
|
+
<total_results>2</total_results>
|
15
|
+
<list>
|
16
|
+
<name>Asdf List</name>
|
17
|
+
</list>
|
18
|
+
<list>
|
19
|
+
<name>Qwerty List</name>
|
20
|
+
</list>
|
21
|
+
</result>
|
22
|
+
</rsp>)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should take in some arguments' do
|
26
|
+
fake_get '/api/list/version/3/do/query?id_greater_than=200&format=simple', sample_results
|
27
|
+
|
28
|
+
expect(client.lists.query(id_greater_than: 200)).to eq({ 'total_results' => 2,
|
29
|
+
'list' => [
|
30
|
+
{ 'name' => 'Asdf List' },
|
31
|
+
{ 'name' => 'Qwerty List' }
|
32
|
+
] })
|
33
|
+
assert_authorization_header auth_manager
|
34
|
+
end
|
35
|
+
end
|
38
36
|
end
|
39
|
-
|
40
37
|
end
|
41
|
-
|
42
|
-
end
|
38
|
+
end
|