Class: Leadtune::Prospect
- Inherits:
-
Object
- Object
- Leadtune::Prospect
- Defined in:
- lib/leadtune/prospect.rb
Overview
Simplify the process of submitting prospects to LeadTune for duplicate checking and appraisal.
For details about the LeadTune API, see: leadtune.com/api
Dynamic Factor Access
Getter and setter methods are dynamically defined for factors as they’re set. See leadtune.com/factors for a list of LeadTune recognized factors.
Instance Attribute Summary collapse
-
#decision ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.delete(options_and_factors = {}, &block) ⇒ Object
Delete a prospect from the LeadTune Appraiser service.
-
.get(options_and_factors = {}, &block) ⇒ Object
Get a prospect from the LeadTune Appraiser service.
-
.post(options_and_factors = {}, &block) ⇒ Object
Post a prospect to the LeadTune Appraiser service.
-
.put(options_and_factors = {}, &block) ⇒ Object
Update a prospect from the LeadTune Appraiser service.
Instance Method Summary collapse
- #api_key=(api_key) ⇒ Object
-
#appraisals ⇒ Object
The appraisals for this Prospect.
-
#decision_id ⇒ Object
The unique
decision_id
for this prospect. -
#delete ⇒ Object
Delete a prospect from the LeadTune Appraiser service.
-
#factors ⇒ Object
Return a hash of the factors specified for this Prospect.
-
#get ⇒ Object
Get a prospect from the LeadTune Appraiser service.
-
#initialize(options_and_factors = {}, &block) ⇒ Prospect
constructor
A new instance of Prospect.
-
#leadtune_host ⇒ Object
:nodoc:.
-
#leadtune_host=(host) ⇒ Object
:nodoc:.
-
#organization ⇒ Object
:nodoc:.
-
#payload ⇒ Object
:nodoc:.
-
#post ⇒ Object
Post this prospect to the LeadTune Appraiser service.
-
#prospect_id ⇒ Object
:nodoc:.
-
#prospect_ref ⇒ Object
:nodoc:.
-
#put ⇒ Object
Update a prospect from the LeadTune Appraiser service.
-
#response ⇒ Object
:nodoc:.
-
#target_buyers ⇒ Object
Return an array of organization codes for the prospect’s target buyers.
-
#target_buyers=(target_buyers) ⇒ Object
Assign an array of organization codes for the prospect’s target buyers.
-
#timeout ⇒ Object
:nodoc:.
-
#timeout=(timeout) ⇒ Object
:nodoc:.
Constructor Details
#initialize(options_and_factors = {}, &block) ⇒ Prospect
Returns a new instance of Prospect.
32 33 34 35 36 37 38 39 40 |
# File 'lib/leadtune/prospect.rb', line 32 def initialize(={}, &block) @factors = {} @decision = nil @config = Config.new @rest = Rest.new(@config) () block.call(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
:nodoc:
238 239 240 241 242 243 244 245 |
# File 'lib/leadtune/prospect.rb', line 238 def method_missing(name, *args, &block) #:nodoc: if /=$/ === name.to_s memoize_new_factor(name) self.send(name, *args, &block) else super end end |
Instance Attribute Details
#decision ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/leadtune/prospect.rb', line 30 def decision @decision end |
Class Method Details
.delete(options_and_factors = {}, &block) ⇒ Object
Delete a prospect from the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
70 71 72 |
# File 'lib/leadtune/prospect.rb', line 70 def self.delete(={}, &block) new(, &block).delete end |
.get(options_and_factors = {}, &block) ⇒ Object
Get a prospect from the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
46 47 48 |
# File 'lib/leadtune/prospect.rb', line 46 def self.get(={}, &block) new(, &block).get end |
.post(options_and_factors = {}, &block) ⇒ Object
Post a prospect to the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
54 55 56 |
# File 'lib/leadtune/prospect.rb', line 54 def self.post(={}, &block) new(, &block).post end |
.put(options_and_factors = {}, &block) ⇒ Object
Update a prospect from the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
62 63 64 |
# File 'lib/leadtune/prospect.rb', line 62 def self.put(={}, &block) new(, &block).put end |
Instance Method Details
#api_key=(api_key) ⇒ Object
183 184 185 |
# File 'lib/leadtune/prospect.rb', line 183 def api_key=(api_key) @config.api_key = api_key end |
#appraisals ⇒ Object
The appraisals for this Prospect.
The Array returned has been extended to include two methods, duplicates
and non_duplicates
. Each returns the appraisals of the target_buyers for whom this lead is or is not a known duplicate.
127 128 129 130 |
# File 'lib/leadtune/prospect.rb', line 127 def appraisals @decision ||= {} @decision["appraisals"] end |
#decision_id ⇒ Object
The unique decision_id
for this prospect.
116 117 118 119 |
# File 'lib/leadtune/prospect.rb', line 116 def decision_id @decision ||= {} @decision["decision_id"] end |
#delete ⇒ Object
Delete a prospect from the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
108 109 110 111 112 |
# File 'lib/leadtune/prospect.rb', line 108 def delete json = @rest.delete(post_data) parse_response(json) unless json.nil? self end |
#factors ⇒ Object
Return a hash of the factors specified for this Prospect.
134 135 136 |
# File 'lib/leadtune/prospect.rb', line 134 def factors @factors end |
#get ⇒ Object
Get a prospect from the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
78 79 80 81 82 |
# File 'lib/leadtune/prospect.rb', line 78 def get json = @rest.get(post_data) parse_response(json) self end |
#leadtune_host ⇒ Object
:nodoc:
171 172 173 |
# File 'lib/leadtune/prospect.rb', line 171 def leadtune_host #:nodoc: @config.leadtune_host end |
#leadtune_host=(host) ⇒ Object
:nodoc:
167 168 169 |
# File 'lib/leadtune/prospect.rb', line 167 def leadtune_host=(host) #:nodoc: @config.leadtune_host = host end |
#organization ⇒ Object
:nodoc:
155 156 157 |
# File 'lib/leadtune/prospect.rb', line 155 def organization #:nodoc: @factors["organization"] || @config.organization end |
#payload ⇒ Object
:nodoc:
191 192 193 |
# File 'lib/leadtune/prospect.rb', line 191 def payload #:nodoc: post_data.reject {|k,v| CURL_OPTIONS.include?(k)} end |
#post ⇒ Object
Post this prospect to the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
88 89 90 91 92 |
# File 'lib/leadtune/prospect.rb', line 88 def post json = @rest.post(post_data) parse_response(json) self end |
#prospect_id ⇒ Object
:nodoc:
159 160 161 |
# File 'lib/leadtune/prospect.rb', line 159 def prospect_id #:nodoc: @factors["prospect_id"] end |
#prospect_ref ⇒ Object
:nodoc:
163 164 165 |
# File 'lib/leadtune/prospect.rb', line 163 def prospect_ref #:nodoc: @factors["prospect_ref"] end |
#put ⇒ Object
Update a prospect from the LeadTune Appraiser service.
Raises a Leadtune::LeadtuneError if a non-2XX response is received.
98 99 100 101 102 |
# File 'lib/leadtune/prospect.rb', line 98 def put json = @rest.put(post_data) parse_response(json) self end |
#response ⇒ Object
:nodoc:
187 188 189 |
# File 'lib/leadtune/prospect.rb', line 187 def response #:nodoc: @rest.response end |
#target_buyers ⇒ Object
Return an array of organization codes for the prospect’s target buyers.
150 151 152 153 |
# File 'lib/leadtune/prospect.rb', line 150 def target_buyers @decision ||= {} @decision["target_buyers"] ||= [] end |
#target_buyers=(target_buyers) ⇒ Object
Assign an array of organization codes for the prospect’s target buyers.
140 141 142 143 144 145 146 |
# File 'lib/leadtune/prospect.rb', line 140 def target_buyers=(target_buyers) unless target_buyers.is_a?(Array) raise ArgumentError.new("target_buyers must be an Array") end @decision = {"target_buyers" => target_buyers} end |
#timeout ⇒ Object
:nodoc:
179 180 181 |
# File 'lib/leadtune/prospect.rb', line 179 def timeout #:nodoc: @config.timeout end |
#timeout=(timeout) ⇒ Object
:nodoc:
175 176 177 |
# File 'lib/leadtune/prospect.rb', line 175 def timeout=(timeout) #:nodoc: @config.timeout = timeout end |