Class: CTM::Sale
Constant Summary collapse
- ReadWriteFields =
[:conversion, :sale_date, :score, :service_rep_name, :value]
Instance Attribute Summary collapse
-
#call_id ⇒ Object
readonly
Returns the value of attribute call_id.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(data, token = nil) ⇒ Sale
constructor
A new instance of Sale.
- #name ⇒ Object
- #name=(n) ⇒ Object
- #release! ⇒ Object
- #save(options = {}) ⇒ Object
Methods inherited from Base
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_id ⇒ Object (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
#name ⇒ Object
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( = {}) path_str = "/api/v1/#{@list_type_path}/#{@call_id}/sale.json" = {} 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 [k] = v end [:id] = @call_id #self.class.debug_output $stderr res = self.class.post path_str, body: .merge(auth_token: @token) #self.class.debug_output nil return nil unless res (res['status'] == 'success') ? true : (res['message'] || res['reason']) end |