Skip to content

Commit d1f2859

Browse files
authored
Merge pull request pardot#44 from clearbit/master
Add support for querying `customField` objects
2 parents d683ab0 + 9f67017 commit d1f2859

File tree

8 files changed

+104
-6
lines changed

8 files changed

+104
-6
lines changed

Gemfile.lock

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

@@ -37,4 +37,4 @@ DEPENDENCIES
3737
ruby-pardot!
3838

3939
BUNDLED WITH
40-
2.0.1
40+
2.0.2

README.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The client will authenticate before performing other API calls, but you can manu
2020

2121
The available objects are:
2222

23+
* custom_fields
2324
* emails
2425
* lists
2526
* opportunities

lib/pardot/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Client
99
include Authentication
1010
include Http
1111

12+
include Objects::CustomFields
1213
include Objects::Emails
1314
include Objects::Lists
1415
include Objects::ListMemberships

lib/pardot/objects/custom_fields.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Pardot
2+
module Objects
3+
module CustomFields
4+
5+
def custom_fields
6+
@custom_fields ||= CustomFields.new self
7+
end
8+
9+
class CustomFields
10+
11+
def initialize client
12+
@client = client
13+
end
14+
15+
def query params
16+
result = get "/do/query", params, "result"
17+
result["total_results"] = result["total_results"].to_i if result["total_results"]
18+
result
19+
end
20+
21+
protected
22+
23+
def get path, params = {}, result = "customField"
24+
response = @client.get "customField", path, params
25+
result ? response[result] : response
26+
end
27+
28+
def post path, params = {}, result = "user"
29+
response = @client.post "customField", path, params
30+
result ? response[result] : response
31+
end
32+
33+
end
34+
35+
end
36+
end
37+
end

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.3.1"
2+
VERSION = "1.3.2"
33
end

lib/ruby-pardot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'pardot/error'
77
require 'pardot/authentication'
88

9+
require 'pardot/objects/custom_fields'
910
require 'pardot/objects/emails'
1011
require 'pardot/objects/lists'
1112
require 'pardot/objects/list_memberships'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2+
3+
describe Pardot::Objects::CustomFields do
4+
5+
before do
6+
@client = create_client
7+
end
8+
9+
describe "query" do
10+
11+
def sample_results
12+
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
13+
<result>
14+
<total_results>1</total_results>
15+
<customField>
16+
<created_at>2019-11-26 13:40:37</created_at>
17+
<crm_id null="true" />
18+
<field_id>CustomObject1574793618883</field_id>
19+
<id>8932</id>
20+
<is_record_multiple_responses>false</is_record_multiple_responses>
21+
<is_use_values>false</is_use_values>
22+
<name>Ω≈ç√∫˜µ≤≥÷</name>
23+
<type>Text</type>
24+
<type_id>1</type_id>
25+
<updated_at>2019-11-26 13:40:37</updated_at>
26+
</customField>
27+
</result>
28+
</rsp>)
29+
end
30+
31+
before do
32+
@client = create_client
33+
end
34+
35+
it "should take in some arguments" do
36+
fake_get "/api/customField/version/3/do/query?id_greater_than=200&format=simple", sample_results
37+
38+
@client.custom_fields.query(:id_greater_than => 200).should == {"total_results" => 1,
39+
"customField"=>
40+
{
41+
"id"=>"8932",
42+
"name"=>"Ω≈ç√∫˜µ≤≥÷",
43+
"field_id"=>"CustomObject1574793618883",
44+
"type"=>"Text",
45+
"type_id"=>"1",
46+
"crm_id"=>{"null"=>"true"},
47+
"is_record_multiple_responses"=>"false",
48+
"is_use_values"=>"false",
49+
"created_at"=>"2019-11-26 13:40:37",
50+
"updated_at"=>"2019-11-26 13:40:37"
51+
}
52+
}
53+
assert_authorization_header
54+
end
55+
56+
end
57+
58+
end

spec/pardot/objects/prospects_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def sample_results
5151
end
5252

5353
it "should return the prospect" do
54-
fake_post "/api/prospect/version/3/do/create/email/user@test.com?format=simple&first_name=Jim", sample_results
55-
54+
fake_post "/api/prospect/version/3/do/create/email/user%40test.com?first_name=Jim&format=simple", sample_results
55+
5656
@client.prospects.create("[email protected]", :first_name => "Jim").should == {"last_name"=>"Smith", "first_name"=>"Jim"}
5757
assert_authorization_header
5858
end
5959

6060
end
6161

62-
end
62+
end

0 commit comments

Comments
 (0)