Class: Nimble::Company
- Inherits:
-
BaseNimble
- Object
- BaseNimble
- Nimble::Company
- Defined in:
- lib/nimble/company.rb
Constant Summary collapse
- RECORD_IS =
MAX_RETRIES = 3
'company'
Class Method Summary collapse
-
.call(company_attributes, additional_details = nil) ⇒ Object
CALLING METHOD.
- .get_save_data(company_attributes, save_on_empty) ⇒ Object
Methods inherited from BaseNimble
find_nimble_record, get_find_data, get_headers, save, send_status
Class Method Details
.call(company_attributes, additional_details = nil) ⇒ Object
CALLING METHOD
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nimble/company.rb', line 7 def self.call(company_attributes, additional_details = nil) # intialize retries return nil unless company_attributes.class == Hash retiries_count = 0 begin # fetch headers headers = get_headers # find nimble id if exists if (additional_details.nil? || additional_details.class != Hash) additional_details = { save_on_empty: true, searchable_string: "", identifier: nil } end nimble_id = find_nimble_record(additional_details[:searchable_string], headers, additional_details[:identifier], Nimble::Company::RECORD_IS) # create json data data = get_save_data(company_attributes, additional_details[:save_on_empty]) # save data on nimble result = save(nimble_id, data, headers) # send email based on response send_status(result) rescue => e # display error message puts e. # increment retry count # retiries_count +=1 # if Nimble::Company::MAX_RETRIES >= retiries_count # # max upto 3 retries # retry # else # send failed email send_status(nil, e.) # end end end |
.get_save_data(company_attributes, save_on_empty) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nimble/company.rb', line 44 def self.get_save_data(company_attributes, save_on_empty) # parent json company_json = { "fields": { }, "record_type": "company" } company_attributes.each { |key, value| field = { key&.to_s.gsub('_', ' ').to_sym => [ { "value": value, "modifier": "" } ] } if save_on_empty company_json[:fields] = company_json[:fields].merge(field) else company_json[:fields] = company_json[:fields].merge(field) if value&.present? end field = {} } return company_json end |