class Nimble::BaseNimble
Public Class Methods
find_nimble_record(searchable_string, headers, identifier, record)
click to toggle source
find nimble record
# File lib/nimble/base_nimble.rb, line 49 def self.find_nimble_record(searchable_string, headers, identifier, record) begin return nil if (identifier.nil? || searchable_string.nil?) data = get_find_data(searchable_string, identifier, record) request = ::HTTParty.get( "https://app.nimble.com/api/v1/contacts?query="+CGI.escape(data.to_json) +'&tags=0&per_page=5', :headers => headers ) value = request["resources"].first["id"] rescue value = nil end return value end
get_find_data(searchable_string, identifier, record)
click to toggle source
generate json for searching nimble record
# File lib/nimble/base_nimble.rb, line 31 def self.get_find_data(searchable_string, identifier, record) fetch = { "and": [ { identifier.to_sym => { "is": searchable_string } }, { "record type": { "is": record } } ] } return fetch end
get_headers()
click to toggle source
generate nimble headers
# File lib/nimble/base_nimble.rb, line 3 def self.get_headers # Arguments: # NIMBLE_API_KEY: (Add this key in your environments development for local) headers = { "Authorization": "Bearer " + ::Nimble.api_token, "Content-Type": 'application/json' } return headers end
save(nimble_id, data, headers)
click to toggle source
save data to nimble
# File lib/nimble/base_nimble.rb, line 13 def self.save(nimble_id, data, headers) if nimble_id&.present? url = "https://app.nimble.com/api/v1/contact/"+nimble_id+"?replace=1" request = ::HTTParty.put( url, :headers => headers, :body => data.to_json ) else url = "https://app.nimble.com/api/v1/contact" request = ::HTTParty.post( url, :headers => headers, :body => data.to_json ) end end
send_status(result = nil, error = nil)
click to toggle source
send email for failed instances
# File lib/nimble/base_nimble.rb, line 64 def self.send_status(result = nil, error = nil) if result&.success? puts 'Data succesfully created' return {success: true, result: result, errors: nil} else puts 'Error occured' error_value = result["errors"]&.values&.first&.values&.join(',') if result&.present? return {success: false, result: result, errors: error || error_value} end end