diff --git a/Gemfile.lock b/Gemfile.lock
index a776dc4..82e43ea 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- ruby-pardot (1.0.2)
+ ruby-pardot (1.1.0)
crack
httparty
@@ -15,7 +15,7 @@ GEM
httparty (0.13.1)
json (~> 1.8)
multi_xml (>= 0.5.2)
- json (1.8.1)
+ json (1.8.3)
multi_xml (0.5.5)
rspec (2.5.0)
rspec-core (~> 2.5.0)
@@ -25,13 +25,16 @@ GEM
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
- safe_yaml (1.0.3)
+ safe_yaml (1.0.4)
PLATFORMS
ruby
DEPENDENCIES
- bundler (>= 1.0.0)
+ bundler (>= 1.10)
fakeweb
rspec
ruby-pardot!
+
+BUNDLED WITH
+ 1.11.2
diff --git a/lib/pardot/authentication.rb b/lib/pardot/authentication.rb
index 84821b8..7919285 100644
--- a/lib/pardot/authentication.rb
+++ b/lib/pardot/authentication.rb
@@ -3,6 +3,7 @@ module Authentication
def authenticate
resp = post "login", nil, :email => @email, :password => @password, :user_key => @user_key
+ update_version(resp["version"]) if resp && resp["version"]
@api_key = resp && resp["api_key"]
end
@@ -14,6 +15,15 @@ def reauthenticate
@api_key = nil
authenticate
end
-
+
+ private
+
+ def update_version version
+ if version.is_a? Array
+ version = version.last
+ end
+ @version = version if version.to_i > 3
+ end
+
end
end
diff --git a/lib/pardot/client.rb b/lib/pardot/client.rb
index 914dbff..36e9745 100644
--- a/lib/pardot/client.rb
+++ b/lib/pardot/client.rb
@@ -20,16 +20,16 @@ class Client
include Objects::Visits
include Objects::VisitorActivities
- attr_accessor :email, :password, :user_key, :api_key, :format
+ attr_accessor :email, :password, :user_key, :api_key, :version, :format
- def initialize email, password, user_key
+ def initialize email, password, user_key, version = 3
@email = email
@password = password
@user_key = user_key
+ @version = version
@format = "simple"
end
-
end
end
diff --git a/lib/pardot/http.rb b/lib/pardot/http.rb
index e0de31a..0dd33e9 100644
--- a/lib/pardot/http.rb
+++ b/lib/pardot/http.rb
@@ -58,8 +58,8 @@ def check_response http_response
rsp
end
- def fullpath object, path, version = 3
- full = File.join("/api", object, "version", version.to_s)
+ def fullpath object, path
+ full = File.join("/api", object, "version", @version.to_s)
unless path.nil?
full = File.join(full, path)
end
diff --git a/lib/pardot/objects/prospects.rb b/lib/pardot/objects/prospects.rb
index 704eb9a..583f3d2 100644
--- a/lib/pardot/objects/prospects.rb
+++ b/lib/pardot/objects/prospects.rb
@@ -26,10 +26,22 @@ def assign_by_id id, params
post "/do/assign/id/#{id}", params
end
+ def assign_by_fid fid, params
+ post "/do/assign/fid/#{fid}", params
+ end
+
def create email, params = {}
post "/do/create/email/#{email}", params
end
+ def delete_by_id id, params = {}
+ post "/do/delete/id/#{id}", params
+ end
+
+ def delete_by_fid fid, params = {}
+ post "/do/delete/fid/#{fid}", params
+ end
+
def read_by_email email, params = {}
post "/do/read/email/#{email}", params
end
@@ -38,6 +50,22 @@ def read_by_id id, params = {}
post "/do/read/id/#{id}", params
end
+ def read_by_fid fid, params = {}
+ post "/do/read/fid/#{fid}", params
+ end
+
+ def unassign_by_email email, params = {}
+ post "/do/unassign/email/#{email}", params
+ end
+
+ def unassign_by_id id, params = {}
+ post "/do/unassign/id/#{id}", params
+ end
+
+ def unassign_by_fid fid, params = {}
+ post "/do/unassign/fid/#{fid}", params
+ end
+
def update_by_email email, params = {}
post "/do/update/email/#{email}", params
end
@@ -46,6 +74,10 @@ def update_by_id id, params = {}
post "/do/update/id/#{id}", params
end
+ def update_by_fid fid, params = {}
+ post "/do/update/fid/#{fid}", params
+ end
+
def upsert_by_email email, params = {}
post "/do/upsert/email/#{email}", params
end
@@ -54,6 +86,10 @@ def upsert_by_id id, params = {}
post "/do/upsert/id/#{id}", params
end
+ def upsert_by_fid fid, params = {}
+ post "/do/upsert/fid/#{fid}", params
+ end
+
protected
def get path, params = {}, result = "prospect"
diff --git a/lib/pardot/version.rb b/lib/pardot/version.rb
index d71de34..e305cb3 100644
--- a/lib/pardot/version.rb
+++ b/lib/pardot/version.rb
@@ -1,3 +1,3 @@
module Pardot
- VERSION = "1.0.2"
+ VERSION = "1.1.0"
end
diff --git a/ruby-pardot.gemspec b/ruby-pardot.gemspec
index 979b4b9..f710b11 100644
--- a/ruby-pardot.gemspec
+++ b/ruby-pardot.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.add_dependency "crack"
s.add_dependency "httparty"
- s.add_development_dependency "bundler", ">= 1.0.0"
+ s.add_development_dependency "bundler", ">= 1.10"
s.add_development_dependency "rspec"
s.add_development_dependency "fakeweb"
diff --git a/spec/pardot/authentication_spec.rb b/spec/pardot/authentication_spec.rb
index 845c265..ee0af8d 100644
--- a/spec/pardot/authentication_spec.rb
+++ b/spec/pardot/authentication_spec.rb
@@ -32,6 +32,45 @@ def authenticate
authenticate
@client.authenticated?.should == true
end
+
+ it "should use version 3" do
+ authenticate
+ @client.version.to_i.should == 3
+ end
+
+ end
+
+ describe "authenticateV4" do
+
+ before do
+ @client = create_client
+
+ fake_post "/api/login/version/3?email=user%40test.com&password=foo&user_key=bar",
+ %(\n\n my_api_key\n4\n\n)
+ end
+
+ def authenticate
+ @client.authenticate
+ end
+
+ it "should return the api key" do
+ authenticate.should == "my_api_key"
+ end
+
+ it "should set the api key" do
+ authenticate
+ @client.api_key.should == "my_api_key"
+ end
+
+ it "should make authenticated? true" do
+ authenticate
+ @client.authenticated?.should == true
+ end
+
+ it "should use version 4" do
+ authenticate
+ @client.version.to_i.should == 4
+ end
end
diff --git a/spec/pardot/client_spec.rb b/spec/pardot/client_spec.rb
new file mode 100644
index 0000000..324f2e4
--- /dev/null
+++ b/spec/pardot/client_spec.rb
@@ -0,0 +1,28 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Pardot::Client do
+
+ def create_client
+ @client = Pardot::Client.new "user@test.com", "foo", "bar"
+ end
+
+ describe "client" do
+ after do
+ @client.email.should == "user@test.com"
+ @client.password.should == "password"
+ @client.user_key.should == "user_key"
+ @client.format.should == "simple"
+ end
+
+ it "should set variables without version" do
+ @client = Pardot::Client.new "user@test.com", "password", "user_key"
+ @client.version.should == 3
+ end
+
+ it "should set variables with version" do
+ @client = Pardot::Client.new "user@test.com", "password", "user_key", 4
+ @client.version.should == 4
+ end
+
+ end
+end
diff --git a/spec/pardot/http_spec.rb b/spec/pardot/http_spec.rb
index 9b98e70..0039887 100644
--- a/spec/pardot/http_spec.rb
+++ b/spec/pardot/http_spec.rb
@@ -68,5 +68,65 @@ def post object = "foo", path = "/bar", params = {}
end
end
+
+ describe "getV4" do
+
+ def get object = "foo", path = "/bar", params = {}
+ @client.version = "4"
+ @client.get object, path, params
+ end
+
+ it "should notice errors and raise them as Pardot::ResponseError" do
+ fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
+ %(?xml version="1.0" encoding="UTF-8"?>\n\n Login failed\n\n)
+
+ lambda { get }.should raise_error(Pardot::ResponseError)
+ end
+
+ it "should catch and reraise SocketErrors as Pardot::NetError" do
+ Pardot::Client.should_receive(:get).and_raise(SocketError)
+
+ lambda { get }.should raise_error(Pardot::NetError)
+ end
+
+ it "should call handle_expired_api_key when the api key expires" do
+ fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
+ %(?xml version="1.0" encoding="UTF-8"?>\n\n Invalid API key or user key\n\n)
+
+ @client.should_receive(:handle_expired_api_key)
+ get
+ end
+
+ end
+
+ describe "postV4" do
+
+ def post object = "foo", path = "/bar", params = {}
+ @client.version = "4"
+ @client.post object, path, params
+ end
+
+ it "should notice errors and raise them as Pardot::ResponseError" do
+ fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
+ %(?xml version="1.0" encoding="UTF-8"?>\n\n Login failed\n\n)
+
+ lambda { post }.should raise_error(Pardot::ResponseError)
+ end
+
+ it "should catch and reraise SocketErrors as Pardot::NetError" do
+ Pardot::Client.should_receive(:post).and_raise(SocketError)
+
+ lambda { post }.should raise_error(Pardot::NetError)
+ end
+
+ it "should call handle_expired_api_key when the api key expires" do
+ fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
+ %(?xml version="1.0" encoding="UTF-8"?>\n\n Invalid API key or user key\n\n)
+
+ @client.should_receive(:handle_expired_api_key)
+ post
+ end
+
+ end
end
\ No newline at end of file