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.
Files changed (42) 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 +5 -5
  6. data/README.rdoc +19 -17
  7. data/Rakefile +2 -3
  8. data/lib/pardot/authentication.rb +23 -12
  9. data/lib/pardot/client.rb +17 -6
  10. data/lib/pardot/error.rb +6 -2
  11. data/lib/pardot/http.rb +47 -44
  12. data/lib/pardot/objects/custom_fields.rb +13 -17
  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 +26 -30
  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/ruby-pardot.gemspec +14 -12
  25. data/spec/pardot/authentication_spec.rb +78 -44
  26. data/spec/pardot/client_spec.rb +50 -15
  27. data/spec/pardot/error_spec.rb +6 -4
  28. data/spec/pardot/http_spec.rb +83 -92
  29. data/spec/pardot/objects/custom_fields_spec.rb +48 -53
  30. data/spec/pardot/objects/emails_spec.rb +34 -36
  31. data/spec/pardot/objects/lists_spec.rb +34 -38
  32. data/spec/pardot/objects/opportunities_spec.rb +58 -61
  33. data/spec/pardot/objects/prospect_accounts_spec.rb +72 -75
  34. data/spec/pardot/objects/prospects_spec.rb +56 -56
  35. data/spec/pardot/objects/users_spec.rb +58 -61
  36. data/spec/pardot/objects/visitor_activities_spec.rb +57 -61
  37. data/spec/pardot/objects/visitors_spec.rb +56 -61
  38. data/spec/pardot/objects/visits_spec.rb +56 -61
  39. data/spec/spec_helper.rb +2 -0
  40. data/spec/support/client_support.rb +40 -4
  41. data/spec/support/fakeweb.rb +13 -8
  42. metadata +8 -7
@@ -1,66 +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::Objects::Opportunities do
4
-
5
- before do
6
- @client = create_client
7
- end
8
-
9
- describe "query" do
10
-
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
- <opportunity>
16
- <name>Jim</name>
17
- <type>Great</type>
18
- </opportunity>
19
- <opportunity>
20
- <name>Sue</name>
21
- <type>Good</type>
22
- </opportunity>
23
- </result>
24
- </rsp>)
25
- end
26
-
27
- before do
28
- @client = create_client
29
- end
30
-
31
- it "should take in some arguments" do
32
- fake_get "/api/opportunity/version/3/do/query?id_greater_than=200&format=simple", sample_results
33
-
34
- expect(@client.opportunities.query(:id_greater_than => 200)).to eq({"total_results" => 2,
35
- "opportunity"=>[
36
- {"type"=>"Great", "name"=>"Jim"},
37
- {"type"=>"Good", "name"=>"Sue"}
38
- ]})
39
- assert_authorization_header
40
- end
41
-
42
- end
43
-
44
- describe "create_by_email" do
45
-
46
- def sample_results
47
- %(<?xml version="1.0" encoding="UTF-8"?>
48
- <rsp stat="ok" version="1.0">
49
- <opportunity>
50
- <name>Jim</name>
51
- <type>Good</type>
52
- </opportunity>
53
- </rsp>)
54
- end
55
-
56
- it "should return the prospect" do
57
- fake_post "/api/opportunity/version/3/do/create/prospect_email/user@test.com?type=Good&format=simple&name=Jim", sample_results
58
-
59
- expect(@client.opportunities.create_by_email("user@test.com", :name => "Jim", :type => "Good")).to eq({"name"=>"Jim", "type"=>"Good"})
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
+ <opportunity>
16
+ <name>Jim</name>
17
+ <type>Great</type>
18
+ </opportunity>
19
+ <opportunity>
20
+ <name>Sue</name>
21
+ <type>Good</type>
22
+ </opportunity>
23
+ </result>
24
+ </rsp>)
25
+ end
26
+
27
+ it 'should take in some arguments' do
28
+ fake_get '/api/opportunity/version/3/do/query?id_greater_than=200&format=simple', sample_results
29
+
30
+ expected = {
31
+ 'total_results' => 2,
32
+ 'opportunity' => [
33
+ { 'type' => 'Great', 'name' => 'Jim' },
34
+ { 'type' => 'Good', 'name' => 'Sue' }
35
+ ]
36
+ }
37
+ expect(client.opportunities.query(id_greater_than: 200)).to eq(expected)
38
+ assert_authorization_header auth_manager
39
+ end
40
+ end
41
+
42
+ describe 'create_by_email' do
43
+ def sample_results
44
+ %(<?xml version="1.0" encoding="UTF-8"?>
45
+ <rsp stat="ok" version="1.0">
46
+ <opportunity>
47
+ <name>Jim</name>
48
+ <type>Good</type>
49
+ </opportunity>
50
+ </rsp>)
51
+ end
52
+
53
+ it 'should return the prospect' do
54
+ fake_post '/api/opportunity/version/3/do/create/prospect_email/user@test.com?type=Good&format=simple&name=Jim', sample_results
55
+
56
+ expect(client.opportunities.create_by_email('user@test.com', name: 'Jim', type: 'Good')).to eq({ 'name' => 'Jim', 'type' => 'Good' })
60
57
 
61
- assert_authorization_header
58
+ assert_authorization_header auth_manager
59
+ end
60
+ end
62
61
  end
63
-
64
62
  end
65
-
66
- end
63
+ end
@@ -1,80 +1,77 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ # frozen_string_literal: true
2
2
 
3
- describe Pardot::Objects::ProspectAccounts do
4
-
5
- before do
6
- @client = create_client
7
- end
8
-
9
- describe "query" do
10
-
11
- def sample_results
12
- %(<?xml version="1.0" encoding="UTF-8"?>
13
- <rsp stat="ok" version="1.0">
14
- <result>
15
- <total_results>2</total_results>
16
- <prospectAccount>
17
- <name>Spaceships R Us</name>
18
- </prospectAccount>
19
- <prospectAccount>
20
- <name>Monsters Inc</name>
21
- </prospectAccount>
22
- </result>
23
- </rsp>)
24
- end
25
-
26
- it "should take in some arguments and respond with valid items" do
27
- fake_get "/api/prospectAccount/version/3/do/query?assigned=true&format=simple", sample_results
28
-
29
- expect(@client.prospect_accounts.query(:assigned => true)).to eq({'total_results' => 2,
30
- 'prospectAccount'=>[
31
- {'name'=>'Spaceships R Us'},
32
- {'name'=>'Monsters Inc'}
33
- ]})
34
- assert_authorization_header
35
- end
36
-
37
- end
38
-
39
- describe 'read' do
40
- def sample_results
41
- %(<?xml version="1.0" encoding="UTF-8"?>
42
- <rsp stat="ok" version="1.0">
43
- <prospectAccount>
44
- <id>1234</id>
45
- <name>SupaDupaPanda</name>
46
- </prospectAccount>
47
- </rsp>)
48
- end
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
49
4
 
50
- it 'should return a valid account' do
51
- fake_post '/api/prospectAccount/version/3/do/read/id/1234?assigned=true&format=simple', sample_results
52
-
53
- expect(@client.prospect_accounts.read('1234', :assigned => true)).to eq({'id' => '1234', 'name' => 'SupaDupaPanda' })
54
- assert_authorization_header
55
- end
56
-
57
- end
58
-
59
-
60
- describe 'create' do
61
-
62
- def sample_results
63
- %(<?xml version="1.0" encoding="UTF-8"?>
64
- <rsp stat="ok" version="1.0">
65
- <prospectAccount>
66
- <name>SuperPanda</name>
67
- </prospectAccount>
68
- </rsp>)
69
- end
70
-
71
- it 'should return the prospect account' do
72
- fake_post '/api/prospectAccount/version/3/do/create?format=simple&name=SuperPanda', sample_results
73
-
74
- expect(@client.prospect_accounts.create(:name => 'SuperPanda')).to eq({"name"=>"SuperPanda"})
75
- assert_authorization_header
5
+ describe Pardot::Objects::ProspectAccounts 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"?>
13
+ <rsp stat="ok" version="1.0">
14
+ <result>
15
+ <total_results>2</total_results>
16
+ <prospectAccount>
17
+ <name>Spaceships R Us</name>
18
+ </prospectAccount>
19
+ <prospectAccount>
20
+ <name>Monsters Inc</name>
21
+ </prospectAccount>
22
+ </result>
23
+ </rsp>)
24
+ end
25
+
26
+ it 'should take in some arguments and respond with valid items' do
27
+ fake_get '/api/prospectAccount/version/3/do/query?assigned=true&format=simple', sample_results
28
+
29
+ expect(client.prospect_accounts.query(assigned: true)).to eq({ 'total_results' => 2,
30
+ 'prospectAccount' => [
31
+ { 'name' => 'Spaceships R Us' },
32
+ { 'name' => 'Monsters Inc' }
33
+ ] })
34
+ assert_authorization_header auth_manager
35
+ end
36
+ end
37
+
38
+ describe 'read' do
39
+ def sample_results
40
+ %(<?xml version="1.0" encoding="UTF-8"?>
41
+ <rsp stat="ok" version="1.0">
42
+ <prospectAccount>
43
+ <id>1234</id>
44
+ <name>SupaDupaPanda</name>
45
+ </prospectAccount>
46
+ </rsp>)
47
+ end
48
+
49
+ it 'should return a valid account' do
50
+ fake_post '/api/prospectAccount/version/3/do/read/id/1234?assigned=true&format=simple', sample_results
51
+
52
+ expect(client.prospect_accounts.read('1234',
53
+ assigned: true)).to eq({ 'id' => '1234', 'name' => 'SupaDupaPanda' })
54
+ assert_authorization_header auth_manager
55
+ end
56
+ end
57
+
58
+ describe 'create' do
59
+ def sample_results
60
+ %(<?xml version="1.0" encoding="UTF-8"?>
61
+ <rsp stat="ok" version="1.0">
62
+ <prospectAccount>
63
+ <name>SuperPanda</name>
64
+ </prospectAccount>
65
+ </rsp>)
66
+ end
67
+
68
+ it 'should return the prospect account' do
69
+ fake_post '/api/prospectAccount/version/3/do/create?format=simple&name=SuperPanda', sample_results
70
+
71
+ expect(client.prospect_accounts.create(name: 'SuperPanda')).to eq({ 'name' => 'SuperPanda' })
72
+ assert_authorization_header auth_manager
73
+ end
74
+ end
76
75
  end
77
-
78
76
  end
79
-
80
77
  end
@@ -1,62 +1,62 @@
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::Objects::Prospects do
4
-
5
- before do
6
- @client = create_client
7
- end
8
-
9
- describe "query" do
10
-
11
- def sample_results
12
- %(<?xml version="1.0" encoding="UTF-8"?>
13
- <rsp stat="ok" version="1.0">
14
- <result>
15
- <total_results>2</total_results>
16
- <prospect>
17
- <first_name>Jim</first_name>
18
- <last_name>Smith</last_name>
19
- </prospect>
20
- <prospect>
21
- <first_name>Sue</first_name>
22
- <last_name>Green</last_name>
23
- </prospect>
24
- </result>
25
- </rsp>)
26
- end
27
-
28
- it "should take in some arguments" do
29
- fake_get "/api/prospect/version/3/do/query?assigned=true&format=simple", sample_results
30
-
31
- expect(@client.prospects.query(:assigned => true)).to eq({"total_results" => 2,
32
- "prospect"=>[
33
- {"last_name"=>"Smith", "first_name"=>"Jim"},
34
- {"last_name"=>"Green", "first_name"=>"Sue"}
35
- ]})
36
- assert_authorization_header
37
- end
38
-
39
- end
40
-
41
- describe "create" do
42
-
43
- def sample_results
44
- %(<?xml version="1.0" encoding="UTF-8"?>
45
- <rsp stat="ok" version="1.0">
46
- <prospect>
47
- <first_name>Jim</first_name>
48
- <last_name>Smith</last_name>
49
- </prospect>
50
- </rsp>)
51
- end
52
-
53
- it "should return the prospect" do
54
- fake_post "/api/prospect/version/3/do/create/email/user%40test.com?first_name=Jim&format=simple", sample_results
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"?>
13
+ <rsp stat="ok" version="1.0">
14
+ <result>
15
+ <total_results>2</total_results>
16
+ <prospect>
17
+ <first_name>Jim</first_name>
18
+ <last_name>Smith</last_name>
19
+ </prospect>
20
+ <prospect>
21
+ <first_name>Sue</first_name>
22
+ <last_name>Green</last_name>
23
+ </prospect>
24
+ </result>
25
+ </rsp>)
26
+ end
27
+
28
+ it 'should take in some arguments' do
29
+ fake_get '/api/prospect/version/3/do/query?assigned=true&format=simple', sample_results
30
+
31
+ expect(client.prospects.query(assigned: true)).to eq({ 'total_results' => 2,
32
+ 'prospect' => [
33
+ { 'last_name' => 'Smith', 'first_name' => 'Jim' },
34
+ { 'last_name' => 'Green', 'first_name' => 'Sue' }
35
+ ] })
36
+ assert_authorization_header auth_manager
37
+ end
38
+ end
39
+
40
+ describe 'create' do
41
+ def sample_results
42
+ %(<?xml version="1.0" encoding="UTF-8"?>
43
+ <rsp stat="ok" version="1.0">
44
+ <prospect>
45
+ <first_name>Jim</first_name>
46
+ <last_name>Smith</last_name>
47
+ </prospect>
48
+ </rsp>)
49
+ end
50
+
51
+ it 'should return the prospect' do
52
+ fake_post '/api/prospect/version/3/do/create/email/user%40test.com?first_name=Jim&format=simple',
53
+ sample_results
55
54
 
56
- expect(@client.prospects.create("user@test.com", :first_name => "Jim")).to eq({"last_name"=>"Smith", "first_name"=>"Jim"})
57
- assert_authorization_header
55
+ expect(client.prospects.create('user@test.com',
56
+ first_name: 'Jim')).to eq({ 'last_name' => 'Smith', 'first_name' => 'Jim' })
57
+ assert_authorization_header auth_manager
58
+ end
59
+ end
58
60
  end
59
-
60
61
  end
61
-
62
62
  end
@@ -1,65 +1,62 @@
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::Objects::Users do
4
-
5
- before do
6
- @client = create_client
7
- end
8
-
9
- describe "query" do
10
-
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
- <user>
16
- <email>user@test.com</email>
17
- <first_name>Jim</first_name>
18
- </user>
19
- <user>
20
- <email>user@example.com</email>
21
- <first_name>Sue</first_name>
22
- </user>
23
- </result>
24
- </rsp>)
25
- end
26
-
27
- before do
28
- @client = create_client
29
- end
30
-
31
- it "should take in some arguments" do
32
- fake_get "/api/user/version/3/do/query?id_greater_than=200&format=simple", sample_results
33
-
34
- expect(@client.users.query(:id_greater_than => 200)).to eq({"total_results" => 2,
35
- "user"=>[
36
- {"email"=>"user@test.com", "first_name"=>"Jim"},
37
- {"email"=>"user@example.com", "first_name"=>"Sue"}
38
- ]})
39
- assert_authorization_header
40
- end
41
-
42
- end
43
-
44
- describe "read_by_email" do
45
-
46
- def sample_results
47
- %(<?xml version="1.0" encoding="UTF-8"?>
48
- <rsp stat="ok" version="1.0">
49
- <user>
50
- <email>user@example.com</email>
51
- <first_name>Sue</first_name>
52
- </user>
53
- </rsp>)
54
- end
55
-
56
- it "should return the prospect" do
57
- fake_post "/api/user/version/3/do/read/email/user@test.com?format=simple", sample_results
58
-
59
- expect(@client.users.read_by_email("user@test.com")).to eq({"email"=>"user@example.com", "first_name"=>"Sue"})
60
- 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
+ <user>
16
+ <email>user@test.com</email>
17
+ <first_name>Jim</first_name>
18
+ </user>
19
+ <user>
20
+ <email>user@example.com</email>
21
+ <first_name>Sue</first_name>
22
+ </user>
23
+ </result>
24
+ </rsp>)
25
+ end
26
+
27
+ it 'should take in some arguments' do
28
+ fake_get '/api/user/version/3/do/query?id_greater_than=200&format=simple', sample_results
29
+
30
+ expect(client.users.query(id_greater_than: 200)).to eq({ 'total_results' => 2,
31
+ 'user' => [
32
+ { 'email' => 'user@test.com',
33
+ 'first_name' => 'Jim' },
34
+ { 'email' => 'user@example.com',
35
+ 'first_name' => 'Sue' }
36
+ ] })
37
+ assert_authorization_header auth_manager
38
+ end
39
+ end
40
+
41
+ describe 'read_by_email' do
42
+ def sample_results
43
+ %(<?xml version="1.0" encoding="UTF-8"?>
44
+ <rsp stat="ok" version="1.0">
45
+ <user>
46
+ <email>user@example.com</email>
47
+ <first_name>Sue</first_name>
48
+ </user>
49
+ </rsp>)
50
+ end
51
+
52
+ it 'should return the prospect' do
53
+ fake_post '/api/user/version/3/do/read/email/user@test.com?format=simple', sample_results
54
+
55
+ expect(client.users.read_by_email('user@test.com')).to eq({ 'email' => 'user@example.com',
56
+ 'first_name' => 'Sue' })
57
+ assert_authorization_header auth_manager
58
+ end
59
+ end
61
60
  end
62
-
63
61
  end
64
-
65
- end
62
+ end