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
@@ -1,65 +1,61 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Objects::VisitorActivities 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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
fake_post "/api/visitorActivity/version/3/do/read/id/10?format=simple", sample_results
|
58
|
-
|
59
|
-
expect(@client.visitor_activities.read(10)).to eq({"details"=>"More details", "type_name"=>"Write"})
|
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
|
+
<visitorActivity>
|
16
|
+
<type_name>Read</type_name>
|
17
|
+
<details>Some details</details>
|
18
|
+
</visitorActivity>
|
19
|
+
<visitorActivity>
|
20
|
+
<type_name>Write</type_name>
|
21
|
+
<details>More details</details>
|
22
|
+
</visitorActivity>
|
23
|
+
</result>
|
24
|
+
</rsp>)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should take in some arguments' do
|
28
|
+
fake_get '/api/visitorActivity/version/3/do/query?id_greater_than=200&format=simple', sample_results
|
29
|
+
|
30
|
+
expect(client.visitor_activities.query(id_greater_than: 200)).to eq({ 'total_results' => 2,
|
31
|
+
'visitorActivity' => [
|
32
|
+
{ 'type_name' => 'Read',
|
33
|
+
'details' => 'Some details' },
|
34
|
+
{ 'type_name' => 'Write',
|
35
|
+
'details' => 'More details' }
|
36
|
+
] })
|
37
|
+
assert_authorization_header auth_manager
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'read' do
|
42
|
+
def sample_results
|
43
|
+
%(<?xml version="1.0" encoding="UTF-8"?>
|
44
|
+
<rsp stat="ok" version="1.0">
|
45
|
+
<visitorActivity>
|
46
|
+
<type_name>Write</type_name>
|
47
|
+
<details>More details</details>
|
48
|
+
</visitorActivity>
|
49
|
+
</rsp>)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return the prospect' do
|
53
|
+
fake_post '/api/visitorActivity/version/3/do/read/id/10?format=simple', sample_results
|
54
|
+
|
55
|
+
expect(client.visitor_activities.read(10)).to eq({ 'details' => 'More details', 'type_name' => 'Write' })
|
56
|
+
assert_authorization_header auth_manager
|
57
|
+
end
|
58
|
+
end
|
61
59
|
end
|
62
|
-
|
63
60
|
end
|
64
|
-
|
65
|
-
end
|
61
|
+
end
|
@@ -1,65 +1,60 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Objects::Visitors 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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
it "should return the prospect" do
|
57
|
-
fake_post "/api/visitor/version/3/do/assign/id/10?type=Good&format=simple&name=Jim", sample_results
|
58
|
-
|
59
|
-
expect(@client.visitors.assign(10, :name => "Jim", :type => "Good")).to eq({"browser"=>"Chrome", "language"=>"es"})
|
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
|
+
describe 'query' do
|
10
|
+
def sample_results
|
11
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
|
12
|
+
<result>
|
13
|
+
<total_results>2</total_results>
|
14
|
+
<visitor>
|
15
|
+
<browser>Firefox</browser>
|
16
|
+
<language>en</language>
|
17
|
+
</visitor>
|
18
|
+
<visitor>
|
19
|
+
<browser>Chrome</browser>
|
20
|
+
<language>es</language>
|
21
|
+
</visitor>
|
22
|
+
</result>
|
23
|
+
</rsp>)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should take in some arguments' do
|
27
|
+
fake_get '/api/visitor/version/3/do/query?id_greater_than=200&format=simple', sample_results
|
28
|
+
|
29
|
+
expect(client.visitors.query(id_greater_than: 200)).to eq({ 'total_results' => 2,
|
30
|
+
'visitor' => [
|
31
|
+
{ 'browser' => 'Firefox',
|
32
|
+
'language' => 'en' },
|
33
|
+
{ 'browser' => 'Chrome', 'language' => 'es' }
|
34
|
+
] })
|
35
|
+
assert_authorization_header auth_manager
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'assign' do
|
40
|
+
def sample_results
|
41
|
+
%(<?xml version="1.0" encoding="UTF-8"?>
|
42
|
+
<rsp stat="ok" version="1.0">
|
43
|
+
<visitor>
|
44
|
+
<browser>Chrome</browser>
|
45
|
+
<language>es</language>
|
46
|
+
</visitor>
|
47
|
+
</rsp>)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return the prospect' do
|
51
|
+
fake_post '/api/visitor/version/3/do/assign/id/10?type=Good&format=simple&name=Jim', sample_results
|
52
|
+
|
53
|
+
expect(client.visitors.assign(10, name: 'Jim',
|
54
|
+
type: 'Good')).to eq({ 'browser' => 'Chrome', 'language' => 'es' })
|
55
|
+
assert_authorization_header auth_manager
|
56
|
+
end
|
57
|
+
end
|
61
58
|
end
|
62
|
-
|
63
59
|
end
|
64
|
-
|
65
|
-
end
|
60
|
+
end
|
@@ -1,65 +1,60 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Objects::Visits 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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
it "should return the prospect" do
|
57
|
-
fake_post "/api/visit/version/3/do/read/id/10?format=simple", sample_results
|
58
|
-
|
59
|
-
expect(@client.visits.read(10)).to eq({"visitor_page_view_count"=>"1", "duration_in_seconds"=>"10"})
|
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
|
+
describe 'query' do
|
10
|
+
def sample_results
|
11
|
+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
|
12
|
+
<result>
|
13
|
+
<total_results>2</total_results>
|
14
|
+
<visit>
|
15
|
+
<duration_in_seconds>50</duration_in_seconds>
|
16
|
+
<visitor_page_view_count>3</visitor_page_view_count>
|
17
|
+
</visit>
|
18
|
+
<visit>
|
19
|
+
<duration_in_seconds>10</duration_in_seconds>
|
20
|
+
<visitor_page_view_count>1</visitor_page_view_count>
|
21
|
+
</visit>
|
22
|
+
</result>
|
23
|
+
</rsp>)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should take in some arguments' do
|
27
|
+
fake_get '/api/visit/version/3/do/query?id_greater_than=200&format=simple', sample_results
|
28
|
+
|
29
|
+
expect(client.visits.query(id_greater_than: 200)).to eq({ 'total_results' => 2,
|
30
|
+
'visit' => [
|
31
|
+
{ 'duration_in_seconds' => '50',
|
32
|
+
'visitor_page_view_count' => '3' },
|
33
|
+
{ 'duration_in_seconds' => '10',
|
34
|
+
'visitor_page_view_count' => '1' }
|
35
|
+
] })
|
36
|
+
assert_authorization_header auth_manager
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'read' do
|
41
|
+
def sample_results
|
42
|
+
%(<?xml version="1.0" encoding="UTF-8"?>
|
43
|
+
<rsp stat="ok" version="1.0">
|
44
|
+
<visit>
|
45
|
+
<duration_in_seconds>10</duration_in_seconds>
|
46
|
+
<visitor_page_view_count>1</visitor_page_view_count>
|
47
|
+
</visit>
|
48
|
+
</rsp>)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return the prospect' do
|
52
|
+
fake_post '/api/visit/version/3/do/read/id/10?format=simple', sample_results
|
53
|
+
|
54
|
+
expect(client.visits.read(10)).to eq({ 'visitor_page_view_count' => '1', 'duration_in_seconds' => '10' })
|
55
|
+
assert_authorization_header auth_manager
|
56
|
+
end
|
57
|
+
end
|
61
58
|
end
|
62
|
-
|
63
59
|
end
|
64
|
-
|
65
|
-
end
|
60
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
def create_auth_managers
|
4
|
+
[UsernamePasswordAuthManager.new, SalesforceAccessTokenAuthManager.new]
|
5
|
+
end
|
6
|
+
|
7
|
+
class UsernamePasswordAuthManager
|
8
|
+
attr_accessor :test_name_suffix, :expected_authorization_header
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@test_name_suffix = 'With UsernamePassword Auth'
|
12
|
+
@expected_authorization_header = 'Pardot api_key=my_api_key, user_key=bar'
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_client
|
16
|
+
client = Pardot::Client.new 'user@test.com', 'foo', 'bar'
|
17
|
+
client.api_key = 'my_api_key'
|
18
|
+
client
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_business_unit_id_header?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class SalesforceAccessTokenAuthManager
|
27
|
+
attr_accessor :test_name_suffix, :expected_authorization_header, :expected_business_unit_id_header
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@test_name_suffix = 'With Salesforce OAuth'
|
31
|
+
@expected_authorization_header = 'Bearer access_token_value'
|
32
|
+
@expected_business_unit_id_header = '0Uv000000000001CAA'
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_client
|
36
|
+
Pardot::Client.new nil, nil, nil, 3, 'access_token_value', '0Uv000000000001CAA'
|
37
|
+
end
|
38
|
+
|
39
|
+
def has_business_unit_id_header?
|
40
|
+
false
|
41
|
+
end
|
6
42
|
end
|
data/spec/support/fakeweb.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fakeweb'
|
2
4
|
FakeWeb.allow_net_connect = false
|
3
5
|
|
4
|
-
def fake_post
|
5
|
-
FakeWeb.register_uri(:post, "https://pi.pardot.com#{path}", :
|
6
|
+
def fake_post(path, response)
|
7
|
+
FakeWeb.register_uri(:post, "https://pi.pardot.com#{path}", body: response)
|
6
8
|
end
|
7
9
|
|
8
|
-
def fake_get
|
9
|
-
FakeWeb.register_uri(:get, "https://pi.pardot.com#{path}", :
|
10
|
+
def fake_get(path, response)
|
11
|
+
FakeWeb.register_uri(:get, "https://pi.pardot.com#{path}", body: response)
|
10
12
|
end
|
11
13
|
|
12
|
-
def fake_authenticate
|
14
|
+
def fake_authenticate(client, api_key)
|
13
15
|
client.api_key = api_key
|
14
16
|
end
|
15
17
|
|
16
|
-
def assert_authorization_header
|
17
|
-
expect(FakeWeb.last_request[:authorization]).to eq(
|
18
|
-
|
18
|
+
def assert_authorization_header(auth_manager)
|
19
|
+
expect(FakeWeb.last_request[:authorization]).to eq(auth_manager.expected_authorization_header)
|
20
|
+
if auth_manager.has_business_unit_id_header?
|
21
|
+
expect(FakeWeb.last_request['Business-Unit-Id']).to eq(auth_manager.expected_business_unit_id_header)
|
22
|
+
end
|
23
|
+
end
|