Skip to content

Commit

Permalink
Merge pull request #44 from clearbit/master
Browse files Browse the repository at this point in the history
Add support for querying `customField` objects
  • Loading branch information
adelawalla authored Dec 6, 2019
2 parents d683ab0 + 9f67017 commit d1f2859
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ruby-pardot (1.3.0)
ruby-pardot (1.3.2)
crack (= 0.4.3)
httparty (= 0.13.1)

Expand Down Expand Up @@ -37,4 +37,4 @@ DEPENDENCIES
ruby-pardot!

BUNDLED WITH
2.0.1
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
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
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
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.3.1"
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
58 changes: 58 additions & 0 deletions spec/pardot/objects/custom_fields_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Pardot::Objects::CustomFields do

before do
@client = create_client
end

describe "query" do

def sample_results
%(<?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="ok" version="1.0">
<result>
<total_results>1</total_results>
<customField>
<created_at>2019-11-26 13:40:37</created_at>
<crm_id null="true" />
<field_id>CustomObject1574793618883</field_id>
<id>8932</id>
<is_record_multiple_responses>false</is_record_multiple_responses>
<is_use_values>false</is_use_values>
<name>Ω≈ç√∫˜µ≤≥÷</name>
<type>Text</type>
<type_id>1</type_id>
<updated_at>2019-11-26 13:40:37</updated_at>
</customField>
</result>
</rsp>)
end

before do
@client = create_client
end

it "should take in some arguments" do
fake_get "/api/customField/version/3/do/query?id_greater_than=200&format=simple", sample_results

@client.custom_fields.query(:id_greater_than => 200).should == {"total_results" => 1,
"customField"=>
{
"id"=>"8932",
"name"=>"Ω≈ç√∫˜µ≤≥÷",
"field_id"=>"CustomObject1574793618883",
"type"=>"Text",
"type_id"=>"1",
"crm_id"=>{"null"=>"true"},
"is_record_multiple_responses"=>"false",
"is_use_values"=>"false",
"created_at"=>"2019-11-26 13:40:37",
"updated_at"=>"2019-11-26 13:40:37"
}
}
assert_authorization_header
end

end

end
6 changes: 3 additions & 3 deletions spec/pardot/objects/prospects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def sample_results
end

it "should return the prospect" do
fake_post "/api/prospect/version/3/do/create/email/user@test.com?format=simple&first_name=Jim", sample_results
fake_post "/api/prospect/version/3/do/create/email/user%40test.com?first_name=Jim&format=simple", sample_results

@client.prospects.create("[email protected]", :first_name => "Jim").should == {"last_name"=>"Smith", "first_name"=>"Jim"}
assert_authorization_header
end

end

end
end

0 comments on commit d1f2859

Please sign in to comment.