Skip to content

Commit fdc4dc8

Browse files
author
Justin Roberts
authored
Merge pull request pardot#29 from Pardot/version_4
Adding version 4 support, incrementing version to 1.1.0
2 parents 837bae6 + 6fd1ad0 commit fdc4dc8

File tree

10 files changed

+188
-12
lines changed

10 files changed

+188
-12
lines changed

Gemfile.lock

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby-pardot (1.0.2)
4+
ruby-pardot (1.1.0)
55
crack
66
httparty
77

@@ -15,7 +15,7 @@ GEM
1515
httparty (0.13.1)
1616
json (~> 1.8)
1717
multi_xml (>= 0.5.2)
18-
json (1.8.1)
18+
json (1.8.3)
1919
multi_xml (0.5.5)
2020
rspec (2.5.0)
2121
rspec-core (~> 2.5.0)
@@ -25,13 +25,16 @@ GEM
2525
rspec-expectations (2.5.0)
2626
diff-lcs (~> 1.1.2)
2727
rspec-mocks (2.5.0)
28-
safe_yaml (1.0.3)
28+
safe_yaml (1.0.4)
2929

3030
PLATFORMS
3131
ruby
3232

3333
DEPENDENCIES
34-
bundler (>= 1.0.0)
34+
bundler (>= 1.10)
3535
fakeweb
3636
rspec
3737
ruby-pardot!
38+
39+
BUNDLED WITH
40+
1.11.2

lib/pardot/authentication.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Authentication
33

44
def authenticate
55
resp = post "login", nil, :email => @email, :password => @password, :user_key => @user_key
6+
update_version(resp["version"]) if resp && resp["version"]
67
@api_key = resp && resp["api_key"]
78
end
89

@@ -14,6 +15,15 @@ def reauthenticate
1415
@api_key = nil
1516
authenticate
1617
end
17-
18+
19+
private
20+
21+
def update_version version
22+
if version.is_a? Array
23+
version = version.last
24+
end
25+
@version = version if version.to_i > 3
26+
end
27+
1828
end
1929
end

lib/pardot/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class Client
2020
include Objects::Visits
2121
include Objects::VisitorActivities
2222

23-
attr_accessor :email, :password, :user_key, :api_key, :format
23+
attr_accessor :email, :password, :user_key, :api_key, :version, :format
2424

25-
def initialize email, password, user_key
25+
def initialize email, password, user_key, version = 3
2626
@email = email
2727
@password = password
2828
@user_key = user_key
29+
@version = version
2930

3031
@format = "simple"
3132
end
3233

33-
3434
end
3535
end

lib/pardot/http.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def check_response http_response
5858
rsp
5959
end
6060

61-
def fullpath object, path, version = 3
62-
full = File.join("/api", object, "version", version.to_s)
61+
def fullpath object, path
62+
full = File.join("/api", object, "version", @version.to_s)
6363
unless path.nil?
6464
full = File.join(full, path)
6565
end

lib/pardot/objects/prospects.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ def assign_by_id id, params
2626
post "/do/assign/id/#{id}", params
2727
end
2828

29+
def assign_by_fid fid, params
30+
post "/do/assign/fid/#{fid}", params
31+
end
32+
2933
def create email, params = {}
3034
post "/do/create/email/#{email}", params
3135
end
3236

37+
def delete_by_id id, params = {}
38+
post "/do/delete/id/#{id}", params
39+
end
40+
41+
def delete_by_fid fid, params = {}
42+
post "/do/delete/fid/#{fid}", params
43+
end
44+
3345
def read_by_email email, params = {}
3446
post "/do/read/email/#{email}", params
3547
end
@@ -38,6 +50,22 @@ def read_by_id id, params = {}
3850
post "/do/read/id/#{id}", params
3951
end
4052

53+
def read_by_fid fid, params = {}
54+
post "/do/read/fid/#{fid}", params
55+
end
56+
57+
def unassign_by_email email, params = {}
58+
post "/do/unassign/email/#{email}", params
59+
end
60+
61+
def unassign_by_id id, params = {}
62+
post "/do/unassign/id/#{id}", params
63+
end
64+
65+
def unassign_by_fid fid, params = {}
66+
post "/do/unassign/fid/#{fid}", params
67+
end
68+
4169
def update_by_email email, params = {}
4270
post "/do/update/email/#{email}", params
4371
end
@@ -46,6 +74,10 @@ def update_by_id id, params = {}
4674
post "/do/update/id/#{id}", params
4775
end
4876

77+
def update_by_fid fid, params = {}
78+
post "/do/update/fid/#{fid}", params
79+
end
80+
4981
def upsert_by_email email, params = {}
5082
post "/do/upsert/email/#{email}", params
5183
end
@@ -54,6 +86,10 @@ def upsert_by_id id, params = {}
5486
post "/do/upsert/id/#{id}", params
5587
end
5688

89+
def upsert_by_fid fid, params = {}
90+
post "/do/upsert/fid/#{fid}", params
91+
end
92+
5793
protected
5894

5995
def get path, params = {}, result = "prospect"

lib/pardot/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Pardot
2-
VERSION = "1.0.2"
2+
VERSION = "1.1.0"
33
end

ruby-pardot.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
1717
s.add_dependency "crack"
1818
s.add_dependency "httparty"
1919

20-
s.add_development_dependency "bundler", ">= 1.0.0"
20+
s.add_development_dependency "bundler", ">= 1.10"
2121
s.add_development_dependency "rspec"
2222
s.add_development_dependency "fakeweb"
2323

spec/pardot/authentication_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,45 @@ def authenticate
3232
authenticate
3333
@client.authenticated?.should == true
3434
end
35+
36+
it "should use version 3" do
37+
authenticate
38+
@client.version.to_i.should == 3
39+
end
40+
41+
end
42+
43+
describe "authenticateV4" do
44+
45+
before do
46+
@client = create_client
47+
48+
fake_post "/api/login/version/3?email=user%40test.com&password=foo&user_key=bar",
49+
%(<?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+
end
51+
52+
def authenticate
53+
@client.authenticate
54+
end
55+
56+
it "should return the api key" do
57+
authenticate.should == "my_api_key"
58+
end
59+
60+
it "should set the api key" do
61+
authenticate
62+
@client.api_key.should == "my_api_key"
63+
end
64+
65+
it "should make authenticated? true" do
66+
authenticate
67+
@client.authenticated?.should == true
68+
end
69+
70+
it "should use version 4" do
71+
authenticate
72+
@client.version.to_i.should == 4
73+
end
3574

3675
end
3776

spec/pardot/client_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2+
3+
describe Pardot::Client do
4+
5+
def create_client
6+
@client = Pardot::Client.new "[email protected]", "foo", "bar"
7+
end
8+
9+
describe "client" do
10+
after do
11+
@client.email.should == "[email protected]"
12+
@client.password.should == "password"
13+
@client.user_key.should == "user_key"
14+
@client.format.should == "simple"
15+
end
16+
17+
it "should set variables without version" do
18+
@client = Pardot::Client.new "[email protected]", "password", "user_key"
19+
@client.version.should == 3
20+
end
21+
22+
it "should set variables with version" do
23+
@client = Pardot::Client.new "[email protected]", "password", "user_key", 4
24+
@client.version.should == 4
25+
end
26+
27+
end
28+
end

spec/pardot/http_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,65 @@ def post object = "foo", path = "/bar", params = {}
6868
end
6969

7070
end
71+
72+
describe "getV4" do
73+
74+
def get object = "foo", path = "/bar", params = {}
75+
@client.version = "4"
76+
@client.get object, path, params
77+
end
78+
79+
it "should notice errors and raise them as Pardot::ResponseError" do
80+
fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
81+
%(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
82+
83+
lambda { get }.should raise_error(Pardot::ResponseError)
84+
end
85+
86+
it "should catch and reraise SocketErrors as Pardot::NetError" do
87+
Pardot::Client.should_receive(:get).and_raise(SocketError)
88+
89+
lambda { get }.should raise_error(Pardot::NetError)
90+
end
91+
92+
it "should call handle_expired_api_key when the api key expires" do
93+
fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
94+
%(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n)
95+
96+
@client.should_receive(:handle_expired_api_key)
97+
get
98+
end
99+
100+
end
101+
102+
describe "postV4" do
103+
104+
def post object = "foo", path = "/bar", params = {}
105+
@client.version = "4"
106+
@client.post object, path, params
107+
end
108+
109+
it "should notice errors and raise them as Pardot::ResponseError" do
110+
fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
111+
%(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n)
112+
113+
lambda { post }.should raise_error(Pardot::ResponseError)
114+
end
115+
116+
it "should catch and reraise SocketErrors as Pardot::NetError" do
117+
Pardot::Client.should_receive(:post).and_raise(SocketError)
118+
119+
lambda { post }.should raise_error(Pardot::NetError)
120+
end
121+
122+
it "should call handle_expired_api_key when the api key expires" do
123+
fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar",
124+
%(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n)
125+
126+
@client.should_receive(:handle_expired_api_key)
127+
post
128+
end
129+
130+
end
71131

72132
end

0 commit comments

Comments
 (0)