leadtune 0.0.1 → 0.0.2
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/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/README.rdoc +17 -4
- data/leadtune.gemspec +13 -1
- data/lib/leadtune.rb +12 -1
- data/lib/leadtune/config.rb +31 -4
- data/lib/leadtune/prospect.rb +19 -8
- data/lib/leadtune/rest.rb +14 -6
- data/lib/leadtune/version.rb +1 -1
- data/spec/leadtune/config_spec.rb +47 -0
- metadata +174 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -32,7 +32,6 @@ GEM
|
|
32
32
|
json (1.4.6)
|
33
33
|
json_pure (1.4.6)
|
34
34
|
linecache (0.43)
|
35
|
-
rack (1.2.1)
|
36
35
|
rake (0.8.7)
|
37
36
|
rdoc (2.5.11)
|
38
37
|
rspec (2.0.0.beta.19)
|
@@ -60,7 +59,6 @@ DEPENDENCIES
|
|
60
59
|
cucumber
|
61
60
|
curb
|
62
61
|
json
|
63
|
-
rack
|
64
62
|
rake
|
65
63
|
rdoc
|
66
64
|
rspec (= 2.0.0.beta.19)
|
data/README.rdoc
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
http://github.com/leadtune/leadtune-ruby
|
4
4
|
|
5
|
+
https://rubygems.org/gems/leadtune
|
6
|
+
|
5
7
|
Copyright 2010 LeadTune, LLC
|
6
8
|
|
7
9
|
Eric Wollesen (mailto:devs@leadtune.com)
|
@@ -37,19 +39,30 @@ Your LeadTune username, password, and organization can be specified in the
|
|
37
39
|
environment variables. <em>These values take precedence over values read
|
38
40
|
from the configuration file.</em>
|
39
41
|
|
42
|
+
=== Rack Initializer
|
43
|
+
|
44
|
+
# config/initializers/leadtune.rb
|
45
|
+
Leadtune::Config.username = "me@mycorp.com"
|
46
|
+
Leadtune::Config.password = "my_secret"
|
47
|
+
Leadtune::Config.organization = "MYC"
|
48
|
+
|
49
|
+
<em>These values take precedence over values read from environment variables
|
50
|
+
or configuration file.</em>
|
51
|
+
|
40
52
|
=== Factors Hash
|
41
53
|
|
42
54
|
When initializing your Leadtune::Prospect, you can include your username,
|
43
55
|
password, and organization along with any factors you wish to
|
44
|
-
submit. <em>These values take precedence over values read from
|
45
|
-
variables, or the configuration file.</em>
|
56
|
+
submit. <em>These values take precedence over values read from rack
|
57
|
+
initializers, environment variables, or the configuration file.</em>
|
46
58
|
|
47
59
|
=== Instance Methods
|
48
60
|
|
49
61
|
You can also set your username, password, and organization by calling the
|
50
62
|
Leadtune::Prospect object's #username=, #password=, and #organization=
|
51
|
-
methods. <em>These values take precedence over values read from
|
52
|
-
|
63
|
+
methods. <em>These values take precedence over values read from the factors
|
64
|
+
hash, rack initializers, environment variables, or the configuration
|
65
|
+
file.</em>
|
53
66
|
|
54
67
|
== Example Usage
|
55
68
|
|
data/leadtune.gemspec
CHANGED
@@ -20,7 +20,19 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.required_rubygems_version = ">= 1.3.6"
|
22
22
|
|
23
|
-
s.add_development_dependency "bundler", ">= 1.0.0"
|
23
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
24
|
+
s.add_development_dependency "ruby-debug"
|
25
|
+
s.add_development_dependency "rspec", "= 2.0.0.beta.19"
|
26
|
+
s.add_development_dependency "rspec-core", "= 2.0.0.beta.19"
|
27
|
+
s.add_development_dependency "rspec-expectations", "= 2.0.0.beta.19"
|
28
|
+
s.add_development_dependency "rspec-mocks", "= 2.0.0.beta.19"
|
29
|
+
s.add_development_dependency "webmock"#, "http://github.com/phiggins/webmock.git"
|
30
|
+
|
31
|
+
s.add_dependency("rake")
|
32
|
+
s.add_dependency("curb")
|
33
|
+
s.add_dependency("json")
|
34
|
+
s.add_dependency("tcpsocket-wait")
|
35
|
+
s.add_dependency("activemodel")
|
24
36
|
|
25
37
|
s.files = `git ls-files`.split("\n")
|
26
38
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
data/lib/leadtune.rb
CHANGED
@@ -17,7 +17,18 @@ module Leadtune #:nodoc:all
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Raised when non-2XX responses are received.
|
20
|
-
class Leadtune::LeadtuneError < RuntimeError
|
20
|
+
class Leadtune::LeadtuneError < RuntimeError
|
21
|
+
attr_reader :code, :message
|
22
|
+
|
23
|
+
def initialize(code, message)
|
24
|
+
@code, @message = code, message
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
"#{@code} #{message}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
21
32
|
|
22
33
|
|
23
34
|
require "leadtune/prospect"
|
data/lib/leadtune/config.rb
CHANGED
@@ -10,26 +10,53 @@ module Leadtune
|
|
10
10
|
|
11
11
|
attr_accessor :environment, :leadtune_host, :username, :password, :timeout
|
12
12
|
|
13
|
+
@@leadtune_host = nil
|
14
|
+
@@username = nil
|
15
|
+
@@password = nil
|
16
|
+
@@organization = nil
|
17
|
+
@@timeout = nil
|
18
|
+
|
13
19
|
def initialize(config_file=nil)
|
14
20
|
load_config_file_values(config_file)
|
15
21
|
end
|
16
22
|
|
23
|
+
def self.username=(username)
|
24
|
+
@@username = username
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.password=(password)
|
28
|
+
@@password = password
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.organization=(organization)
|
32
|
+
@@organization = organization
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.leadtune_host=(leadtune_host)
|
36
|
+
@@leadtune_host = leadtune_host
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.timeout=(timeout)
|
40
|
+
@@timeout = timeout.to_i
|
41
|
+
end
|
42
|
+
|
17
43
|
def username
|
18
|
-
@username ||= ENV["LEADTUNE_USERNAME"] || @config_file_values["username"]
|
44
|
+
@username ||= @@username || ENV["LEADTUNE_USERNAME"] || @config_file_values["username"]
|
19
45
|
end
|
20
46
|
|
21
47
|
def password
|
22
|
-
@password ||= ENV["LEADTUNE_PASSWORD"] || @config_file_values["password"]
|
48
|
+
@password ||= @@password || ENV["LEADTUNE_PASSWORD"] || @config_file_values["password"]
|
23
49
|
end
|
24
50
|
|
25
51
|
def timeout
|
26
|
-
@timeout ||= (
|
52
|
+
@timeout ||= (@@timeout ||
|
53
|
+
ENV["LEADTUNE_TIMEOUT"] ||
|
27
54
|
@config_file_values["timeout"] ||
|
28
55
|
DEFAULT_TIMEOUT).to_i
|
29
56
|
end
|
30
57
|
|
31
58
|
def organization
|
32
|
-
ENV["LEADTUNE_ORGANIZATION"] || @config_file_values["organization"]
|
59
|
+
@@organization || ENV["LEADTUNE_ORGANIZATION"] || @config_file_values["organization"]
|
33
60
|
end
|
34
61
|
|
35
62
|
def leadtune_host
|
data/lib/leadtune/prospect.rb
CHANGED
@@ -140,7 +140,7 @@ module Leadtune
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def organization #:nodoc:
|
143
|
-
@factors["organization"]
|
143
|
+
@factors["organization"] || @config.organization
|
144
144
|
end
|
145
145
|
|
146
146
|
def prospect_id #:nodoc:
|
@@ -167,23 +167,33 @@ module Leadtune
|
|
167
167
|
@config.password = password
|
168
168
|
end
|
169
169
|
|
170
|
+
def response
|
171
|
+
@rest.response
|
172
|
+
end
|
173
|
+
|
174
|
+
def payload
|
175
|
+
post_data.reject {|k,v| CURL_OPTIONS.include?(k)}
|
176
|
+
end
|
177
|
+
|
170
178
|
|
171
179
|
private
|
172
180
|
|
181
|
+
CURL_OPTIONS = ["username", "password", "timeout", "leadtune_host",]
|
182
|
+
|
173
183
|
def post_data #:nodoc:
|
174
|
-
@factors.merge("decision" => decision
|
184
|
+
@factors.merge("decision" => @decision,
|
185
|
+
"organization" => @config.organization)
|
175
186
|
end
|
176
187
|
|
177
188
|
def load_options_and_factors(options) #:nodoc:
|
178
|
-
|
189
|
+
load_curl_options(options)
|
179
190
|
load_factors(options)
|
180
191
|
end
|
181
192
|
|
182
|
-
def
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
@config.leadtune_host = options.delete("timeout") if options["leadtune_host"]
|
193
|
+
def load_curl_options(options) #:nodoc:
|
194
|
+
CURL_OPTIONS.each do |option|
|
195
|
+
@config.send("#{option}=", options.delete(option)) if options[option]
|
196
|
+
end
|
187
197
|
end
|
188
198
|
|
189
199
|
def load_factors(factors) #:nodoc:
|
@@ -193,6 +203,7 @@ module Leadtune
|
|
193
203
|
end
|
194
204
|
|
195
205
|
def parse_response(response) #:nodoc:
|
206
|
+
response = response.dup
|
196
207
|
load_decision(response)
|
197
208
|
load_factors(response)
|
198
209
|
end
|
data/lib/leadtune/rest.rb
CHANGED
@@ -9,30 +9,33 @@ require "json"
|
|
9
9
|
module Leadtune
|
10
10
|
class Rest #:nodoc:all
|
11
11
|
|
12
|
+
attr_reader :response
|
13
|
+
|
12
14
|
def initialize(config)
|
13
15
|
@config = config
|
14
16
|
@post_data = nil
|
17
|
+
@response = {}
|
15
18
|
end
|
16
19
|
|
17
20
|
def get(post_data)
|
18
21
|
@post_data = post_data
|
19
22
|
curl = build_curl_easy_object_get
|
20
23
|
curl.http("GET")
|
21
|
-
|
24
|
+
parse_response(curl.body_str)
|
22
25
|
end
|
23
26
|
|
24
27
|
def post(post_data)
|
25
28
|
@post_data = post_data
|
26
29
|
curl = build_curl_easy_object_post
|
27
30
|
curl.http("POST")
|
28
|
-
|
31
|
+
parse_response(curl.body_str)
|
29
32
|
end
|
30
33
|
|
31
34
|
def put(post_data)
|
32
35
|
@post_data = post_data
|
33
36
|
curl = build_curl_easy_object_put
|
34
37
|
curl.http("PUT")
|
35
|
-
|
38
|
+
parse_response(curl.body_str)
|
36
39
|
end
|
37
40
|
|
38
41
|
|
@@ -46,9 +49,9 @@ module Leadtune
|
|
46
49
|
curl.timeout = @config.timeout
|
47
50
|
curl.headers = default_headers
|
48
51
|
curl.on_failure do |curl, code|
|
49
|
-
raise LeadtuneError.new(
|
52
|
+
raise LeadtuneError.new(curl.response_code, curl.body_str)
|
50
53
|
end
|
51
|
-
#curl.verbose = true
|
54
|
+
# curl.verbose = true
|
52
55
|
yield curl
|
53
56
|
end
|
54
57
|
end
|
@@ -62,14 +65,15 @@ module Leadtune
|
|
62
65
|
build_curl_easy_object do |curl|
|
63
66
|
curl.url = URI.join(@config.leadtune_host, "/prospects").to_s
|
64
67
|
curl.post_body = @post_data.to_json
|
68
|
+
$stderr.puts curl.post_body if curl.verbose?
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
68
72
|
def build_curl_easy_object_put #:nodoc:
|
69
73
|
build_curl_easy_object do |curl|
|
70
74
|
curl.url = build_put_url
|
71
|
-
#curl.verbose = true
|
72
75
|
curl.put_data = @post_data.to_json
|
76
|
+
$stderr.puts curl.post_body if curl.verbose?
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
@@ -94,5 +98,9 @@ module Leadtune
|
|
94
98
|
URI.join(@config.leadtune_host, path).to_s
|
95
99
|
end
|
96
100
|
|
101
|
+
def parse_response(body)
|
102
|
+
@response = body ? JSON::parse(body) : {}
|
103
|
+
end
|
104
|
+
|
97
105
|
end
|
98
106
|
end
|
data/lib/leadtune/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
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
|
+
require "spec_helper"
|
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
|
+
describe Leadtune::Config do
|
19
|
+
before(:each) {Leadtune::Config.reset_class_vars}
|
20
|
+
after(:each) {Leadtune::Config.reset_class_vars}
|
21
|
+
|
22
|
+
context("can set") do
|
23
|
+
it "password" do
|
24
|
+
Leadtune::Config.password = "secret"
|
25
|
+
|
26
|
+
Leadtune::Config.new.password.should == "secret"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "username" do
|
30
|
+
Leadtune::Config.username = "bob"
|
31
|
+
|
32
|
+
Leadtune::Config.new.username.should == "bob"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "timeout" do
|
36
|
+
Leadtune::Config.timeout = 5
|
37
|
+
|
38
|
+
Leadtune::Config.new.timeout.should == 5
|
39
|
+
end
|
40
|
+
|
41
|
+
it "organization" do
|
42
|
+
Leadtune::Config.organization = "ORG"
|
43
|
+
|
44
|
+
Leadtune::Config.new.organization.should == "ORG"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Wollesen
|
@@ -34,6 +34,176 @@ dependencies:
|
|
34
34
|
type: :development
|
35
35
|
name: bundler
|
36
36
|
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
requirement: *id002
|
48
|
+
type: :development
|
49
|
+
name: ruby-debug
|
50
|
+
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - "="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 62196421
|
58
|
+
segments:
|
59
|
+
- 2
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
- beta
|
63
|
+
- 19
|
64
|
+
version: 2.0.0.beta.19
|
65
|
+
requirement: *id003
|
66
|
+
type: :development
|
67
|
+
name: rspec
|
68
|
+
prerelease: false
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - "="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 62196421
|
76
|
+
segments:
|
77
|
+
- 2
|
78
|
+
- 0
|
79
|
+
- 0
|
80
|
+
- beta
|
81
|
+
- 19
|
82
|
+
version: 2.0.0.beta.19
|
83
|
+
requirement: *id004
|
84
|
+
type: :development
|
85
|
+
name: rspec-core
|
86
|
+
prerelease: false
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - "="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 62196421
|
94
|
+
segments:
|
95
|
+
- 2
|
96
|
+
- 0
|
97
|
+
- 0
|
98
|
+
- beta
|
99
|
+
- 19
|
100
|
+
version: 2.0.0.beta.19
|
101
|
+
requirement: *id005
|
102
|
+
type: :development
|
103
|
+
name: rspec-expectations
|
104
|
+
prerelease: false
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - "="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 62196421
|
112
|
+
segments:
|
113
|
+
- 2
|
114
|
+
- 0
|
115
|
+
- 0
|
116
|
+
- beta
|
117
|
+
- 19
|
118
|
+
version: 2.0.0.beta.19
|
119
|
+
requirement: *id006
|
120
|
+
type: :development
|
121
|
+
name: rspec-mocks
|
122
|
+
prerelease: false
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirement: *id007
|
134
|
+
type: :development
|
135
|
+
name: webmock
|
136
|
+
prerelease: false
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirement: *id008
|
148
|
+
type: :runtime
|
149
|
+
name: rake
|
150
|
+
prerelease: false
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
|
+
requirement: *id009
|
162
|
+
type: :runtime
|
163
|
+
name: curb
|
164
|
+
prerelease: false
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
175
|
+
requirement: *id010
|
176
|
+
type: :runtime
|
177
|
+
name: json
|
178
|
+
prerelease: false
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
hash: 3
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
requirement: *id011
|
190
|
+
type: :runtime
|
191
|
+
name: tcpsocket-wait
|
192
|
+
prerelease: false
|
193
|
+
- !ruby/object:Gem::Dependency
|
194
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
195
|
+
none: false
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
hash: 3
|
200
|
+
segments:
|
201
|
+
- 0
|
202
|
+
version: "0"
|
203
|
+
requirement: *id012
|
204
|
+
type: :runtime
|
205
|
+
name: activemodel
|
206
|
+
prerelease: false
|
37
207
|
description: LeadTune Ruby API Gem
|
38
208
|
email:
|
39
209
|
- devs@leadtune.com
|
@@ -62,6 +232,7 @@ files:
|
|
62
232
|
- spec/echo_server.rb
|
63
233
|
- spec/get.rb
|
64
234
|
- spec/leadtune/appraisals_spec.rb
|
235
|
+
- spec/leadtune/config_spec.rb
|
65
236
|
- spec/leadtune/prospect_spec.rb
|
66
237
|
- spec/leadtune/rest_spec.rb
|
67
238
|
- spec/post.rb
|