ruby-pardot 1.3.2 → 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 (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,44 +1,39 @@
1
1
  module Pardot
2
2
  module Objects
3
-
4
3
  module Emails
5
-
6
4
  def emails
7
5
  @emails ||= Emails.new self
8
6
  end
9
7
 
10
8
  class Emails
11
-
12
- def initialize client
9
+ def initialize(client)
13
10
  @client = client
14
11
  end
15
12
 
16
- def read_by_id id
13
+ def read_by_id(id)
17
14
  get "/do/read/id/#{id}"
18
15
  end
19
16
 
20
- def send_to_prospect prospect_id, params
17
+ def send_to_prospect(prospect_id, params)
21
18
  post "/do/send/prospect_id/#{prospect_id}", params
22
19
  end
23
20
 
24
- def send_to_list params
25
- post "/do/send", params
21
+ def send_to_list(params)
22
+ post '/do/send', params
26
23
  end
27
24
 
28
25
  protected
29
26
 
30
- def get path, params = {}, result = "email"
31
- response = @client.get "email", path, params
27
+ def get(path, params = {}, result = 'email')
28
+ response = @client.get 'email', path, params
32
29
  result ? response[result] : response
33
30
  end
34
31
 
35
- def post path, params = {}, result = "email"
36
- response = @client.post "email", path, params
32
+ def post(path, params = {}, result = 'email')
33
+ response = @client.post 'email', path, params
37
34
  result ? response[result] : response
38
35
  end
39
-
40
36
  end
41
-
42
37
  end
43
38
  end
44
39
  end
@@ -1,36 +1,32 @@
1
1
  module Pardot
2
2
  module Objects
3
3
  module ListMemberships
4
-
5
4
  def list_memberships
6
5
  @list_memberships ||= ListMemberships.new self
7
6
  end
8
7
 
9
8
  class ListMemberships
10
-
11
- def initialize client
9
+ def initialize(client)
12
10
  @client = client
13
11
  end
14
12
 
15
- def query params
16
- result = get "/do/query", params, "result"
17
- result["total_results"] = result["total_results"].to_i if result["total_results"]
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
18
 
21
- def read_by_id id, params = {}
19
+ def read_by_id(id, params = {})
22
20
  get "/do/read/id/#{id}", params
23
21
  end
24
22
 
25
23
  protected
26
24
 
27
- def get path, params = {}, result = "listMembership"
28
- response = @client.get "listMembership", path, params
25
+ def get(path, params = {}, result = 'listMembership')
26
+ response = @client.get 'listMembership', path, params
29
27
  result ? response[result] : response
30
28
  end
31
-
32
29
  end
33
-
34
30
  end
35
31
  end
36
- end
32
+ end
@@ -1,50 +1,45 @@
1
1
  module Pardot
2
2
  module Objects
3
-
4
3
  module Lists
5
-
6
4
  def lists
7
5
  @lists ||= Lists.new self
8
6
  end
9
-
7
+
10
8
  class Lists
11
-
12
- def initialize client
9
+ def initialize(client)
13
10
  @client = client
14
11
  end
15
-
16
- def create id, params = {}
17
- post "/do/create", params
12
+
13
+ def create(_id, params = {})
14
+ post '/do/create', params
18
15
  end
19
-
20
- def query params
21
- result = get "/do/query", params, "result"
22
- result["total_results"] = result["total_results"].to_i if result["total_results"]
16
+
17
+ def query(params)
18
+ result = get '/do/query', params, 'result'
19
+ result['total_results'] = result['total_results'].to_i if result['total_results']
23
20
  result
24
21
  end
25
-
26
- def read_by_id id, params = {}
22
+
23
+ def read_by_id(id, params = {})
27
24
  get "/do/read/id/#{id}", params
28
25
  end
29
-
30
- def update id, params = {}
26
+
27
+ def update(id, _params = {})
31
28
  post "/do/update/#{id}"
32
29
  end
33
-
30
+
34
31
  protected
35
-
36
- def get path, params = {}, result = "list"
37
- response = @client.get "list", path, params
32
+
33
+ def get(path, params = {}, result = 'list')
34
+ response = @client.get 'list', path, params
38
35
  result ? response[result] : response
39
36
  end
40
-
41
- def post path, params = {}, result = "list"
42
- response = @client.post "list", path, params
37
+
38
+ def post(path, params = {}, result = 'list')
39
+ response = @client.post 'list', path, params
43
40
  result ? response[result] : response
44
41
  end
45
-
46
42
  end
47
-
48
43
  end
49
44
  end
50
45
  end
@@ -1,54 +1,49 @@
1
1
  module Pardot
2
2
  module Objects
3
-
4
3
  module Opportunities
5
-
6
4
  def opportunities
7
5
  @opportunities ||= Opportunities.new self
8
6
  end
9
-
7
+
10
8
  class Opportunities
11
-
12
- def initialize client
9
+ def initialize(client)
13
10
  @client = client
14
11
  end
15
-
16
- def query params
17
- result = get "/do/query", params, "result"
18
- 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']
19
16
  result
20
17
  end
21
-
22
- def create_by_email email, params = {}
18
+
19
+ def create_by_email(email, params = {})
23
20
  post "/do/create/prospect_email/#{email}", params
24
21
  end
25
-
26
- def create_by_id prospect_id, params = {}
22
+
23
+ def create_by_id(prospect_id, params = {})
27
24
  post "/do/create/prospect_id/#{prospect_id}", params
28
25
  end
29
-
30
- def read_by_id id, params = {}
26
+
27
+ def read_by_id(id, params = {})
31
28
  post "/do/read/id/#{id}", params
32
29
  end
33
-
34
- def update_by_id id, params = {}
30
+
31
+ def update_by_id(id, params = {})
35
32
  post "/do/update/id/#{id}", params
36
33
  end
37
-
34
+
38
35
  protected
39
-
40
- def get path, params = {}, result = "opportunity"
41
- response = @client.get "opportunity", path, params
36
+
37
+ def get(path, params = {}, result = 'opportunity')
38
+ response = @client.get 'opportunity', path, params
42
39
  result ? response[result] : response
43
40
  end
44
-
45
- def post path, params = {}, result = "opportunity"
46
- response = @client.post "opportunity", path, params
41
+
42
+ def post(path, params = {}, result = 'opportunity')
43
+ response = @client.post 'opportunity', path, params
47
44
  result ? response[result] : response
48
45
  end
49
-
50
46
  end
51
-
52
47
  end
53
48
  end
54
49
  end
@@ -6,7 +6,6 @@ module Pardot
6
6
  end
7
7
 
8
8
  class ProspectAccounts
9
-
10
9
  def initialize(client)
11
10
  @client = client
12
11
  end
@@ -18,18 +17,18 @@ module Pardot
18
17
  result
19
18
  end
20
19
 
21
- def describe(params={})
20
+ def describe(params = {})
22
21
  post('/do/describe', params)
23
22
  end
24
23
 
25
- def create(params={})
24
+ def create(params = {})
26
25
  post('/do/create', params)
27
26
  end
28
27
 
29
28
  # read_by_id
30
29
  # update_by_id
31
- [:read, :update].each do |verb|
32
- define_method(verb) do |id, params={}|
30
+ %i[read update].each do |verb|
31
+ define_method(verb) do |id, params = {}|
33
32
  post(api_url(verb, 'id', id), params)
34
33
  end
35
34
  end
@@ -40,12 +39,12 @@ module Pardot
40
39
  "/do/#{verb}/#{direct_to}/#{value}"
41
40
  end
42
41
 
43
- def get(path, params={}, result='prospectAccount')
42
+ def get(path, params = {}, result = 'prospectAccount')
44
43
  response = @client.get('prospectAccount', path, params)
45
44
  result ? response[result] : response
46
45
  end
47
46
 
48
- def post(path, params={}, result='prospectAccount')
47
+ def post(path, params = {}, result = 'prospectAccount')
49
48
  response = @client.post('prospectAccount', path, params)
50
49
  result ? response[result] : response
51
50
  end
@@ -3,109 +3,105 @@ require 'cgi'
3
3
  module Pardot
4
4
  module Objects
5
5
  module Prospects
6
-
7
6
  def prospects
8
7
  @prospects ||= Prospects.new self
9
8
  end
10
9
 
11
10
  class Prospects
12
-
13
- def initialize client
11
+ def initialize(client)
14
12
  @client = client
15
13
  end
16
14
 
17
- def query search_criteria
18
- result = get "/do/query", search_criteria, "result"
19
- result["total_results"] = result["total_results"].to_i if result["total_results"]
15
+ def query(search_criteria)
16
+ result = get '/do/query', search_criteria, 'result'
17
+ result['total_results'] = result['total_results'].to_i if result['total_results']
20
18
  result
21
19
  end
22
20
 
23
- def assign_by_email email, params
21
+ def assign_by_email(email, params)
24
22
  post "/do/assign/email/#{CGI.escape(email)}", params
25
23
  end
26
24
 
27
- def assign_by_id id, params
25
+ def assign_by_id(id, params)
28
26
  post "/do/assign/id/#{CGI.escape(id)}", params
29
27
  end
30
28
 
31
- def assign_by_fid fid, params
29
+ def assign_by_fid(fid, params)
32
30
  post "/do/assign/fid/#{CGI.escape(fid)}", params
33
31
  end
34
32
 
35
- def create email, params = {}
33
+ def create(email, params = {})
36
34
  post "/do/create/email/#{CGI.escape(email)}", params
37
35
  end
38
36
 
39
- def delete_by_id id, params = {}
37
+ def delete_by_id(id, params = {})
40
38
  post "/do/delete/id/#{CGI.escape(id)}", params
41
39
  end
42
40
 
43
- def delete_by_fid fid, params = {}
41
+ def delete_by_fid(fid, params = {})
44
42
  post "/do/delete/fid/#{CGI.escape(fid)}", params
45
43
  end
46
44
 
47
- def read_by_email email, params = {}
45
+ def read_by_email(email, params = {})
48
46
  post "/do/read/email/#{CGI.escape(email)}", params
49
47
  end
50
48
 
51
- def read_by_id id, params = {}
49
+ def read_by_id(id, params = {})
52
50
  post "/do/read/id/#{CGI.escape(id)}", params
53
51
  end
54
52
 
55
- def read_by_fid fid, params = {}
53
+ def read_by_fid(fid, params = {})
56
54
  post "/do/read/fid/#{CGI.escape(fid)}", params
57
55
  end
58
56
 
59
- def unassign_by_email email, params = {}
57
+ def unassign_by_email(email, params = {})
60
58
  post "/do/unassign/email/#{CGI.escape(email)}", params
61
59
  end
62
60
 
63
- def unassign_by_id id, params = {}
61
+ def unassign_by_id(id, params = {})
64
62
  post "/do/unassign/id/#{CGI.escape(id)}", params
65
63
  end
66
64
 
67
- def unassign_by_fid fid, params = {}
65
+ def unassign_by_fid(fid, params = {})
68
66
  post "/do/unassign/fid/#{CGI.escape(fid)}", params
69
67
  end
70
68
 
71
- def update_by_email email, params = {}
69
+ def update_by_email(email, params = {})
72
70
  post "/do/update/email/#{CGI.escape(email)}", params
73
71
  end
74
72
 
75
- def update_by_id id, params = {}
73
+ def update_by_id(id, params = {})
76
74
  post "/do/update/id/#{CGI.escape(id)}", params
77
75
  end
78
76
 
79
- def update_by_fid fid, params = {}
77
+ def update_by_fid(fid, params = {})
80
78
  post "/do/update/fid/#{CGI.escape(fid)}", params
81
79
  end
82
80
 
83
- def upsert_by_email email, params = {}
81
+ def upsert_by_email(email, params = {})
84
82
  post "/do/upsert/email/#{CGI.escape(email)}", params
85
83
  end
86
84
 
87
- def upsert_by_id id, params = {}
85
+ def upsert_by_id(id, params = {})
88
86
  post "/do/upsert/id/#{CGI.escape(id)}", params
89
87
  end
90
88
 
91
- def upsert_by_fid fid, params = {}
89
+ def upsert_by_fid(fid, params = {})
92
90
  post "/do/upsert/fid/#{CGI.escape(fid)}", params
93
91
  end
94
92
 
95
93
  protected
96
94
 
97
- def get path, params = {}, result = "prospect"
98
- response = @client.get "prospect", path, params
95
+ def get(path, params = {}, result = 'prospect')
96
+ response = @client.get 'prospect', path, params
99
97
  result ? response[result] : response
100
98
  end
101
99
 
102
- def post path, params = {}, result = "prospect"
103
- response = @client.post "prospect", path, params
100
+ def post(path, params = {}, result = 'prospect')
101
+ response = @client.post 'prospect', path, params
104
102
  result ? response[result] : response
105
103
  end
106
-
107
104
  end
108
-
109
105
  end
110
106
  end
111
107
  end
@@ -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