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,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 params
16
- result = get "/do/query", params, "result"
17
- result["total_results"] = result["total_results"].to_i if result["total_results"]
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 id, params = {}
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 path, params = {}, result = "visitorActivity"
28
- response = @client.get "visitorActivity", path, params
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 path, params = {}, result = "visitorActivity"
33
- response = @client.post "visitorActivity", path, params
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 params
16
- result = get "/do/query", params, "result"
17
- result["total_results"] = result["total_results"].to_i if result["total_results"]
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 id, params = {}
18
+
19
+ def assign(id, params = {})
22
20
  post "/do/assign/id/#{id}", params
23
21
  end
24
-
25
- def read id, params = {}
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 path, params = {}, result = "visitor"
32
- response = @client.get "visitor", path, params
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 path, params = {}, result = "visitor"
37
- response = @client.post "visitor", path, params
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 params
16
- result = get "/do/query", params, "result"
17
- result["total_results"] = result["total_results"].to_i if result["total_results"]
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 id, params = {}
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 path, params = {}, result = "visit"
28
- response = @client.get "visit", path, params
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 path, params = {}, result = "visit"
33
- response = @client.post "visit", path, params
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
@@ -1,3 +1,3 @@
1
1
  module Pardot
2
- VERSION = "1.3.2"
2
+ VERSION = '1.4.0'
3
3
  end
data/ruby-pardot.gemspec CHANGED
@@ -1,27 +1,29 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/pardot/version", __FILE__)
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 = "ruby-pardot"
6
+ s.name = 'ruby-pardot'
6
7
  s.version = Pardot::VERSION
7
8
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Dan Cunning"]
9
- s.email = ["support@pardot.com"]
10
- s.homepage = "http://github.com/pardot/ruby-pardot"
11
- s.summary = "Library for interacting with the Pardot API"
12
- s.description = "Library for interacting with the Pardot API"
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 "crack", "0.4.3"
18
- s.add_dependency "httparty", "0.18.1"
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
23
  s.add_development_dependency "rspec", "3.5.0"
22
- s.add_development_dependency "fakeweb"
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 =~ /^bin\/(.*)/ ? $1 : nil}.compact
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
- 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::Authentication 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'
8
+ end
9
+
10
+ def create_client_using_salesforce_access_token
11
+ @client = Pardot::Client.new nil, nil, nil, 3, 'access_token_value', '0Uv000000000001CAA'
7
12
  end
8
-
9
- describe "authenticate" do
10
-
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
38
+ end
39
+
40
+ describe 'authenticate' do
11
41
  before do
12
42
  @client = create_client
13
-
14
- fake_post "/api/login/version/3",
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 verifyBody
52
+ def verify_body
23
53
  expect(FakeWeb.last_request.body).to eq('email=user%40test.com&password=foo&user_key=bar')
24
54
  end
25
-
26
- it "should return the api key" do
27
- expect(authenticate).to eq("my_api_key")
55
+
56
+ it 'should return the api key' do
57
+ expect(authenticate).to eq('my_api_key')
28
58
  end
29
-
30
- it "should set the api key" do
59
+
60
+ it 'should set the api key' do
31
61
  authenticate
32
- expect(@client.api_key).to eq("my_api_key")
33
- verifyBody
62
+ expect(@client.api_key).to eq('my_api_key')
63
+ verify_body
34
64
  end
35
-
36
- it "should make authenticated? true" do
65
+
66
+ it 'should make authenticated? true' do
37
67
  authenticate
38
68
  expect(@client.authenticated?).to eq(true)
39
- verifyBody
69
+ verify_body
40
70
  end
41
71
 
42
- it "should use version 3" do
72
+ it 'should use version 3' do
43
73
  authenticate
44
74
  expect(@client.version.to_i).to eq(3)
45
- verifyBody
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 "authenticateV4" do
51
-
87
+ describe 'authenticateV4' do
52
88
  before do
53
89
  @client = create_client
54
-
55
- fake_post "/api/login/version/3",
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 verifyBody
99
+ def verify_body
64
100
  expect(FakeWeb.last_request.body).to eq('email=user%40test.com&password=foo&user_key=bar')
65
101
  end
66
-
67
- it "should return the api key" do
68
- expect(authenticate).to eq("my_api_key")
102
+
103
+ it 'should return the api key' do
104
+ expect(authenticate).to eq('my_api_key')
69
105
  end
70
-
71
- it "should set the api key" do
106
+
107
+ it 'should set the api key' do
72
108
  authenticate
73
- expect(@client.api_key).to eq("my_api_key")
74
- verifyBody
109
+ expect(@client.api_key).to eq('my_api_key')
110
+ verify_body
75
111
  end
76
-
77
- it "should make authenticated? true" do
112
+
113
+ it 'should make authenticated? true' do
78
114
  authenticate
79
115
  expect(@client.authenticated?).to eq(true)
80
- verifyBody
116
+ verify_body
81
117
  end
82
118
 
83
- it "should use version 4" do
119
+ it 'should use version 4' do
84
120
  authenticate
85
121
  expect(@client.version.to_i).to eq(4)
86
- verifyBody
122
+ verify_body
87
123
  end
88
-
89
124
  end
90
-
91
- end
125
+ end
@@ -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'
8
+ end
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')
21
+ end
22
+
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/)
28
+ end
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./)
35
+ end
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
7
43
  end
8
-
9
- describe "client" do
44
+
45
+ describe 'client' do
10
46
  after do
11
- expect(@client.email).to eq("user@test.com")
12
- expect(@client.password).to eq("password")
13
- expect(@client.user_key).to eq("user_key")
14
- expect(@client.format).to eq("simple")
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')
15
51
  end
16
52
 
17
- it "should set variables without version" do
18
- @client = Pardot::Client.new "user@test.com", "password", "user_key"
53
+ it 'should set variables without version' do
54
+ @client = Pardot::Client.new 'user@test.com', 'password', 'user_key'
19
55
  expect(@client.version).to eq(3)
20
56
  end
21
-
22
- it "should set variables with version" do
23
- @client = Pardot::Client.new "user@test.com", "password", "user_key", 4
57
+
58
+ it 'should set variables with version' do
59
+ @client = Pardot::Client.new 'user@test.com', 'password', 'user_key', 4
24
60
  expect(@client.version).to eq(4)
25
61
  end
26
-
27
62
  end
28
63
  end