Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 772 #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
PATH
remote: .
specs:
ruby-pardot (1.1.0)
crack
httparty
ruby-pardot (1.3.2)
crack (= 0.4.3)
httparty (= 0.13.1)

GEM
remote: http://rubygems.org/
specs:
crack (0.4.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.1.2)
fakeweb (1.3.0)
httparty (0.13.1)
json (~> 1.8)
multi_xml (>= 0.5.2)
json (1.8.3)
multi_xml (0.5.5)
json (1.8.6)
multi_xml (0.6.0)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
Expand All @@ -25,7 +25,7 @@ GEM
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
safe_yaml (1.0.4)
safe_yaml (1.0.5)

PLATFORMS
ruby
Expand All @@ -37,4 +37,4 @@ DEPENDENCIES
ruby-pardot!

BUNDLED WITH
1.11.2
2.0.2
1 change: 1 addition & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The client will authenticate before performing other API calls, but you can manu

The available objects are:

* custom_fields
* emails
* lists
* opportunities
Expand Down
2 changes: 1 addition & 1 deletion lib/pardot/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Pardot
module Authentication

def authenticate
resp = post "login", nil, :email => @email, :password => @password, :user_key => @user_key
resp = post "login", nil, nil, nil, :email => @email, :password => @password, :user_key => @user_key
update_version(resp["version"]) if resp && resp["version"]
@api_key = resp && resp["api_key"]
end
Expand Down
1 change: 1 addition & 0 deletions lib/pardot/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Client
include Authentication
include Http

include Objects::CustomFields
include Objects::Emails
include Objects::Lists
include Objects::ListMemberships
Expand Down
17 changes: 13 additions & 4 deletions lib/pardot/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Http
def get object, path, params = {}, num_retries = 0
smooth_params object, params
full_path = fullpath object, path
check_response self.class.get(full_path, :query => params)
headers = create_auth_header object
check_response self.class.get(full_path, :query => params, :headers => headers)

rescue Pardot::ExpiredApiKeyError => e
handle_expired_api_key :get, object, path, params, num_retries, e
Expand All @@ -13,10 +14,11 @@ def get object, path, params = {}, num_retries = 0
raise Pardot::NetError.new(e)
end

def post object, path, params = {}, num_retries = 0
def post object, path, params = {}, num_retries = 0, bodyParams = {}
smooth_params object, params
full_path = fullpath object, path
check_response self.class.post(full_path, :query => params)
headers = create_auth_header object
check_response self.class.post(full_path, :query => params, :body => bodyParams, :headers => headers)

rescue Pardot::ExpiredApiKeyError => e
handle_expired_api_key :post, object, path, params, num_retries, e
Expand All @@ -39,7 +41,14 @@ def smooth_params object, params
return if object == "login"

authenticate unless authenticated?
params.merge! :user_key => @user_key, :api_key => @api_key, :format => @format
params.merge! :format => @format
end

def create_auth_header object
return if object == "login"
# { :Authorization => "Pardot api_key=#{@api_key}, user_key=#{@user_key}" }
{ :Authorization => "Bearer 00D030000004Yxj!ARYAQM5rCFm65bX3wwx_bpWBzEb1w8Bbp0_zuWe1XXliCcfKtalT42o6dMpEeG4uDFy3hzww9f.SPHCuk40MatRfkw8cC0LX", "Pardot-Business-Unit-Id" => "0Uv03000000CaRgCAK" }

end

def check_response http_response
Expand Down
37 changes: 37 additions & 0 deletions lib/pardot/objects/custom_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Pardot
module Objects
module CustomFields

def custom_fields
@custom_fields ||= CustomFields.new self
end

class CustomFields

def initialize client
@client = client
end

def query params
result = get "/do/query", params, "result"
result["total_results"] = result["total_results"].to_i if result["total_results"]
result
end

protected

def get path, params = {}, result = "customField"
response = @client.get "customField", path, params
result ? response[result] : response
end

def post path, params = {}, result = "user"
response = @client.post "customField", path, params
result ? response[result] : response
end

end

end
end
end
92 changes: 47 additions & 45 deletions lib/pardot/objects/prospects.rb
Original file line number Diff line number Diff line change
@@ -1,109 +1,111 @@
require 'cgi'

module Pardot
module Objects
module Prospects

def prospects
@prospects ||= Prospects.new self
end

class Prospects

def initialize client
@client = client
end

def query search_criteria
result = get "/do/query", search_criteria, "result"
result["total_results"] = result["total_results"].to_i if result["total_results"]
result
end

def assign_by_email email, params
post "/do/assign/email/#{email}", params
post "/do/assign/email/#{CGI.escape(email)}", params
end

def assign_by_id id, params
post "/do/assign/id/#{id}", params
post "/do/assign/id/#{CGI.escape(id)}", params
end

def assign_by_fid fid, params
post "/do/assign/fid/#{fid}", params
post "/do/assign/fid/#{CGI.escape(fid)}", params
end

def create email, params = {}
post "/do/create/email/#{email}", params
post "/do/create/email/#{CGI.escape(email)}", params
end

def delete_by_id id, params = {}
post "/do/delete/id/#{id}", params
post "/do/delete/id/#{CGI.escape(id)}", params
end

def delete_by_fid fid, params = {}
post "/do/delete/fid/#{fid}", params
post "/do/delete/fid/#{CGI.escape(fid)}", params
end

def read_by_email email, params = {}
post "/do/read/email/#{email}", params
post "/do/read/email/#{CGI.escape(email)}", params
end

def read_by_id id, params = {}
post "/do/read/id/#{id}", params
post "/do/read/id/#{CGI.escape(id)}", params
end

def read_by_fid fid, params = {}
post "/do/read/fid/#{fid}", params
post "/do/read/fid/#{CGI.escape(fid)}", params
end

def unassign_by_email email, params = {}
post "/do/unassign/email/#{email}", params
post "/do/unassign/email/#{CGI.escape(email)}", params
end

def unassign_by_id id, params = {}
post "/do/unassign/id/#{id}", params
post "/do/unassign/id/#{CGI.escape(id)}", params
end

def unassign_by_fid fid, params = {}
post "/do/unassign/fid/#{fid}", params
post "/do/unassign/fid/#{CGI.escape(fid)}", params
end

def update_by_email email, params = {}
post "/do/update/email/#{email}", params
post "/do/update/email/#{CGI.escape(email)}", params
end

def update_by_id id, params = {}
post "/do/update/id/#{id}", params
post "/do/update/id/#{CGI.escape(id)}", params
end

def update_by_fid fid, params = {}
post "/do/update/fid/#{fid}", params
post "/do/update/fid/#{CGI.escape(fid)}", params
end

def upsert_by_email email, params = {}
post "/do/upsert/email/#{email}", params
post "/do/upsert/email/#{CGI.escape(email)}", params
end

def upsert_by_id id, params = {}
post "/do/upsert/id/#{id}", params
post "/do/upsert/id/#{CGI.escape(id)}", params
end

def upsert_by_fid fid, params = {}
post "/do/upsert/fid/#{fid}", params
post "/do/upsert/fid/#{CGI.escape(fid)}", params
end

protected

def get path, params = {}, result = "prospect"
response = @client.get "prospect", path, params
result ? response[result] : response
end

def post path, params = {}, result = "prospect"
response = @client.post "prospect", path, params
result ? response[result] : response
end

end

end
end
end
2 changes: 1 addition & 1 deletion lib/pardot/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pardot
VERSION = "1.1.0"
VERSION = "1.3.2"
end
1 change: 1 addition & 0 deletions lib/ruby-pardot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'pardot/error'
require 'pardot/authentication'

require 'pardot/objects/custom_fields'
require 'pardot/objects/emails'
require 'pardot/objects/lists'
require 'pardot/objects/list_memberships'
Expand Down
4 changes: 2 additions & 2 deletions ruby-pardot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "ruby-pardot"

s.add_dependency "crack"
s.add_dependency "httparty"
s.add_dependency "crack", "0.4.3"
s.add_dependency "httparty", "0.13.1"

s.add_development_dependency "bundler", ">= 1.10"
s.add_development_dependency "rspec"
Expand Down
Loading