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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +9 -0
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +26 -19
  6. data/README.rdoc +23 -18
  7. data/Rakefile +2 -3
  8. data/lib/pardot/authentication.rb +23 -12
  9. data/lib/pardot/client.rb +18 -6
  10. data/lib/pardot/error.rb +6 -2
  11. data/lib/pardot/http.rb +51 -41
  12. data/lib/pardot/objects/custom_fields.rb +33 -0
  13. data/lib/pardot/objects/emails.rb +9 -14
  14. data/lib/pardot/objects/list_memberships.rb +8 -12
  15. data/lib/pardot/objects/lists.rb +20 -25
  16. data/lib/pardot/objects/opportunities.rb +21 -26
  17. data/lib/pardot/objects/prospect_accounts.rb +6 -7
  18. data/lib/pardot/objects/prospects.rb +69 -71
  19. data/lib/pardot/objects/users.rb +17 -21
  20. data/lib/pardot/objects/visitor_activities.rb +15 -19
  21. data/lib/pardot/objects/visitors.rb +17 -21
  22. data/lib/pardot/objects/visits.rb +15 -19
  23. data/lib/pardot/version.rb +1 -1
  24. data/lib/ruby-pardot.rb +1 -0
  25. data/ruby-pardot.gemspec +15 -13
  26. data/spec/pardot/authentication_spec.rb +84 -50
  27. data/spec/pardot/client_spec.rb +52 -17
  28. data/spec/pardot/error_spec.rb +6 -4
  29. data/spec/pardot/http_spec.rb +96 -104
  30. data/spec/pardot/objects/custom_fields_spec.rb +53 -0
  31. data/spec/pardot/objects/emails_spec.rb +34 -33
  32. data/spec/pardot/objects/lists_spec.rb +34 -37
  33. data/spec/pardot/objects/opportunities_spec.rb +59 -60
  34. data/spec/pardot/objects/prospect_accounts_spec.rb +72 -73
  35. data/spec/pardot/objects/prospects_spec.rb +58 -57
  36. data/spec/pardot/objects/users_spec.rb +58 -60
  37. data/spec/pardot/objects/visitor_activities_spec.rb +57 -60
  38. data/spec/pardot/objects/visitors_spec.rb +56 -60
  39. data/spec/pardot/objects/visits_spec.rb +56 -60
  40. data/spec/spec_helper.rb +2 -0
  41. data/spec/support/client_support.rb +40 -4
  42. data/spec/support/fakeweb.rb +14 -5
  43. metadata +17 -18
@@ -1,28 +1,63 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
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 "user@test.com", "foo", "bar"
7
+ @client = Pardot::Client.new 'user@test.com', 'foo', 'bar'
7
8
  end
8
-
9
- describe "client" do
10
- after do
11
- @client.email.should == "user@test.com"
12
- @client.password.should == "password"
13
- @client.user_key.should == "user_key"
14
- @client.format.should == "simple"
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 "should set variables without version" do
18
- @client = Pardot::Client.new "user@test.com", "password", "user_key"
19
- @client.version.should == 3
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 "should set variables with version" do
23
- @client = Pardot::Client.new "user@test.com", "password", "user_key", 4
24
- @client.version.should == 4
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
@@ -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
- "code" => "9",
6
- "__content__" => "A prospect with the specified email address already exists"
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.should == @res["__content__"]
26
+ expect(subject.to_s).to eq(@res['__content__'])
25
27
  end
26
28
  specify do
27
- subject.message.should == @res["__content__"]
29
+ expect(subject.message).to eq(@res['__content__'])
28
30
  end
29
31
  end
30
32
 
@@ -1,132 +1,124 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
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, "my_api_key"
8
+ fake_authenticate @client, 'my_api_key'
8
9
  end
9
-
10
+
10
11
  def create_client
11
- @client = Pardot::Client.new "user@test.com", "foo", "bar"
12
+ @client = Pardot::Client.new 'user@test.com', 'foo', 'bar'
12
13
  end
13
-
14
- describe "get" do
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?api_key=my_api_key&format=simple&user_key=bar",
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
- lambda { get }.should raise_error(Pardot::ResponseError)
25
- end
26
-
27
- it "should catch and reraise SocketErrors as Pardot::NetError" do
28
- Pardot::Client.should_receive(:get).and_raise(SocketError)
29
-
30
- lambda { get }.should 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?api_key=my_api_key&format=simple&user_key=bar",
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
- @client.should_receive(:handle_expired_api_key)
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 "post" do
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 "should notice errors and raise them as Pardot::ResponseError" do
50
- fake_post "/api/foo/version/3/bar?api_key=my_api_key&format=simple&user_key=bar",
51
- %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
52
-
53
- lambda { post }.should raise_error(Pardot::ResponseError)
54
- end
55
-
56
- it "should catch and reraise SocketErrors as Pardot::NetError" do
57
- Pardot::Client.should_receive(:post).and_raise(SocketError)
58
-
59
- lambda { post }.should raise_error(Pardot::NetError)
60
- end
61
-
62
- it "should call handle_expired_api_key when the api key expires" do
63
- fake_post "/api/foo/version/3/bar?api_key=my_api_key&format=simple&user_key=bar",
64
- %(?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)
65
-
66
- @client.should_receive(:handle_expired_api_key)
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 "getV4" do
73
-
74
- def get object = "foo", path = "/bar", params = {}
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 "should notice errors and raise them as Pardot::ResponseError" do
80
- fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
81
- %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
82
-
83
- lambda { get }.should raise_error(Pardot::ResponseError)
84
- end
85
-
86
- it "should catch and reraise SocketErrors as Pardot::NetError" do
87
- Pardot::Client.should_receive(:get).and_raise(SocketError)
88
-
89
- lambda { get }.should raise_error(Pardot::NetError)
90
- end
91
-
92
- it "should call handle_expired_api_key when the api key expires" do
93
- fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
94
- %(?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)
95
-
96
- @client.should_receive(:handle_expired_api_key)
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 "postV4" do
103
-
104
- def post object = "foo", path = "/bar", params = {}
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 "should notice errors and raise them as Pardot::ResponseError" do
110
- fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
111
- %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
112
-
113
- lambda { post }.should raise_error(Pardot::ResponseError)
114
- end
115
-
116
- it "should catch and reraise SocketErrors as Pardot::NetError" do
117
- Pardot::Client.should_receive(:post).and_raise(SocketError)
118
-
119
- lambda { post }.should raise_error(Pardot::NetError)
120
- end
121
-
122
- it "should call handle_expired_api_key when the api key expires" do
123
- fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
124
- %(?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)
125
-
126
- @client.should_receive(:handle_expired_api_key)
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
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ # frozen_string_literal: true
2
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
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
20
4
 
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"}
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