ruby-pardot 1.2.0 → 1.4.1
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 +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/lib/pardot/objects/users.rb
CHANGED
@@ -1,45 +1,41 @@
|
|
1
1
|
module Pardot
|
2
2
|
module Objects
|
3
3
|
module Users
|
4
|
-
|
5
4
|
def users
|
6
5
|
@users ||= Users.new self
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
class Users
|
10
|
-
|
11
|
-
def initialize client
|
9
|
+
def initialize(client)
|
12
10
|
@client = client
|
13
11
|
end
|
14
|
-
|
15
|
-
def query
|
16
|
-
result = get
|
17
|
-
result[
|
12
|
+
|
13
|
+
def query(params)
|
14
|
+
result = get '/do/query', params, 'result'
|
15
|
+
result['total_results'] = result['total_results'].to_i if result['total_results']
|
18
16
|
result
|
19
17
|
end
|
20
|
-
|
21
|
-
def read_by_email
|
18
|
+
|
19
|
+
def read_by_email(email, params = {})
|
22
20
|
post "/do/read/email/#{email}", params
|
23
21
|
end
|
24
|
-
|
25
|
-
def read_by_id
|
22
|
+
|
23
|
+
def read_by_id(id, params = {})
|
26
24
|
post "/do/read/id/#{id}", params
|
27
25
|
end
|
28
|
-
|
26
|
+
|
29
27
|
protected
|
30
|
-
|
31
|
-
def get
|
32
|
-
response = @client.get
|
28
|
+
|
29
|
+
def get(path, params = {}, result = 'user')
|
30
|
+
response = @client.get 'user', path, params
|
33
31
|
result ? response[result] : response
|
34
32
|
end
|
35
|
-
|
36
|
-
def post
|
37
|
-
response = @client.post
|
33
|
+
|
34
|
+
def post(path, params = {}, result = 'user')
|
35
|
+
response = @client.post 'user', path, params
|
38
36
|
result ? response[result] : response
|
39
37
|
end
|
40
|
-
|
41
38
|
end
|
42
|
-
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
@@ -1,41 +1,37 @@
|
|
1
1
|
module Pardot
|
2
2
|
module Objects
|
3
3
|
module VisitorActivities
|
4
|
-
|
5
4
|
def visitor_activities
|
6
5
|
@visitor_activities ||= VisitorActivities.new self
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
class VisitorActivities
|
10
|
-
|
11
|
-
def initialize client
|
9
|
+
def initialize(client)
|
12
10
|
@client = client
|
13
11
|
end
|
14
|
-
|
15
|
-
def query
|
16
|
-
result = get
|
17
|
-
result[
|
12
|
+
|
13
|
+
def query(params)
|
14
|
+
result = get '/do/query', params, 'result'
|
15
|
+
result['total_results'] = result['total_results'].to_i if result['total_results']
|
18
16
|
result
|
19
17
|
end
|
20
|
-
|
21
|
-
def read
|
18
|
+
|
19
|
+
def read(id, params = {})
|
22
20
|
post "/do/read/id/#{id}", params
|
23
21
|
end
|
24
|
-
|
22
|
+
|
25
23
|
protected
|
26
|
-
|
27
|
-
def get
|
28
|
-
response = @client.get
|
24
|
+
|
25
|
+
def get(path, params = {}, result = 'visitorActivity')
|
26
|
+
response = @client.get 'visitorActivity', path, params
|
29
27
|
result ? response[result] : response
|
30
28
|
end
|
31
|
-
|
32
|
-
def post
|
33
|
-
response = @client.post
|
29
|
+
|
30
|
+
def post(path, params = {}, result = 'visitorActivity')
|
31
|
+
response = @client.post 'visitorActivity', path, params
|
34
32
|
result ? response[result] : response
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
38
|
-
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|
@@ -1,45 +1,41 @@
|
|
1
1
|
module Pardot
|
2
2
|
module Objects
|
3
3
|
module Visitors
|
4
|
-
|
5
4
|
def visitors
|
6
5
|
@visitors ||= Visitors.new self
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
class Visitors
|
10
|
-
|
11
|
-
def initialize client
|
9
|
+
def initialize(client)
|
12
10
|
@client = client
|
13
11
|
end
|
14
|
-
|
15
|
-
def query
|
16
|
-
result = get
|
17
|
-
result[
|
12
|
+
|
13
|
+
def query(params)
|
14
|
+
result = get '/do/query', params, 'result'
|
15
|
+
result['total_results'] = result['total_results'].to_i if result['total_results']
|
18
16
|
result
|
19
17
|
end
|
20
|
-
|
21
|
-
def assign
|
18
|
+
|
19
|
+
def assign(id, params = {})
|
22
20
|
post "/do/assign/id/#{id}", params
|
23
21
|
end
|
24
|
-
|
25
|
-
def read
|
22
|
+
|
23
|
+
def read(id, params = {})
|
26
24
|
post "/do/read/id/#{id}", params
|
27
25
|
end
|
28
|
-
|
26
|
+
|
29
27
|
protected
|
30
|
-
|
31
|
-
def get
|
32
|
-
response = @client.get
|
28
|
+
|
29
|
+
def get(path, params = {}, result = 'visitor')
|
30
|
+
response = @client.get 'visitor', path, params
|
33
31
|
result ? response[result] : response
|
34
32
|
end
|
35
|
-
|
36
|
-
def post
|
37
|
-
response = @client.post
|
33
|
+
|
34
|
+
def post(path, params = {}, result = 'visitor')
|
35
|
+
response = @client.post 'visitor', path, params
|
38
36
|
result ? response[result] : response
|
39
37
|
end
|
40
|
-
|
41
38
|
end
|
42
|
-
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
@@ -1,41 +1,37 @@
|
|
1
1
|
module Pardot
|
2
2
|
module Objects
|
3
3
|
module Visits
|
4
|
-
|
5
4
|
def visits
|
6
5
|
@visits ||= Visits.new self
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
class Visits
|
10
|
-
|
11
|
-
def initialize client
|
9
|
+
def initialize(client)
|
12
10
|
@client = client
|
13
11
|
end
|
14
|
-
|
15
|
-
def query
|
16
|
-
result = get
|
17
|
-
result[
|
12
|
+
|
13
|
+
def query(params)
|
14
|
+
result = get '/do/query', params, 'result'
|
15
|
+
result['total_results'] = result['total_results'].to_i if result['total_results']
|
18
16
|
result
|
19
17
|
end
|
20
|
-
|
21
|
-
def read
|
18
|
+
|
19
|
+
def read(id, params = {})
|
22
20
|
post "/do/read/id/#{id}", params
|
23
21
|
end
|
24
|
-
|
22
|
+
|
25
23
|
protected
|
26
|
-
|
27
|
-
def get
|
28
|
-
response = @client.get
|
24
|
+
|
25
|
+
def get(path, params = {}, result = 'visit')
|
26
|
+
response = @client.get 'visit', path, params
|
29
27
|
result ? response[result] : response
|
30
28
|
end
|
31
|
-
|
32
|
-
def post
|
33
|
-
response = @client.post
|
29
|
+
|
30
|
+
def post(path, params = {}, result = 'visit')
|
31
|
+
response = @client.post 'visit', path, params
|
34
32
|
result ? response[result] : response
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
38
|
-
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|
data/lib/pardot/version.rb
CHANGED
data/lib/ruby-pardot.rb
CHANGED
data/ruby-pardot.gemspec
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/pardot/version', __dir__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
6
|
+
s.name = 'ruby-pardot'
|
6
7
|
s.version = Pardot::VERSION
|
7
8
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
9
|
+
s.authors = ['Dan Cunning']
|
10
|
+
s.email = ['support@pardot.com']
|
11
|
+
s.homepage = 'http://github.com/pardot/ruby-pardot'
|
12
|
+
s.summary = 'Library for interacting with the Pardot API'
|
13
|
+
s.description = 'Library for interacting with the Pardot API'
|
13
14
|
|
15
|
+
s.required_ruby_version = '>= 2.6'
|
14
16
|
s.required_rubygems_version = ">= 1.3.6"
|
15
17
|
s.rubyforge_project = "ruby-pardot"
|
16
18
|
|
17
|
-
s.add_dependency
|
18
|
-
s.add_dependency
|
19
|
+
s.add_dependency 'crack', '0.4.3'
|
20
|
+
s.add_dependency 'httparty', '0.18.1'
|
19
21
|
|
20
22
|
s.add_development_dependency "bundler", ">= 1.10"
|
21
|
-
s.add_development_dependency "rspec"
|
22
|
-
s.add_development_dependency "fakeweb"
|
23
|
+
s.add_development_dependency "rspec", "3.5.0"
|
24
|
+
s.add_development_dependency "fakeweb", "1.3.0"
|
23
25
|
|
24
26
|
s.files = `git ls-files`.split("\n")
|
25
|
-
s.executables = `git ls-files`.split("\n").map{|f| f =~
|
27
|
+
s.executables = `git ls-files`.split("\n").map { |f| f =~ %r{^bin/(.*)} ? Regexp.last_match(1) : nil }.compact
|
26
28
|
s.require_path = 'lib'
|
27
29
|
end
|
@@ -1,91 +1,125 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
4
|
|
3
5
|
describe Pardot::Authentication do
|
4
|
-
|
5
6
|
def create_client
|
6
|
-
@client = Pardot::Client.new
|
7
|
+
@client = Pardot::Client.new 'user@test.com', 'foo', 'bar'
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_client_using_salesforce_access_token
|
11
|
+
@client = Pardot::Client.new nil, nil, nil, 3, 'access_token_value', '0Uv000000000001CAA'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'authenticate with Salesforce access_token' do
|
15
|
+
before do
|
16
|
+
@client = create_client_using_salesforce_access_token
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises error when calling authenticate' do
|
20
|
+
expect do
|
21
|
+
@client.authenticate
|
22
|
+
end.to raise_error.with_message(/Authentication not available when using Salesforce access token/)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raises error when calling reauthenticate' do
|
26
|
+
expect do
|
27
|
+
@client.reauthenticate
|
28
|
+
end.to raise_error.with_message(/Reauthentication not available when using Salesforce access token/)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns true for authenticated' do
|
32
|
+
expect(@client.authenticated?).to eq(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns true for using_salesforce_access_token' do
|
36
|
+
expect(@client.using_salesforce_access_token?).to eq(true)
|
37
|
+
end
|
7
38
|
end
|
8
|
-
|
9
|
-
describe
|
10
|
-
|
39
|
+
|
40
|
+
describe 'authenticate' do
|
11
41
|
before do
|
12
42
|
@client = create_client
|
13
|
-
|
14
|
-
fake_post
|
43
|
+
|
44
|
+
fake_post '/api/login/version/3',
|
15
45
|
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">\n <api_key>my_api_key</api_key>\n</rsp>\n)
|
16
46
|
end
|
17
|
-
|
47
|
+
|
18
48
|
def authenticate
|
19
49
|
@client.authenticate
|
20
50
|
end
|
21
51
|
|
22
|
-
def
|
23
|
-
FakeWeb.last_request.body.
|
52
|
+
def verify_body
|
53
|
+
expect(FakeWeb.last_request.body).to eq('email=user%40test.com&password=foo&user_key=bar')
|
24
54
|
end
|
25
|
-
|
26
|
-
it
|
27
|
-
authenticate.
|
55
|
+
|
56
|
+
it 'should return the api key' do
|
57
|
+
expect(authenticate).to eq('my_api_key')
|
28
58
|
end
|
29
|
-
|
30
|
-
it
|
59
|
+
|
60
|
+
it 'should set the api key' do
|
31
61
|
authenticate
|
32
|
-
@client.api_key.
|
33
|
-
|
62
|
+
expect(@client.api_key).to eq('my_api_key')
|
63
|
+
verify_body
|
34
64
|
end
|
35
|
-
|
36
|
-
it
|
65
|
+
|
66
|
+
it 'should make authenticated? true' do
|
37
67
|
authenticate
|
38
|
-
@client.authenticated
|
39
|
-
|
68
|
+
expect(@client.authenticated?).to eq(true)
|
69
|
+
verify_body
|
40
70
|
end
|
41
71
|
|
42
|
-
it
|
72
|
+
it 'should use version 3' do
|
43
73
|
authenticate
|
44
|
-
@client.version.to_i.
|
45
|
-
|
74
|
+
expect(@client.version.to_i).to eq(3)
|
75
|
+
verify_body
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns false for using_salesforce_access_token' do
|
79
|
+
expect(@client.using_salesforce_access_token?).to eq(false)
|
80
|
+
|
81
|
+
authenticate
|
82
|
+
expect(@client.using_salesforce_access_token?).to eq(false)
|
83
|
+
verify_body
|
46
84
|
end
|
47
|
-
|
48
85
|
end
|
49
86
|
|
50
|
-
describe
|
51
|
-
|
87
|
+
describe 'authenticateV4' do
|
52
88
|
before do
|
53
89
|
@client = create_client
|
54
|
-
|
55
|
-
fake_post
|
90
|
+
|
91
|
+
fake_post '/api/login/version/3',
|
56
92
|
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">\n <api_key>my_api_key</api_key>\n<version>4</version>\n</rsp>\n)
|
57
93
|
end
|
58
|
-
|
94
|
+
|
59
95
|
def authenticate
|
60
96
|
@client.authenticate
|
61
97
|
end
|
62
98
|
|
63
|
-
def
|
64
|
-
FakeWeb.last_request.body.
|
99
|
+
def verify_body
|
100
|
+
expect(FakeWeb.last_request.body).to eq('email=user%40test.com&password=foo&user_key=bar')
|
65
101
|
end
|
66
|
-
|
67
|
-
it
|
68
|
-
authenticate.
|
102
|
+
|
103
|
+
it 'should return the api key' do
|
104
|
+
expect(authenticate).to eq('my_api_key')
|
69
105
|
end
|
70
|
-
|
71
|
-
it
|
106
|
+
|
107
|
+
it 'should set the api key' do
|
72
108
|
authenticate
|
73
|
-
@client.api_key.
|
74
|
-
|
109
|
+
expect(@client.api_key).to eq('my_api_key')
|
110
|
+
verify_body
|
75
111
|
end
|
76
|
-
|
77
|
-
it
|
112
|
+
|
113
|
+
it 'should make authenticated? true' do
|
78
114
|
authenticate
|
79
|
-
@client.authenticated
|
80
|
-
|
115
|
+
expect(@client.authenticated?).to eq(true)
|
116
|
+
verify_body
|
81
117
|
end
|
82
118
|
|
83
|
-
it
|
119
|
+
it 'should use version 4' do
|
84
120
|
authenticate
|
85
|
-
@client.version.to_i.
|
86
|
-
|
121
|
+
expect(@client.version.to_i).to eq(4)
|
122
|
+
verify_body
|
87
123
|
end
|
88
|
-
|
89
124
|
end
|
90
|
-
|
91
|
-
end
|
125
|
+
end
|