ruby-pardot 1.1.0 → 1.4.0

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 +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +9 -0
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +29 -22
  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 +88 -40
  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 +23 -21
@@ -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.1.0"
2
+ VERSION = '1.4.0'
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"]
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"
18
- s.add_dependency "httparty"
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,77 +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?email=user%40test.com&password=foo&user_key=bar",
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
-
22
- it "should return the api key" do
23
- authenticate.should == "my_api_key"
51
+
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 set the api key" do
55
+
56
+ it 'should return the api key' do
57
+ expect(authenticate).to eq('my_api_key')
58
+ end
59
+
60
+ it 'should set the api key' do
27
61
  authenticate
28
- @client.api_key.should == "my_api_key"
62
+ expect(@client.api_key).to eq('my_api_key')
63
+ verify_body
29
64
  end
30
-
31
- it "should make authenticated? true" do
65
+
66
+ it 'should make authenticated? true' do
32
67
  authenticate
33
- @client.authenticated?.should == true
68
+ expect(@client.authenticated?).to eq(true)
69
+ verify_body
34
70
  end
35
71
 
36
- it "should use version 3" do
72
+ it 'should use version 3' do
37
73
  authenticate
38
- @client.version.to_i.should == 3
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
39
84
  end
40
-
41
85
  end
42
86
 
43
- describe "authenticateV4" do
44
-
87
+ describe 'authenticateV4' do
45
88
  before do
46
89
  @client = create_client
47
-
48
- fake_post "/api/login/version/3?email=user%40test.com&password=foo&user_key=bar",
90
+
91
+ fake_post '/api/login/version/3',
49
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)
50
93
  end
51
-
94
+
52
95
  def authenticate
53
96
  @client.authenticate
54
97
  end
55
-
56
- it "should return the api key" do
57
- authenticate.should == "my_api_key"
98
+
99
+ def verify_body
100
+ expect(FakeWeb.last_request.body).to eq('email=user%40test.com&password=foo&user_key=bar')
101
+ end
102
+
103
+ it 'should return the api key' do
104
+ expect(authenticate).to eq('my_api_key')
58
105
  end
59
-
60
- it "should set the api key" do
106
+
107
+ it 'should set the api key' do
61
108
  authenticate
62
- @client.api_key.should == "my_api_key"
109
+ expect(@client.api_key).to eq('my_api_key')
110
+ verify_body
63
111
  end
64
-
65
- it "should make authenticated? true" do
112
+
113
+ it 'should make authenticated? true' do
66
114
  authenticate
67
- @client.authenticated?.should == true
115
+ expect(@client.authenticated?).to eq(true)
116
+ verify_body
68
117
  end
69
118
 
70
- it "should use version 4" do
119
+ it 'should use version 4' do
71
120
  authenticate
72
- @client.version.to_i.should == 4
121
+ expect(@client.version.to_i).to eq(4)
122
+ verify_body
73
123
  end
74
-
75
124
  end
76
-
77
- end
125
+ end