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,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 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_by_email email, params = {}
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 id, params = {}
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 path, params = {}, result = "user"
32
- response = @client.get "user", path, params
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 path, params = {}, result = "user"
37
- response = @client.post "user", path, params
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 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.2.0"
2
+ VERSION = '1.4.1'
3
3
  end
data/lib/ruby-pardot.rb CHANGED
@@ -6,6 +6,7 @@ require 'pardot/http'
6
6
  require 'pardot/error'
7
7
  require 'pardot/authentication'
8
8
 
9
+ require 'pardot/objects/custom_fields'
9
10
  require 'pardot/objects/emails'
10
11
  require 'pardot/objects/lists'
11
12
  require 'pardot/objects/list_memberships'
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", "Chris Little", "Justin Roberts"]
9
- s.email = ["support@pardot.com", "chris.little@salesforce.com", "justin.roberts@salesforce.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.13.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
- 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 =~ /^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'
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 "authenticate" do
10
-
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
23
- FakeWeb.last_request.body.should == 'email=user%40test.com&password=foo&user_key=bar'
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 "should return the api key" do
27
- authenticate.should == "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
- @client.api_key.should == "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
- @client.authenticated?.should == true
39
- verifyBody
68
+ expect(@client.authenticated?).to eq(true)
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
- @client.version.to_i.should == 3
45
- verifyBody
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 "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
64
- FakeWeb.last_request.body.should == 'email=user%40test.com&password=foo&user_key=bar'
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 "should return the api key" do
68
- authenticate.should == "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
- @client.api_key.should == "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
- @client.authenticated?.should == true
80
- verifyBody
115
+ expect(@client.authenticated?).to eq(true)
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
- @client.version.to_i.should == 4
86
- verifyBody
121
+ expect(@client.version.to_i).to eq(4)
122
+ verify_body
87
123
  end
88
-
89
124
  end
90
-
91
- end
125
+ end