ruby-pardot 1.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.
- data/.gitignore +3 -0
- data/.rspec +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +32 -0
- data/README.rdoc +82 -0
- data/Rakefile +11 -0
- data/lib/pardot/authentication.rb +19 -0
- data/lib/pardot/client.rb +32 -0
- data/lib/pardot/error.rb +8 -0
- data/lib/pardot/http.rb +69 -0
- data/lib/pardot/objects/lists.rb +50 -0
- data/lib/pardot/objects/opportunities.rb +54 -0
- data/lib/pardot/objects/prospects.rb +73 -0
- data/lib/pardot/objects/users.rb +45 -0
- data/lib/pardot/objects/visitor_activities.rb +41 -0
- data/lib/pardot/objects/visitors.rb +45 -0
- data/lib/pardot/objects/visits.rb +41 -0
- data/lib/pardot/version.rb +3 -0
- data/lib/ruby-pardot.rb +17 -0
- data/ruby-pardot.gemspec +27 -0
- data/spec/pardot/authentication_spec.rb +38 -0
- data/spec/pardot/http_spec.rb +72 -0
- data/spec/pardot/objects/lists_spec.rb +41 -0
- data/spec/pardot/objects/opportunities_spec.rb +64 -0
- data/spec/pardot/objects/prospects_spec.rb +61 -0
- data/spec/pardot/objects/users_spec.rb +64 -0
- data/spec/pardot/objects/visitor_activities_spec.rb +64 -0
- data/spec/pardot/objects/visitors_spec.rb +64 -0
- data/spec/pardot/objects/visits_spec.rb +64 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/client_support.rb +6 -0
- data/spec/support/fakeweb.rb +14 -0
- metadata +132 -0
data/.gitignore
ADDED
data/.rspec
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruby-pardot (1.0)
|
5
|
+
crack
|
6
|
+
httparty
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
crack (0.1.8)
|
12
|
+
diff-lcs (1.1.2)
|
13
|
+
fakeweb (1.3.0)
|
14
|
+
httparty (0.7.4)
|
15
|
+
crack (= 0.1.8)
|
16
|
+
rspec (2.5.0)
|
17
|
+
rspec-core (~> 2.5.0)
|
18
|
+
rspec-expectations (~> 2.5.0)
|
19
|
+
rspec-mocks (~> 2.5.0)
|
20
|
+
rspec-core (2.5.1)
|
21
|
+
rspec-expectations (2.5.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (>= 1.0.0)
|
30
|
+
fakeweb
|
31
|
+
rspec
|
32
|
+
ruby-pardot!
|
data/README.rdoc
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
== Install
|
2
|
+
|
3
|
+
Add the following to your Gemfile
|
4
|
+
|
5
|
+
gem "ruby-pardot"
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
=== Authentication
|
10
|
+
|
11
|
+
The client will authenticate before performing other API calls, but you can manually authenticate as well
|
12
|
+
|
13
|
+
client = Pardot::Client.new email, password, user_key
|
14
|
+
|
15
|
+
# will raise a Pardot::ResponseError if login fails
|
16
|
+
# will raise a Pardot::NetError if the http call fails
|
17
|
+
client.authenticate
|
18
|
+
|
19
|
+
=== Object Types
|
20
|
+
|
21
|
+
The available objects are:
|
22
|
+
|
23
|
+
* lists
|
24
|
+
* opportunities
|
25
|
+
* prospects
|
26
|
+
* users
|
27
|
+
* visitor_activities
|
28
|
+
* visitors
|
29
|
+
* visits
|
30
|
+
|
31
|
+
=== Querying Objects
|
32
|
+
|
33
|
+
http://developer.pardot.com/kb/api-version-3/querying-prospects
|
34
|
+
|
35
|
+
Most objects accept limit, offset, sort_by, and sord_order parameters
|
36
|
+
|
37
|
+
prospects = client.prospects.query(:assigned => false, :sort_by => "last_activity_at", :limit => 20)
|
38
|
+
|
39
|
+
prospects["total_results"] # number of prospects found
|
40
|
+
|
41
|
+
prospects["prospect"].each do |prospect|
|
42
|
+
puts prospect["first_name"]
|
43
|
+
end
|
44
|
+
|
45
|
+
=== Creating, editing, and reading objects
|
46
|
+
|
47
|
+
See each individual object's API reference page for available methods
|
48
|
+
|
49
|
+
http://developer.pardot.com/kb/api-version-3/using-prospects
|
50
|
+
|
51
|
+
prospect = client.prospects.create("user@test.com", :first_name => "John", :last_name => "Doe")
|
52
|
+
|
53
|
+
prospect.each do |key, value|
|
54
|
+
puts "#{key} is #{value}"
|
55
|
+
end
|
56
|
+
|
57
|
+
=== Output formats
|
58
|
+
|
59
|
+
client.format = "simple" # default
|
60
|
+
client.format = "mobile"
|
61
|
+
client.format = "full"
|
62
|
+
|
63
|
+
=== Error handling
|
64
|
+
|
65
|
+
Pardot will respond with an error message when you provide invalid parameters
|
66
|
+
|
67
|
+
begin
|
68
|
+
prospect = client.prospects.create("user@test.com")
|
69
|
+
rescue Pardot::ResponseError => e
|
70
|
+
# the request went through, but Pardot responded with an error, possibly because this email is already in use
|
71
|
+
end
|
72
|
+
|
73
|
+
Performing API calls across the internet is inherently unsafe, so be sure to catch the exceptions
|
74
|
+
|
75
|
+
begin
|
76
|
+
visitor = client.visitors.query(:id_greater_than => 200)
|
77
|
+
rescue Pardot::NetError => e
|
78
|
+
# the API request failed
|
79
|
+
# - socket broke before the request was completed
|
80
|
+
# - pi.pardot.com is under heavy load
|
81
|
+
# - many number of other reasons
|
82
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pardot
|
2
|
+
module Authentication
|
3
|
+
|
4
|
+
def authenticate
|
5
|
+
resp = post "login", nil, :email => @email, :password => @password, :user_key => @user_key
|
6
|
+
@api_key = resp["api_key"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def authenticated?
|
10
|
+
@api_key != nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def reauthenticate
|
14
|
+
@api_key = nil
|
15
|
+
authenticate
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Pardot
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'https://pi.pardot.com'
|
7
|
+
format :xml
|
8
|
+
|
9
|
+
include Authentication
|
10
|
+
include Http
|
11
|
+
|
12
|
+
include Objects::Lists
|
13
|
+
include Objects::Opportunities
|
14
|
+
include Objects::Prospects
|
15
|
+
include Objects::Users
|
16
|
+
include Objects::Visitors
|
17
|
+
include Objects::Visits
|
18
|
+
include Objects::VisitorActivities
|
19
|
+
|
20
|
+
attr_accessor :email, :password, :user_key, :api_key, :format
|
21
|
+
|
22
|
+
def initialize email, password, user_key
|
23
|
+
@email = email
|
24
|
+
@password = password
|
25
|
+
@user_key = user_key
|
26
|
+
|
27
|
+
@format = "simple"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/pardot/error.rb
ADDED
data/lib/pardot/http.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Pardot
|
2
|
+
module Http
|
3
|
+
|
4
|
+
def get object, path, params = {}, num_retries = 0
|
5
|
+
smooth_params object, params
|
6
|
+
full_path = fullpath object, path
|
7
|
+
check_response self.class.get(full_path, :query => params)
|
8
|
+
|
9
|
+
rescue Pardot::ExpiredApiKeyError => e
|
10
|
+
handle_expired_api_key :get, object, path, params, num_retries, e
|
11
|
+
|
12
|
+
rescue SocketError, Interrupt, EOFError, SystemCallError => e
|
13
|
+
raise Pardot::NetError.new(e)
|
14
|
+
end
|
15
|
+
|
16
|
+
def post object, path, params = {}, num_retries = 0
|
17
|
+
smooth_params object, params
|
18
|
+
full_path = fullpath object, path
|
19
|
+
check_response self.class.post(full_path, :query => params)
|
20
|
+
|
21
|
+
rescue Pardot::ExpiredApiKeyError => e
|
22
|
+
handle_expired_api_key :post, object, path, params, num_retries, e
|
23
|
+
|
24
|
+
rescue SocketError, Interrupt, EOFError, SystemCallError => e
|
25
|
+
raise Pardot::NetError.new(e)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def handle_expired_api_key method, object, path, params, num_retries, e
|
31
|
+
raise e unless num_retries == 0
|
32
|
+
|
33
|
+
reauthenticate
|
34
|
+
|
35
|
+
send(method, object, path, params, 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
def smooth_params object, params
|
39
|
+
return if object == "login"
|
40
|
+
|
41
|
+
authenticate unless authenticated?
|
42
|
+
params.merge! :user_key => @user_key, :api_key => @api_key, :format => @format
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_response http_response
|
46
|
+
rsp = http_response["rsp"]
|
47
|
+
|
48
|
+
error = rsp["err"] if rsp
|
49
|
+
error ||= "Unknown Failure: #{rsp.inspect}" if rsp && rsp["stat"] == "fail"
|
50
|
+
|
51
|
+
if error == "Invalid API key or user key" && @api_key
|
52
|
+
raise ExpiredApiKeyError.new @api_key
|
53
|
+
end
|
54
|
+
|
55
|
+
raise ResponseError.new error if error
|
56
|
+
|
57
|
+
rsp
|
58
|
+
end
|
59
|
+
|
60
|
+
def fullpath object, path, version = 3
|
61
|
+
full = File.join("/api", object, "version", version.to_s)
|
62
|
+
unless path.nil?
|
63
|
+
full = File.join(full, path)
|
64
|
+
end
|
65
|
+
full
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Pardot
|
2
|
+
module Objects
|
3
|
+
|
4
|
+
module Lists
|
5
|
+
|
6
|
+
def lists
|
7
|
+
@lists ||= Lists.new self
|
8
|
+
end
|
9
|
+
|
10
|
+
class Lists
|
11
|
+
|
12
|
+
def initialize client
|
13
|
+
@client = client
|
14
|
+
end
|
15
|
+
|
16
|
+
def create id, params = {}
|
17
|
+
post "/do/create", params
|
18
|
+
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"]
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_by_id id, params = {}
|
27
|
+
get "/do/read/id/#{id}", params
|
28
|
+
end
|
29
|
+
|
30
|
+
def update id, params = {}
|
31
|
+
post "/do/update/#{id}"
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def get path, params = {}, result = "list"
|
37
|
+
response = @client.get "list", path, params
|
38
|
+
result ? response[result] : response
|
39
|
+
end
|
40
|
+
|
41
|
+
def post path, params = {}, result = "list"
|
42
|
+
response = @client.post "list", path, params
|
43
|
+
result ? response[result] : response
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Pardot
|
2
|
+
module Objects
|
3
|
+
|
4
|
+
module Opportunities
|
5
|
+
|
6
|
+
def opportunities
|
7
|
+
@opportunities ||= Opportunities.new self
|
8
|
+
end
|
9
|
+
|
10
|
+
class Opportunities
|
11
|
+
|
12
|
+
def initialize client
|
13
|
+
@client = client
|
14
|
+
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"]
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_by_email email, params = {}
|
23
|
+
post "/do/create/prospect_email/#{email}", params
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_by_id prospect_id, params = {}
|
27
|
+
post "/do/create/prospect_id/#{prospect_id}", params
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_by_id id, params = {}
|
31
|
+
post "/do/read/id/#{id}", params
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_by_id id, params = {}
|
35
|
+
post "/do/update/id/#{id}", params
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def get path, params = {}, result = "opportunity"
|
41
|
+
response = @client.get "opportunity", path, params
|
42
|
+
result ? response[result] : response
|
43
|
+
end
|
44
|
+
|
45
|
+
def post path, params = {}, result = "opportunity"
|
46
|
+
response = @client.post "opportunity", path, params
|
47
|
+
result ? response[result] : response
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Pardot
|
2
|
+
module Objects
|
3
|
+
module Prospects
|
4
|
+
|
5
|
+
def prospects
|
6
|
+
@prospects ||= Prospects.new self
|
7
|
+
end
|
8
|
+
|
9
|
+
class Prospects
|
10
|
+
|
11
|
+
def initialize client
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
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"]
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
def assign_by_email email, params
|
22
|
+
post "/do/assign/email/#{email}", params
|
23
|
+
end
|
24
|
+
|
25
|
+
def assign_by_id id, params
|
26
|
+
post "/do/assign/id/#{id}", params
|
27
|
+
end
|
28
|
+
|
29
|
+
def create email, params = {}
|
30
|
+
post "/do/create/email/#{email}", params
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_by_email email, params = {}
|
34
|
+
post "/do/read/email/#{email}", params
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_by_id id, params = {}
|
38
|
+
post "/do/read/id/#{id}", params
|
39
|
+
end
|
40
|
+
|
41
|
+
def update_by_email email, params = {}
|
42
|
+
post "/do/update/email/#{email}", params
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_by_id id, params = {}
|
46
|
+
post "/do/update/id/#{id}", params
|
47
|
+
end
|
48
|
+
|
49
|
+
def upsert_by_email email, params = {}
|
50
|
+
post "/do/upsert/email/#{email}", params
|
51
|
+
end
|
52
|
+
|
53
|
+
def upsert_by_id id, params = {}
|
54
|
+
post "/do/upsert/id/#{id}", params
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def get path, params = {}, result = "prospect"
|
60
|
+
response = @client.get "prospect", path, params
|
61
|
+
result ? response[result] : response
|
62
|
+
end
|
63
|
+
|
64
|
+
def post path, params = {}, result = "prospect"
|
65
|
+
response = @client.post "prospect", path, params
|
66
|
+
result ? response[result] : response
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|