Skip to content
Browse files

added support for create, read, query, update lists

  • Loading branch information...
1 parent e5ceeff commit 278d7a79e86b9880e96bdc7601a2ab664ead5ede @znbailey znbailey committed May 17, 2011
Showing with 97 additions and 3 deletions.
  1. +1 −0 README.rdoc
  2. +4 −3 lib/pardot/client.rb
  3. +50 −0 lib/pardot/objects/lists.rb
  4. +1 −0 lib/ruby-pardot.rb
  5. +41 −0 spec/pardot/objects/lists_spec.rb
View
1 README.rdoc
@@ -20,6 +20,7 @@ The client will authenticate before performing other API calls, but you can manu
The available objects are:
+* lists
* opportunities
* prospects
* users
View
7 lib/pardot/client.rb
@@ -8,11 +8,12 @@ class Client
include Authentication
include Http
-
- include Objects::Prospects
+
+ include Objects::Lists
include Objects::Opportunities
- include Objects::Visitors
+ include Objects::Prospects
include Objects::Users
+ include Objects::Visitors
include Objects::Visits
include Objects::VisitorActivities
View
50 lib/pardot/objects/lists.rb
@@ -0,0 +1,50 @@
+module Pardot
+ module Objects
+
+ module Lists
+
+ def lists
+ @lists ||= Lists.new self
+ end
+
+ class Lists
+
+ def initialize client
+ @client = client
+ end
+
+ def create id, params = {}
+ post "/do/create", params
+ end
+
+ def query params
+ result = get "/do/query", params, "result"
+ result["total_results"] = result["total_results"].to_i if result["total_results"]
+ result
+ end
+
+ def read_by_id id, params = {}
+ get "/do/read/id/#{id}", params
+ end
+
+ def update id, params = {}
+ post "/do/update/#{id}"
+ end
+
+ protected
+
+ def get path, params = {}, result = "list"
+ response = @client.get "list", path, params
+ result ? response[result] : response
+ end
+
+ def post path, params = {}, result = "list"
+ response = @client.post "list", path, params
+ result ? response[result] : response
+ end
+
+ end
+
+ end
+ end
+end
View
1 lib/ruby-pardot.rb
@@ -8,6 +8,7 @@
require 'pardot/error'
require 'pardot/authentication'
+require 'pardot/objects/lists'
require 'pardot/objects/opportunities'
require 'pardot/objects/prospects'
require 'pardot/objects/users'
View
41 spec/pardot/objects/lists_spec.rb
@@ -0,0 +1,41 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe Pardot::Objects::Lists 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>2</total_results>
+ <list>
+ <name>Asdf List</name>
+ </list>
+ <list>
+ <name>Qwerty List</name>
+ </list>
+ </result>
+ </rsp>)
+ end
+
+ before do
+ @client = create_client
+ end
+
+ it "should take in some arguments" do
+ fake_get "/api/list/version/3/do/query?api_key=my_api_key&id_greater_than=200&format=simple&user_key=bar", sample_results
+
+ @client.lists.query(:id_greater_than => 200).should == {"total_results" => 2,
+ "list"=>[
+ {"name"=>"Asdf List"},
+ {"name"=>"Qwerty List"}
+ ]}
+ end
+
+ end
+
+end

0 comments on commit 278d7a7

Please sign in to comment.
Something went wrong with that request. Please try again.