Class: Leadtune::Prospect

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options_and_factors={}, &block)
  @factors = {}
  @decision = nil
  @config = Config.new
  @rest = Rest.new(@config)

  load_options_and_factors(options_and_factors)
  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

#decisionObject

: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(options_and_factors={}, &block)
  new(options_and_factors, &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(options_and_factors={}, &block)
  new(options_and_factors, &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(options_and_factors={}, &block)
  new(options_and_factors, &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(options_and_factors={}, &block)
  new(options_and_factors, &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

#appraisalsObject

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_idObject

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

#deleteObject

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

#factorsObject

Return a hash of the factors specified for this Prospect.



134
135
136
# File 'lib/leadtune/prospect.rb', line 134

def factors
  @factors
end

#getObject

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_hostObject

: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

#organizationObject

:nodoc:



155
156
157
# File 'lib/leadtune/prospect.rb', line 155

def organization #:nodoc:
  @factors["organization"] || @config.organization
end

#payloadObject

:nodoc:



191
192
193
# File 'lib/leadtune/prospect.rb', line 191

def payload #:nodoc:
  post_data.reject {|k,v| CURL_OPTIONS.include?(k)}
end

#postObject

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_idObject

:nodoc:



159
160
161
# File 'lib/leadtune/prospect.rb', line 159

def prospect_id #:nodoc:
  @factors["prospect_id"]
end

#prospect_refObject

:nodoc:



163
164
165
# File 'lib/leadtune/prospect.rb', line 163

def prospect_ref #:nodoc:
  @factors["prospect_ref"]
end

#putObject

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

#responseObject

:nodoc:



187
188
189
# File 'lib/leadtune/prospect.rb', line 187

def response #:nodoc:
  @rest.response
end

#target_buyersObject

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

#timeoutObject

: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