Class: CTM::Sale

Inherits:
Base
  • Object
show all
Defined in:
lib/ctm/sale.rb

Constant Summary collapse

ReadWriteFields =
[:conversion,
:sale_date,        :score,
:service_rep_name, :value]

Instance Attribute Summary collapse

Attributes inherited from Base

#account_id, #token

Instance Method Summary collapse

Methods inherited from Base

create

Constructor Details

#initialize(data, token = nil) ⇒ Sale

Returns a new instance of Sale.



10
11
12
13
14
15
16
# File 'lib/ctm/sale.rb', line 10

def initialize(data, token=nil)
  super(data, token)

  [ :call_id, *ReadWriteFields].each do |k|
    instance_variable_set "@#{k}", data[k.to_s]
  end
end

Instance Attribute Details

#call_idObject (readonly)

Returns the value of attribute call_id.



7
8
9
# File 'lib/ctm/sale.rb', line 7

def call_id
  @call_id
end

Instance Method Details

#nameObject



18
19
20
# File 'lib/ctm/sale.rb', line 18

def name
  @service_rep_name
end

#name=(n) ⇒ Object



22
23
24
25
# File 'lib/ctm/sale.rb', line 22

def name=(n)
  @service_rep_name = n
  @service_rep_name
end

#release!Object



27
28
29
30
31
# File 'lib/ctm/sale.rb', line 27

def release!
  path_str ="/api/v1/#{@list_type_path}/#{@call_id}/sale.json"
  res = self.class.delete path_str, body: {auth_token: @token}
  res.parsed_response
end

#save(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ctm/sale.rb', line 33

def save(options = {})
  path_str = "/api/v1/#{@list_type_path}/#{@call_id}/sale.json"
  options = {}
  ReadWriteFields.each do |k|
    v = self.send k
    case k.to_s
    when 'conversion' then v = v ? 'on' : 'off'
    when 'service_rep_name' then k = :name
    end
    options[k] = v
  end
  options[:id] = @call_id

  #self.class.debug_output $stderr
  res = self.class.post path_str, body: options.merge(auth_token: @token)
  #self.class.debug_output nil
  return nil unless res
  (res['status'] == 'success') ? true : (res['message'] || res['reason'])
end