leadtune 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -29
- data/Rakefile +1 -4
- data/lib/leadtune/config.rb +6 -37
- data/lib/leadtune/prospect.rb +20 -17
- data/lib/leadtune/rest.rb +1 -1
- data/lib/leadtune/util.rb +38 -0
- data/lib/leadtune/version.rb +1 -1
- data/lib/leadtune.rb +8 -7
- data/spec/leadtune/config_spec.rb +16 -11
- data/spec/leadtune/prospect_spec.rb +12 -53
- data/spec/leadtune/rest_spec.rb +14 -98
- data/spec/spec_helper.rb +12 -15
- metadata +5 -6
- data/lib/array_extensions.rb +0 -12
- data/lib/hash_extensions.rb +0 -34
data/README.rdoc
CHANGED
@@ -19,26 +19,6 @@ detailed below. Available configuration values include:
|
|
19
19
|
* password
|
20
20
|
* organization
|
21
21
|
|
22
|
-
=== Configuration File
|
23
|
-
|
24
|
-
The configuration file can be specified when calling Prospect#new. If no
|
25
|
-
file is specified, the gem will also look for +leadtune.yml+ in the
|
26
|
-
current directory.
|
27
|
-
|
28
|
-
==== Format
|
29
|
-
|
30
|
-
The configuration file is a YAML file, an example of which is:
|
31
|
-
username: me@mycorp.com
|
32
|
-
password: my_secret
|
33
|
-
organization: MYC
|
34
|
-
|
35
|
-
=== Environment Variables
|
36
|
-
|
37
|
-
Your LeadTune username, password, and organization can be specified in the
|
38
|
-
+LEADTUNE_USERNAME+, +LEADTUNE_PASSWORD+, and +LEADTUNE_ORGANIZATION+
|
39
|
-
environment variables. <em>These values take precedence over values read
|
40
|
-
from the configuration file.</em>
|
41
|
-
|
42
22
|
=== Rack Initializer
|
43
23
|
|
44
24
|
# config/initializers/leadtune.rb
|
@@ -46,23 +26,19 @@ from the configuration file.</em>
|
|
46
26
|
Leadtune::Config.password = "my_secret"
|
47
27
|
Leadtune::Config.organization = "MYC"
|
48
28
|
|
49
|
-
<em>These values take precedence over values read from environment variables
|
50
|
-
or configuration file.</em>
|
51
|
-
|
52
29
|
=== Factors Hash
|
53
30
|
|
54
31
|
When initializing your Leadtune::Prospect, you can include your username,
|
55
32
|
password, and organization along with any factors you wish to
|
56
|
-
submit. <em>These values take precedence over values read from rack
|
57
|
-
|
33
|
+
submit. <em>These values take precedence over values read from the rack
|
34
|
+
initializer.</em>
|
58
35
|
|
59
36
|
=== Instance Methods
|
60
37
|
|
61
38
|
You can also set your username, password, and organization by calling the
|
62
39
|
Leadtune::Prospect object's #username=, #password=, and #organization=
|
63
40
|
methods. <em>These values take precedence over values read from the factors
|
64
|
-
hash
|
65
|
-
file.</em>
|
41
|
+
hash and the rack initializer.</em>
|
66
42
|
|
67
43
|
== Example Usage
|
68
44
|
|
@@ -97,9 +73,9 @@ An attempt was made to allow for an ActiveModel-like interface.
|
|
97
73
|
... and so on
|
98
74
|
prospect.post
|
99
75
|
|
100
|
-
== Automatic Environment
|
76
|
+
== Automatic Environment Detection
|
101
77
|
|
102
|
-
At initialization, an attempt is made to
|
78
|
+
At initialization, an attempt is made to detect your application's current
|
103
79
|
environment. If a rack or rails production environment is detected, prospects
|
104
80
|
will be posted to LeadTune's production host. Otherwise prospects will be
|
105
81
|
posted to LeadTune's sandbox host. The application environment can be
|
data/Rakefile
CHANGED
data/lib/leadtune/config.rb
CHANGED
@@ -16,10 +16,6 @@ module Leadtune
|
|
16
16
|
@@organization = nil
|
17
17
|
@@timeout = nil
|
18
18
|
|
19
|
-
def initialize(config_file=nil)
|
20
|
-
load_config_file_values(config_file)
|
21
|
-
end
|
22
|
-
|
23
19
|
def self.username=(username)
|
24
20
|
@@username = username
|
25
21
|
end
|
@@ -37,32 +33,27 @@ module Leadtune
|
|
37
33
|
end
|
38
34
|
|
39
35
|
def self.timeout=(timeout)
|
40
|
-
@@timeout = timeout
|
36
|
+
@@timeout = timeout
|
41
37
|
end
|
42
38
|
|
43
39
|
def username
|
44
|
-
@username ||= @@username
|
40
|
+
@username ||= @@username
|
45
41
|
end
|
46
42
|
|
47
43
|
def password
|
48
|
-
@password ||= @@password
|
44
|
+
@password ||= @@password
|
49
45
|
end
|
50
46
|
|
51
47
|
def timeout
|
52
|
-
@timeout ||=
|
53
|
-
ENV["LEADTUNE_TIMEOUT"] ||
|
54
|
-
@config_file_values["timeout"] ||
|
55
|
-
DEFAULT_TIMEOUT).to_i
|
48
|
+
@timeout ||= @@timeout || DEFAULT_TIMEOUT
|
56
49
|
end
|
57
50
|
|
58
51
|
def organization
|
59
|
-
@@organization
|
52
|
+
@@organization
|
60
53
|
end
|
61
54
|
|
62
55
|
def leadtune_host
|
63
|
-
@leadtune_host ||=
|
64
|
-
@config_file_values["host"] ||
|
65
|
-
LEADTUNE_HOSTS[environment])
|
56
|
+
@leadtune_host ||= @@leadtune_host || LEADTUNE_HOSTS[environment]
|
66
57
|
end
|
67
58
|
|
68
59
|
def environment
|
@@ -83,28 +74,6 @@ module Leadtune
|
|
83
74
|
|
84
75
|
private
|
85
76
|
|
86
|
-
def load_config_file_values(config_file)
|
87
|
-
@config_file_values = {}
|
88
|
-
|
89
|
-
find_config_file(config_file) do |config_file|
|
90
|
-
@config_file_values = YAML::load(config_file)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def find_config_file(config_file)
|
95
|
-
case config_file
|
96
|
-
when String
|
97
|
-
yield File.open(config_file)
|
98
|
-
when File, StringIO
|
99
|
-
yield config_file
|
100
|
-
when nil
|
101
|
-
if File.exist?("leadtune.yml")
|
102
|
-
yield File.open("leadtune.yml")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
77
|
DEFAULT_TIMEOUT = 5
|
109
78
|
LEADTUNE_HOST_SANDBOX = "https://sandbox-appraiser.leadtune.com".freeze
|
110
79
|
LEADTUNE_HOST_PRODUCTION = "https://appraiser.leadtune.com".freeze
|
data/lib/leadtune/prospect.rb
CHANGED
@@ -29,18 +29,13 @@ module Leadtune
|
|
29
29
|
class Prospect
|
30
30
|
attr_accessor :decision #:nodoc:
|
31
31
|
|
32
|
-
|
33
|
-
#
|
34
|
-
# [+config_file+] An optional filename or a file-like object
|
35
|
-
# [+factors+] A hash of factors with which to initialize the Prospect
|
36
|
-
|
37
|
-
def initialize(*args, &block)
|
32
|
+
def initialize(options_and_factors={}, &block)
|
38
33
|
@factors = {}
|
39
34
|
@decision = nil
|
40
|
-
@config = Config.new
|
35
|
+
@config = Config.new
|
41
36
|
@rest = Rest.new(@config)
|
42
37
|
|
43
|
-
load_options_and_factors(
|
38
|
+
load_options_and_factors(options_and_factors)
|
44
39
|
block.call(self) if block_given?
|
45
40
|
end
|
46
41
|
|
@@ -48,24 +43,24 @@ module Leadtune
|
|
48
43
|
#
|
49
44
|
# Raises a Leadtune::LeadtuneError if a non-2XX response is received.
|
50
45
|
|
51
|
-
def self.get(
|
52
|
-
new(
|
46
|
+
def self.get(options_and_factors={}, &block)
|
47
|
+
new(options_and_factors, &block).get
|
53
48
|
end
|
54
49
|
|
55
50
|
# Post a prospect to the LeadTune Appraiser service.
|
56
51
|
#
|
57
52
|
# Raises a Leadtune::LeadtuneError if a non-2XX response is received.
|
58
53
|
|
59
|
-
def self.post(
|
60
|
-
new(
|
54
|
+
def self.post(options_and_factors={}, &block)
|
55
|
+
new(options_and_factors, &block).post
|
61
56
|
end
|
62
57
|
|
63
58
|
# Update a prospect from the LeadTune Appraiser service.
|
64
59
|
#
|
65
60
|
# Raises a Leadtune::LeadtuneError if a non-2XX response is received.
|
66
61
|
|
67
|
-
def self.put(
|
68
|
-
new(
|
62
|
+
def self.put(options_and_factors={}, &block)
|
63
|
+
new(options_and_factors, &block).put
|
69
64
|
end
|
70
65
|
|
71
66
|
# Get a prospect from the LeadTune Appraiser service.
|
@@ -159,6 +154,14 @@ module Leadtune
|
|
159
154
|
@config.leadtune_host
|
160
155
|
end
|
161
156
|
|
157
|
+
def timeout=(timeout) #:nodoc:
|
158
|
+
@config.timeout = timeout
|
159
|
+
end
|
160
|
+
|
161
|
+
def timeout #:nodoc:
|
162
|
+
@config.timeout
|
163
|
+
end
|
164
|
+
|
162
165
|
def username=(username)
|
163
166
|
@config.username = username
|
164
167
|
end
|
@@ -167,18 +170,18 @@ module Leadtune
|
|
167
170
|
@config.password = password
|
168
171
|
end
|
169
172
|
|
170
|
-
def response
|
173
|
+
def response #:nodoc:
|
171
174
|
@rest.response
|
172
175
|
end
|
173
176
|
|
174
|
-
def payload
|
177
|
+
def payload #:nodoc:
|
175
178
|
post_data.reject {|k,v| CURL_OPTIONS.include?(k)}
|
176
179
|
end
|
177
180
|
|
178
181
|
|
179
182
|
private
|
180
183
|
|
181
|
-
CURL_OPTIONS = ["username", "password", "timeout", "leadtune_host",]
|
184
|
+
CURL_OPTIONS = ["username", "password", "timeout", "leadtune_host",] #:nodoc:
|
182
185
|
|
183
186
|
def post_data #:nodoc:
|
184
187
|
@factors.merge("decision" => @decision,
|
data/lib/leadtune/rest.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# LeadTune API Ruby Gem
|
2
|
+
#
|
3
|
+
# http://github.com/leadtune/leadtune-ruby
|
4
|
+
# Eric Wollesen (mailto:devs@leadtune.com)
|
5
|
+
# Copyright 2010 LeadTune LLC
|
6
|
+
|
7
|
+
module Leadtune
|
8
|
+
class Util
|
9
|
+
|
10
|
+
# File merb/core_ext/hash.rb, line 87, with slight tweaks
|
11
|
+
|
12
|
+
def self.to_params(hash)
|
13
|
+
params = ''
|
14
|
+
stack = []
|
15
|
+
|
16
|
+
hash.each do |k, v|
|
17
|
+
if v.is_a?(Hash)
|
18
|
+
stack << [k,v]
|
19
|
+
else
|
20
|
+
params << "#{k}=#{v}&"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
stack.each do |parent, sub_hash|
|
25
|
+
sub_hash.each do |k, v|
|
26
|
+
if v.is_a?(Hash)
|
27
|
+
stack << ["#{parent}[#{k}]", v]
|
28
|
+
else
|
29
|
+
params << "#{parent}[#{k}]=#{v}&"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
params.chop! # trailing &
|
35
|
+
params
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/leadtune/version.rb
CHANGED
data/lib/leadtune.rb
CHANGED
@@ -7,10 +7,6 @@
|
|
7
7
|
dir = File.dirname(__FILE__)
|
8
8
|
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
|
9
9
|
|
10
|
-
require "array_extensions"
|
11
|
-
require "hash_extensions"
|
12
|
-
|
13
|
-
|
14
10
|
# For details about the LeadTune API, see: http://leadtune.com/api
|
15
11
|
|
16
12
|
module Leadtune #:nodoc:all
|
@@ -18,19 +14,24 @@ end
|
|
18
14
|
|
19
15
|
# Raised when non-2XX responses are received.
|
20
16
|
class Leadtune::LeadtuneError < RuntimeError
|
21
|
-
|
17
|
+
|
18
|
+
# HTTP status code
|
19
|
+
attr_reader :code
|
20
|
+
|
21
|
+
# Any body text included with the response
|
22
|
+
attr_reader :message
|
22
23
|
|
23
24
|
def initialize(code, message)
|
24
25
|
@code, @message = code, message
|
25
26
|
end
|
26
27
|
|
27
|
-
def to_s
|
28
|
+
def to_s #:nodoc:
|
28
29
|
"#{@code} #{message}"
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
|
33
|
-
|
34
|
+
require "leadtune/util"
|
34
35
|
require "leadtune/prospect"
|
35
36
|
require "leadtune/rest"
|
36
37
|
require "leadtune/appraisals"
|
@@ -6,18 +6,17 @@
|
|
6
6
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
|
-
class Leadtune::Config
|
10
|
-
def self.reset_class_vars
|
11
|
-
@@timeout = nil
|
12
|
-
@@organization = nil
|
13
|
-
@@username = nil
|
14
|
-
@@password = nil
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
9
|
describe Leadtune::Config do
|
19
|
-
before(:each) {
|
20
|
-
after(:each) {
|
10
|
+
before(:each) {teardown_initializer}
|
11
|
+
after(:each) {teardown_initializer}
|
12
|
+
|
13
|
+
it "reads environment from APP_ENV" do
|
14
|
+
ENV["APP_ENV"] = "production"
|
15
|
+
|
16
|
+
subject.environment.should == :production
|
17
|
+
|
18
|
+
ENV.delete("APP_ENV")
|
19
|
+
end
|
21
20
|
|
22
21
|
context("can set") do
|
23
22
|
it "password" do
|
@@ -43,5 +42,11 @@ describe Leadtune::Config do
|
|
43
42
|
|
44
43
|
Leadtune::Config.new.organization.should == "ORG"
|
45
44
|
end
|
45
|
+
|
46
|
+
it "leadtune_host" do
|
47
|
+
Leadtune::Config.leadtune_host = "http://bad_url_for_test"
|
48
|
+
|
49
|
+
Leadtune::Config.new.leadtune_host.should == "http://bad_url_for_test"
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
@@ -15,21 +15,11 @@ describe Leadtune::Prospect do
|
|
15
15
|
"email" => "bar@baz.com",
|
16
16
|
"target_buyers" => ["AcmeU", "Bravo", "ConvU",],
|
17
17
|
"event" => "offers_prepared",}) do |p|
|
18
|
-
# use ||= so we won't override if loaded from
|
18
|
+
# use ||= so we won't override if loaded from initializer
|
19
19
|
p.organization ||= "Foo"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
context("w/ organization from config_file") do
|
24
|
-
subject do
|
25
|
-
Leadtune::Prospect.new(leadtune_config_file)
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#organization" do
|
29
|
-
specify {subject.organization.should == "config_file_org"}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
23
|
context("when presented with an unrecognized factor") do
|
34
24
|
it "creates a setter and a getter by that name" do
|
35
25
|
fail "getter already exists" if subject.respond_to?(:my_new_factor)
|
@@ -43,41 +33,6 @@ describe Leadtune::Prospect do
|
|
43
33
|
end
|
44
34
|
end
|
45
35
|
|
46
|
-
context("w/ organization from ENV") do
|
47
|
-
before(:all) do
|
48
|
-
setup_leadtune_env
|
49
|
-
end
|
50
|
-
|
51
|
-
after(:all) do
|
52
|
-
teardown_leadtune_env
|
53
|
-
end
|
54
|
-
|
55
|
-
subject {Leadtune::Prospect.new}
|
56
|
-
|
57
|
-
describe "#organization" do
|
58
|
-
specify {subject.organization.should == "env_org"}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context("w/ organization from ENV *AND* config_file") do
|
63
|
-
|
64
|
-
before(:all) do
|
65
|
-
setup_leadtune_env
|
66
|
-
end
|
67
|
-
|
68
|
-
after(:all) do
|
69
|
-
teardown_leadtune_env
|
70
|
-
end
|
71
|
-
|
72
|
-
subject {Leadtune::Prospect.new(leadtune_config_file)}
|
73
|
-
|
74
|
-
describe "#organization" do
|
75
|
-
it "uses the ENV value over the config file" do
|
76
|
-
subject.organization.should == "env_org"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
36
|
describe "#get" do
|
82
37
|
before(:each) do
|
83
38
|
stub_request(:any, /.*leadtune.*/).to_return(:body => fake_curb_response)
|
@@ -114,13 +69,6 @@ describe Leadtune::Prospect do
|
|
114
69
|
|
115
70
|
s.channel.should == "banner"
|
116
71
|
end
|
117
|
-
|
118
|
-
it "accepts a config_file as its (optional) first argument" do
|
119
|
-
s = Leadtune::Prospect.new(leadtune_config_file, {:channel => "banner",})
|
120
|
-
|
121
|
-
s.channel.should == "banner"
|
122
|
-
s.organization.should == "config_file_org"
|
123
|
-
end
|
124
72
|
end
|
125
73
|
|
126
74
|
describe("#target_buyers=") do
|
@@ -136,6 +84,17 @@ describe Leadtune::Prospect do
|
|
136
84
|
end
|
137
85
|
end
|
138
86
|
|
87
|
+
context("w/ organization from initializer") do
|
88
|
+
before(:each) {setup_initializer}
|
89
|
+
after(:each) {teardown_initializer}
|
90
|
+
|
91
|
+
describe("#organization") do
|
92
|
+
it "uses the initializer value" do
|
93
|
+
subject.organization.should == "init_org"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
139
98
|
|
140
99
|
private
|
141
100
|
|
data/spec/leadtune/rest_spec.rb
CHANGED
@@ -14,94 +14,35 @@ describe Leadtune::Rest do
|
|
14
14
|
|
15
15
|
subject {Leadtune::Rest.new(Leadtune::Config.new)}
|
16
16
|
|
17
|
-
context("w/ username
|
18
|
-
|
19
|
-
subject {Leadtune::Rest.new(rest_config)}
|
17
|
+
context("w/ username and password from initializer") do
|
20
18
|
|
21
19
|
before(:each) do
|
22
20
|
@curl_easy = null_curl_easy
|
21
|
+
setup_initializer
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
@curl_easy.should_receive(:username=).with("config@config.com")
|
28
|
-
|
29
|
-
subject.get(mock_post_data)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#password" do
|
34
|
-
it "uses the config_file value" do
|
35
|
-
@curl_easy.should_receive(:password=).with("config_secret")
|
36
|
-
|
37
|
-
subject.get(mock_post_data)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context("w/ username & password from ENV") do
|
43
|
-
before(:all) do
|
44
|
-
setup_leadtune_env
|
45
|
-
end
|
46
|
-
|
47
|
-
after(:all) do
|
48
|
-
teardown_leadtune_env
|
49
|
-
end
|
50
|
-
|
51
|
-
before(:each) do
|
52
|
-
@curl_easy = null_curl_easy
|
24
|
+
after(:each) do
|
25
|
+
teardown_initializer
|
53
26
|
end
|
54
27
|
|
55
28
|
describe "#username" do
|
56
|
-
it "uses the
|
57
|
-
@curl_easy.should_receive(:username=).with("
|
58
|
-
|
59
|
-
subject.get(mock_post_data)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#password" do
|
64
|
-
it "uses the ENV value" do
|
65
|
-
@curl_easy.should_receive(:password=).with("env_secret")
|
66
|
-
|
67
|
-
subject.get(mock_post_data)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context("w/ username & password from ENV *AND* config_file") do
|
73
|
-
|
74
|
-
subject {Leadtune::Rest.new(rest_config)}
|
75
|
-
|
76
|
-
before(:all) do
|
77
|
-
setup_leadtune_env
|
78
|
-
end
|
79
|
-
|
80
|
-
after(:all) do
|
81
|
-
teardown_leadtune_env
|
82
|
-
end
|
83
|
-
|
84
|
-
before(:each) do
|
85
|
-
@curl_easy = null_curl_easy
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "#username" do
|
89
|
-
it "uses the ENV value over the config file" do
|
90
|
-
@curl_easy.should_receive(:username=).with("env@env.com")
|
29
|
+
it "uses the initializer value" do
|
30
|
+
@curl_easy.should_receive(:username=).with("init_user")
|
91
31
|
|
92
32
|
subject.get(mock_post_data)
|
93
33
|
end
|
94
34
|
end
|
95
35
|
|
96
36
|
describe "#password" do
|
97
|
-
it "uses the
|
98
|
-
@curl_easy.should_receive(:password=).with("
|
37
|
+
it "uses the initializer value" do
|
38
|
+
@curl_easy.should_receive(:password=).with("init_secret")
|
99
39
|
|
100
40
|
subject.get(mock_post_data)
|
101
41
|
end
|
102
42
|
end
|
103
43
|
end
|
104
44
|
|
45
|
+
|
105
46
|
describe "#post (slow)" do
|
106
47
|
|
107
48
|
before(:all) {WebMock.allow_net_connect!}
|
@@ -123,12 +64,6 @@ describe Leadtune::Rest do
|
|
123
64
|
@curl_easy = null_curl_easy
|
124
65
|
end
|
125
66
|
|
126
|
-
it "is passed on to Curl::Easy" do
|
127
|
-
@curl_easy.should_receive(:timeout=).with(5)
|
128
|
-
|
129
|
-
subject.get(mock_post_data)
|
130
|
-
end
|
131
|
-
|
132
67
|
context("by default") do
|
133
68
|
it "is 5" do
|
134
69
|
@curl_easy.should_receive(:timeout=).with(5)
|
@@ -137,25 +72,15 @@ describe Leadtune::Rest do
|
|
137
72
|
end
|
138
73
|
end
|
139
74
|
|
140
|
-
context("with timeout of
|
141
|
-
before(:
|
142
|
-
|
75
|
+
context("with timeout of 7 in initializer") do
|
76
|
+
before(:each) do
|
77
|
+
setup_initializer
|
143
78
|
end
|
144
79
|
|
145
|
-
after(:
|
146
|
-
|
80
|
+
after(:each) do
|
81
|
+
teardown_initializer
|
147
82
|
end
|
148
83
|
|
149
|
-
it "is 6" do
|
150
|
-
@curl_easy.should_receive(:timeout=).with(6)
|
151
|
-
|
152
|
-
subject.get(mock_post_data)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context("with timeout of 7 in config_file") do
|
157
|
-
subject {Leadtune::Rest.new(rest_config)}
|
158
|
-
|
159
84
|
it "is 7" do
|
160
85
|
@curl_easy.should_receive(:timeout=).with(7)
|
161
86
|
|
@@ -199,15 +124,6 @@ describe Leadtune::Rest do
|
|
199
124
|
curl_easy
|
200
125
|
end
|
201
126
|
|
202
|
-
def rest_config
|
203
|
-
config_file = StringIO.new <<EOF
|
204
|
-
username: config@config.com
|
205
|
-
password: config_secret
|
206
|
-
timeout: 7
|
207
|
-
EOF
|
208
|
-
Leadtune::Config.new(config_file)
|
209
|
-
end
|
210
|
-
|
211
127
|
def mock_server(code, &block)
|
212
128
|
quietly do
|
213
129
|
server = WEBrick::HTTPServer.new(:Port => THREADED_MOCK_SERVER_PORT)
|
data/spec/spec_helper.rb
CHANGED
@@ -14,22 +14,19 @@ RSpec.configure do |config|
|
|
14
14
|
config.include WebMock
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def setup_initializer
|
18
|
+
Leadtune::Config.username = "init_user"
|
19
|
+
Leadtune::Config.password = "init_secret"
|
20
|
+
Leadtune::Config.timeout = 7
|
21
|
+
Leadtune::Config.organization = "init_org"
|
22
|
+
Leadtune::Config.leadtune_host = "http://localhost.init"
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def teardown_initializer
|
26
|
+
Leadtune::Config.username = nil
|
27
|
+
Leadtune::Config.password = nil
|
28
|
+
Leadtune::Config.timeout = nil
|
29
|
+
Leadtune::Config.organization = nil
|
30
|
+
Leadtune::Config.leadtune_host = nil
|
27
31
|
end
|
28
32
|
|
29
|
-
def leadtune_config_file
|
30
|
-
StringIO.new <<EOF
|
31
|
-
username: config_file@config_file.com
|
32
|
-
password: config_file_secret
|
33
|
-
organization: config_file_org
|
34
|
-
EOF
|
35
|
-
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leadtune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Wollesen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-21 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -221,13 +221,12 @@ files:
|
|
221
221
|
- README.rdoc
|
222
222
|
- Rakefile
|
223
223
|
- leadtune.gemspec
|
224
|
-
- lib/array_extensions.rb
|
225
|
-
- lib/hash_extensions.rb
|
226
224
|
- lib/leadtune.rb
|
227
225
|
- lib/leadtune/appraisals.rb
|
228
226
|
- lib/leadtune/config.rb
|
229
227
|
- lib/leadtune/prospect.rb
|
230
228
|
- lib/leadtune/rest.rb
|
229
|
+
- lib/leadtune/util.rb
|
231
230
|
- lib/leadtune/version.rb
|
232
231
|
- spec/echo_server.rb
|
233
232
|
- spec/get.rb
|
data/lib/array_extensions.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# LeadTune API Ruby Gem
|
2
|
-
#
|
3
|
-
# http://github.com/leadtune/leadtune-ruby
|
4
|
-
# Eric Wollesen (mailto:devs@leadtune.com)
|
5
|
-
# Copyright 2010 LeadTune LLC
|
6
|
-
|
7
|
-
class Array
|
8
|
-
# stolen from ActiveSupport
|
9
|
-
def extract_options!
|
10
|
-
last.is_a?(::Hash) ? pop : {}
|
11
|
-
end
|
12
|
-
end
|
data/lib/hash_extensions.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# LeadTune API Ruby Gem
|
2
|
-
#
|
3
|
-
# http://github.com/leadtune/leadtune-ruby
|
4
|
-
# Eric Wollesen (mailto:devs@leadtune.com)
|
5
|
-
# Copyright 2010 LeadTune LLC
|
6
|
-
|
7
|
-
class Hash
|
8
|
-
# File merb/core_ext/hash.rb, line 87
|
9
|
-
def to_params
|
10
|
-
params = ''
|
11
|
-
stack = []
|
12
|
-
|
13
|
-
each do |k, v|
|
14
|
-
if v.is_a?(Hash)
|
15
|
-
stack << [k,v]
|
16
|
-
else
|
17
|
-
params << "#{k}=#{v}&"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
stack.each do |parent, hash|
|
22
|
-
hash.each do |k, v|
|
23
|
-
if v.is_a?(Hash)
|
24
|
-
stack << ["#{parent}[#{k}]", v]
|
25
|
-
else
|
26
|
-
params << "#{parent}[#{k}]=#{v}&"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
params.chop! # trailing &
|
32
|
-
params
|
33
|
-
end
|
34
|
-
end
|