Skip to content

Commit

Permalink
Version 0.0.9
Browse files Browse the repository at this point in the history
  * Allows one to add arbitrary query string parameters to POST prospect
  • Loading branch information
John David Eriksen committed Mar 1, 2011
1 parent d369bcf commit dbf64e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Expand Up @@ -57,15 +57,15 @@ An attempt was made to allow for an ActiveModel-like interface.

prospect = Leadtune::Prospect.post do |p|
p.event = "offers_prepared"
p.email = "test@example.com"
p.email = "test@example.com"
... and so on
end

<em>Or even</em>

prospect = Leadtune::Prospect.new
prospect.event = "offers_prepared"
prosepct.email = "test@example.com"
prospect.email = "test@example.com"
... and so on
prospect.post

Expand Down
12 changes: 10 additions & 2 deletions lib/leadtune/config.rb
Expand Up @@ -7,13 +7,13 @@
module Leadtune

class Config #:nodoc:all

attr_accessor :environment, :leadtune_host, :api_key, :timeout
attr_accessor :environment, :leadtune_host, :api_key, :timeout, :query_params

@@leadtune_host = nil
@@api_key = nil
@@organization = nil
@@timeout = nil
@@query_params = nil

def self.api_key=(api_key)
@@api_key = api_key
Expand All @@ -31,6 +31,10 @@ def self.timeout=(timeout)
@@timeout = timeout
end

def self.query_params=(query_params)
@@query_params = query_params
end

def api_key
@api_key ||= @@api_key
end
Expand All @@ -39,6 +43,10 @@ def timeout
@timeout ||= @@timeout || DEFAULT_TIMEOUT
end

def query_params
@query_params ||= @@query_params
end

def organization
@@organization
end
Expand Down
13 changes: 11 additions & 2 deletions lib/leadtune/rest.rb
Expand Up @@ -9,6 +9,7 @@

module Leadtune
class Rest #:nodoc:all
PROSPECTS_PATH = "/prospects"

attr_reader :response

Expand Down Expand Up @@ -95,8 +96,16 @@ def build_curl_easy_object_get #:nodoc:
end
end

def build_optional_query_params
if @config.query_params
"?" + Leadtune::Util.to_params(@config.query_params)
else
""
end
end

def build_post_url #:nodoc:
URI.join(@config.leadtune_host, "/prospects").to_s
URI.join(@config.leadtune_host, PROSPECTS_PATH, build_optional_query_params).to_s
end

def build_get_url #:nodoc:
Expand All @@ -110,7 +119,7 @@ def build_get_url #:nodoc:
end

def build_put_url #:nodoc:
path = "/prospects"
path = PROSPECTS_PATH
path += "/#{@post_data["prospect_id"]}" if @post_data["prospect_id"]
# I would use URI.join, but there's a bug in its implementation in 1.8.6
@config.leadtune_host + path
Expand Down
6 changes: 6 additions & 0 deletions spec/leadtune/config_spec.rb
Expand Up @@ -42,5 +42,11 @@

Leadtune::Config.new.leadtune_host.should == "http://bad_url_for_test"
end

it "query_params" do
Leadtune::Config.query_params = {"foo" => "bar"}

Leadtune::Config.new.query_params.should == {"foo" => "bar"}
end
end
end

0 comments on commit dbf64e8

Please sign in to comment.