ruby-pardot 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b5a3bceaeff6bb81efc73dfc2ee2fb51e3fce2e
4
- data.tar.gz: cdc11f89e0415c6b3d0484d7fe67147a3b8a087e
3
+ metadata.gz: d1399136219ec0bea476ce3d8719d50664a2cbca
4
+ data.tar.gz: c24bfb39f4efbf9c228725f60d8cbe029d9b3eab
5
5
  SHA512:
6
- metadata.gz: 69f994887ac58cf22de6f963d1793f4dfb0ba35cb3adedc4d3baf3fcabd766ce187bb31047de526545488cbe951c7e31d29872bfe75d5029a675254c7fe60817
7
- data.tar.gz: 013ffa24e4853541125c89bcb08c90ce88de3db3a0cd2475fba4bc787682f1e8fd1a9e91550cc1ea702e74c282b8b818e2fa254cba29699a0471a612cc108b16
6
+ metadata.gz: 349bf990141ef0c54deaae2a8a85859bd2d18f4619e2b561d6248bbe20223d013771b63bc83f72d81844df6e1affe136d3bc6afbd32e48f11553a74b6f6c1ae0
7
+ data.tar.gz: f678e13f8963b06ca5e4cb636ea04407280e10b1fa8fa24f3b5da264722347bdf3508aa9042ca363f090e00b0ee5e0f651a5e8b411b9abae5de7322944a81a36
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-pardot (1.0.2)
4
+ ruby-pardot (1.1.0)
5
5
  crack
6
6
  httparty
7
7
 
@@ -15,7 +15,7 @@ GEM
15
15
  httparty (0.13.1)
16
16
  json (~> 1.8)
17
17
  multi_xml (>= 0.5.2)
18
- json (1.8.1)
18
+ json (1.8.3)
19
19
  multi_xml (0.5.5)
20
20
  rspec (2.5.0)
21
21
  rspec-core (~> 2.5.0)
@@ -25,13 +25,16 @@ GEM
25
25
  rspec-expectations (2.5.0)
26
26
  diff-lcs (~> 1.1.2)
27
27
  rspec-mocks (2.5.0)
28
- safe_yaml (1.0.3)
28
+ safe_yaml (1.0.4)
29
29
 
30
30
  PLATFORMS
31
31
  ruby
32
32
 
33
33
  DEPENDENCIES
34
- bundler (>= 1.0.0)
34
+ bundler (>= 1.10)
35
35
  fakeweb
36
36
  rspec
37
37
  ruby-pardot!
38
+
39
+ BUNDLED WITH
40
+ 1.11.2
@@ -3,6 +3,7 @@ module Pardot
3
3
 
4
4
  def authenticate
5
5
  resp = post "login", nil, :email => @email, :password => @password, :user_key => @user_key
6
+ update_version(resp["version"]) if resp && resp["version"]
6
7
  @api_key = resp && resp["api_key"]
7
8
  end
8
9
 
@@ -14,6 +15,15 @@ module Pardot
14
15
  @api_key = nil
15
16
  authenticate
16
17
  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
+
18
28
  end
19
29
  end
@@ -20,16 +20,16 @@ module Pardot
20
20
  include Objects::Visits
21
21
  include Objects::VisitorActivities
22
22
 
23
- attr_accessor :email, :password, :user_key, :api_key, :format
23
+ attr_accessor :email, :password, :user_key, :api_key, :version, :format
24
24
 
25
- def initialize email, password, user_key
25
+ def initialize email, password, user_key, version = 3
26
26
  @email = email
27
27
  @password = password
28
28
  @user_key = user_key
29
+ @version = version
29
30
 
30
31
  @format = "simple"
31
32
  end
32
33
 
33
-
34
34
  end
35
35
  end
@@ -58,8 +58,8 @@ module Pardot
58
58
  rsp
59
59
  end
60
60
 
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)
63
63
  unless path.nil?
64
64
  full = File.join(full, path)
65
65
  end
@@ -26,10 +26,22 @@ module Pardot
26
26
  post "/do/assign/id/#{id}", params
27
27
  end
28
28
 
29
+ def assign_by_fid fid, params
30
+ post "/do/assign/fid/#{fid}", params
31
+ end
32
+
29
33
  def create email, params = {}
30
34
  post "/do/create/email/#{email}", params
31
35
  end
32
36
 
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
+
33
45
  def read_by_email email, params = {}
34
46
  post "/do/read/email/#{email}", params
35
47
  end
@@ -38,6 +50,22 @@ module Pardot
38
50
  post "/do/read/id/#{id}", params
39
51
  end
40
52
 
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
+
41
69
  def update_by_email email, params = {}
42
70
  post "/do/update/email/#{email}", params
43
71
  end
@@ -46,6 +74,10 @@ module Pardot
46
74
  post "/do/update/id/#{id}", params
47
75
  end
48
76
 
77
+ def update_by_fid fid, params = {}
78
+ post "/do/update/fid/#{fid}", params
79
+ end
80
+
49
81
  def upsert_by_email email, params = {}
50
82
  post "/do/upsert/email/#{email}", params
51
83
  end
@@ -54,6 +86,10 @@ module Pardot
54
86
  post "/do/upsert/id/#{id}", params
55
87
  end
56
88
 
89
+ def upsert_by_fid fid, params = {}
90
+ post "/do/upsert/fid/#{fid}", params
91
+ end
92
+
57
93
  protected
58
94
 
59
95
  def get path, params = {}, result = "prospect"
@@ -1,3 +1,3 @@
1
1
  module Pardot
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency "crack"
18
18
  s.add_dependency "httparty"
19
19
 
20
- s.add_development_dependency "bundler", ">= 1.0.0"
20
+ s.add_development_dependency "bundler", ">= 1.10"
21
21
  s.add_development_dependency "rspec"
22
22
  s.add_development_dependency "fakeweb"
23
23
 
@@ -32,6 +32,45 @@ describe Pardot::Authentication do
32
32
  authenticate
33
33
  @client.authenticated?.should == true
34
34
  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
35
74
 
36
75
  end
37
76
 
@@ -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 "user@test.com", "foo", "bar"
7
+ end
8
+
9
+ describe "client" do
10
+ after do
11
+ @client.email.should == "user@test.com"
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 "user@test.com", "password", "user_key"
19
+ @client.version.should == 3
20
+ end
21
+
22
+ it "should set variables with version" do
23
+ @client = Pardot::Client.new "user@test.com", "password", "user_key", 4
24
+ @client.version.should == 4
25
+ end
26
+
27
+ end
28
+ end
@@ -68,5 +68,65 @@ describe Pardot::Http do
68
68
  end
69
69
 
70
70
  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
71
131
 
72
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pardot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Cunning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crack
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.0
47
+ version: '1.10'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.0
54
+ version: '1.10'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +111,7 @@ files:
111
111
  - lib/ruby-pardot.rb
112
112
  - ruby-pardot.gemspec
113
113
  - spec/pardot/authentication_spec.rb
114
+ - spec/pardot/client_spec.rb
114
115
  - spec/pardot/error_spec.rb
115
116
  - spec/pardot/http_spec.rb
116
117
  - spec/pardot/objects/emails_spec.rb
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  version: 1.3.6
145
146
  requirements: []
146
147
  rubyforge_project: ruby-pardot
147
- rubygems_version: 2.4.6
148
+ rubygems_version: 2.5.1
148
149
  signing_key:
149
150
  specification_version: 4
150
151
  summary: Library for interacting with the Pardot API