ruby-pardot 1.2.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +9 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +26 -19
- data/README.rdoc +23 -18
- data/Rakefile +2 -3
- data/lib/pardot/authentication.rb +23 -12
- data/lib/pardot/client.rb +18 -6
- data/lib/pardot/error.rb +6 -2
- data/lib/pardot/http.rb +51 -41
- data/lib/pardot/objects/custom_fields.rb +33 -0
- 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 +69 -71
- 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/lib/ruby-pardot.rb +1 -0
- data/ruby-pardot.gemspec +15 -13
- data/spec/pardot/authentication_spec.rb +84 -50
- data/spec/pardot/client_spec.rb +52 -17
- data/spec/pardot/error_spec.rb +6 -4
- data/spec/pardot/http_spec.rb +96 -104
- data/spec/pardot/objects/custom_fields_spec.rb +53 -0
- data/spec/pardot/objects/emails_spec.rb +34 -33
- data/spec/pardot/objects/lists_spec.rb +34 -37
- data/spec/pardot/objects/opportunities_spec.rb +59 -60
- data/spec/pardot/objects/prospect_accounts_spec.rb +72 -73
- data/spec/pardot/objects/prospects_spec.rb +58 -57
- data/spec/pardot/objects/users_spec.rb +58 -60
- data/spec/pardot/objects/visitor_activities_spec.rb +57 -60
- data/spec/pardot/objects/visitors_spec.rb +56 -60
- data/spec/pardot/objects/visits_spec.rb +56 -60
- data/spec/spec_helper.rb +2 -0
- data/spec/support/client_support.rb +40 -4
- data/spec/support/fakeweb.rb +14 -5
- metadata +17 -18
data/spec/pardot/client_spec.rb
CHANGED
@@ -1,28 +1,63 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Client do
|
4
|
-
|
5
6
|
def create_client
|
6
|
-
@client = Pardot::Client.new
|
7
|
+
@client = Pardot::Client.new 'user@test.com', 'foo', 'bar'
|
7
8
|
end
|
8
|
-
|
9
|
-
describe
|
10
|
-
|
11
|
-
@client.
|
12
|
-
@client.
|
13
|
-
@client.
|
14
|
-
@client.
|
9
|
+
|
10
|
+
describe 'client with Salesforce access_token' do
|
11
|
+
it 'should set properties' do
|
12
|
+
@client = Pardot::Client.new nil, nil, nil, 3, 'access_token_value', '0Uv000000000001CAA'
|
13
|
+
expect(@client.email).to eq(nil)
|
14
|
+
expect(@client.password).to eq(nil)
|
15
|
+
expect(@client.user_key).to eq(nil)
|
16
|
+
expect(@client.api_key).to eq(nil)
|
17
|
+
expect(@client.version).to eq(3)
|
18
|
+
expect(@client.salesforce_access_token).to eq('access_token_value')
|
19
|
+
expect(@client.business_unit_id).to eq('0Uv000000000001CAA')
|
20
|
+
expect(@client.format).to eq('simple')
|
15
21
|
end
|
16
22
|
|
17
|
-
it
|
18
|
-
|
19
|
-
|
23
|
+
it 'raises error with nil business_unit_id' do
|
24
|
+
expect do
|
25
|
+
Pardot::Client.new nil, nil, nil, 3, 'access_token_value',
|
26
|
+
nil
|
27
|
+
end.to raise_error.with_message(/business_unit_id required when using Salesforce access_token/)
|
20
28
|
end
|
21
|
-
|
22
|
-
it
|
23
|
-
|
24
|
-
|
29
|
+
|
30
|
+
it 'raises error with invalid business_unit_id due to length' do
|
31
|
+
expect do
|
32
|
+
Pardot::Client.new nil, nil, nil, 3, 'access_token_value',
|
33
|
+
'0Uv1234567890'
|
34
|
+
end.to raise_error.with_message(/Invalid business_unit_id value. Expected ID to start with '0Uv' and be length of 18 characters./)
|
25
35
|
end
|
26
36
|
|
37
|
+
it 'raises error with invalid business_unit_id due to invalid prefix' do
|
38
|
+
expect do
|
39
|
+
Pardot::Client.new nil, nil, nil, 3, 'access_token_value',
|
40
|
+
'001000000000001AAA'
|
41
|
+
end.to raise_error.with_message(/Invalid business_unit_id value. Expected ID to start with '0Uv' and be length of 18 characters./)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'client' do
|
46
|
+
after do
|
47
|
+
expect(@client.email).to eq('user@test.com')
|
48
|
+
expect(@client.password).to eq('password')
|
49
|
+
expect(@client.user_key).to eq('user_key')
|
50
|
+
expect(@client.format).to eq('simple')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should set variables without version' do
|
54
|
+
@client = Pardot::Client.new 'user@test.com', 'password', 'user_key'
|
55
|
+
expect(@client.version).to eq(3)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should set variables with version' do
|
59
|
+
@client = Pardot::Client.new 'user@test.com', 'password', 'user_key', 4
|
60
|
+
expect(@client.version).to eq(4)
|
61
|
+
end
|
27
62
|
end
|
28
63
|
end
|
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
|
-
subject.to_s.
|
26
|
+
expect(subject.to_s).to eq(@res['__content__'])
|
25
27
|
end
|
26
28
|
specify do
|
27
|
-
subject.message.
|
29
|
+
expect(subject.message).to eq(@res['__content__'])
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
data/spec/pardot/http_spec.rb
CHANGED
@@ -1,132 +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
|
21
|
-
fake_get
|
22
|
-
%(
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
it
|
28
|
-
Pardot::Client.
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
it
|
34
|
-
fake_get
|
35
|
-
%(
|
36
|
-
|
37
|
-
@client.
|
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
|
+
expect(-> { get }).to raise_error(Pardot::ResponseError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
28
|
+
expect(Pardot::Client).to receive(:get).and_raise(SocketError)
|
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
|
+
|
37
|
+
expect(@client).to receive(:handle_expired_api_key)
|
38
38
|
get
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
|
-
|
43
|
-
describe
|
44
|
-
|
45
|
-
def post object = "foo", path = "/bar", params = {}
|
41
|
+
|
42
|
+
describe 'post' do
|
43
|
+
def post(object = 'foo', path = '/bar', params = {})
|
46
44
|
@client.post object, path, params
|
47
45
|
end
|
48
|
-
|
49
|
-
it
|
50
|
-
fake_post
|
51
|
-
%(
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
it
|
57
|
-
Pardot::Client.
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
it
|
63
|
-
fake_post
|
64
|
-
%(
|
65
|
-
|
66
|
-
@client.
|
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)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
55
|
+
expect(Pardot::Client).to receive(:post).and_raise(SocketError)
|
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
|
+
|
64
|
+
expect(@client).to receive(:handle_expired_api_key)
|
67
65
|
post
|
68
66
|
end
|
69
|
-
|
70
67
|
end
|
71
68
|
|
72
|
-
describe
|
73
|
-
|
74
|
-
|
75
|
-
@client.version = "4"
|
69
|
+
describe 'getV4' do
|
70
|
+
def get(object = 'foo', path = '/bar', params = {})
|
71
|
+
@client.version = '4'
|
76
72
|
@client.get object, path, params
|
77
73
|
end
|
78
|
-
|
79
|
-
it
|
80
|
-
fake_get
|
81
|
-
%(
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
it
|
87
|
-
Pardot::Client.
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
it
|
93
|
-
fake_get
|
94
|
-
%(
|
95
|
-
|
96
|
-
@client.
|
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)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
83
|
+
expect(Pardot::Client).to receive(:get).and_raise(SocketError)
|
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
|
+
|
92
|
+
expect(@client).to receive(:handle_expired_api_key)
|
97
93
|
get
|
98
94
|
end
|
99
|
-
|
100
95
|
end
|
101
|
-
|
102
|
-
describe
|
103
|
-
|
104
|
-
|
105
|
-
@client.version = "4"
|
96
|
+
|
97
|
+
describe 'postV4' do
|
98
|
+
def post(object = 'foo', path = '/bar', params = {})
|
99
|
+
@client.version = '4'
|
106
100
|
@client.post object, path, params
|
107
101
|
end
|
108
|
-
|
109
|
-
it
|
110
|
-
fake_post
|
111
|
-
%(
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
it
|
117
|
-
Pardot::Client.
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
it
|
123
|
-
fake_post
|
124
|
-
%(
|
125
|
-
|
126
|
-
@client.
|
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)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should catch and reraise SocketErrors as Pardot::NetError' do
|
111
|
+
expect(Pardot::Client).to receive(:post).and_raise(SocketError)
|
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
|
+
|
120
|
+
expect(@client).to receive(:handle_expired_api_key)
|
127
121
|
post
|
128
122
|
end
|
129
|
-
|
130
123
|
end
|
131
|
-
|
132
|
-
end
|
124
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
4
|
+
|
5
|
+
describe Pardot::Objects::CustomFields 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
|
+
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
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,36 +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
|
-
|
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
|
34
36
|
end
|
35
|
-
|
36
|
-
end
|
37
|
+
end
|