Class: SalesforceArSync::SoapHandler::Base
- Inherits:
-
Object
- Object
- SalesforceArSync::SoapHandler::Base
- Defined in:
- lib/salesforce_ar_sync/soap_handler/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sobjects ⇒ Object
readonly
Returns the value of attribute sobjects.
-
#xml_hashed ⇒ Object
readonly
Returns the value of attribute xml_hashed.
Class Method Summary collapse
-
.deletion_map(field) ⇒ Object
Get configuration for the in app deletions.
- .namespaced(field) ⇒ Object
Instance Method Summary collapse
- #batch_process ⇒ Object
-
#generate_response(error = nil) ⇒ Object
xml for SFDC response called from soap_message_controller.
-
#initialize(_organization, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#process_notifications(priority = 90) ⇒ Object
queues each individual record from the message for update.
-
#valid? ⇒ Boolean
ensures that the received message is properly formed, and that it comes from the expected Salesforce Org.
Constructor Details
#initialize(_organization, options = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 6 def initialize(_organization, = {}) = .to_unsafe_h @xml_hashed = .to_unsafe_h @organization = SalesforceArSync.config['ORGANIZATION_ID'] @sobjects = collect_sobjects if valid? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 4 def end |
#sobjects ⇒ Object (readonly)
Returns the value of attribute sobjects.
4 5 6 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 4 def sobjects @sobjects end |
#xml_hashed ⇒ Object (readonly)
Returns the value of attribute xml_hashed.
4 5 6 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 4 def xml_hashed @xml_hashed end |
Class Method Details
.deletion_map(field) ⇒ Object
Get configuration for the in app deletions. Map to the object within the app if named differently then in SalesForce
54 55 56 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 54 def self.deletion_map(field) SalesforceArSync.config['DELETION_MAP'].fetch(field, field) end |
.namespaced(field) ⇒ Object
48 49 50 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 48 def self.namespaced(field) SalesforceArSync.config['NAMESPACE_PREFIX'].present? ? :"#{SalesforceArSync.config['NAMESPACE_PREFIX']}__#{field}" : :"#{field}" end |
Instance Method Details
#batch_process ⇒ Object
31 32 33 34 35 36 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 31 def batch_process return if sobjects.nil? || !block_given? sobjects.each do |sobject| yield sobject end end |
#generate_response(error = nil) ⇒ Object
xml for SFDC response called from soap_message_controller
40 41 42 43 44 45 46 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 40 def generate_response(error = nil) response = "<Ack>#{sobjects.nil? ? false : true}</Ack>" unless error if error response = "<soapenv:Fault><faultcode>soap:Receiver</faultcode><faultstring>#{error.message}</faultstring></soapenv:Fault>" end "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><notificationsResponse>#{response}</notificationsResponse></soapenv:Body></soapenv:Envelope>" end |
#process_notifications(priority = 90) ⇒ Object
queues each individual record from the message for update
14 15 16 17 18 19 20 21 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 14 def process_notifications(priority = 90) batch_process do |sobject| SalesforceArSync::SyncObjectJob.set( priority: priority, wait_until: 5.seconds.from_now ).perform_later([:klass], sobject) end end |
#valid? ⇒ Boolean
ensures that the received message is properly formed, and that it comes from the expected Salesforce Org
24 25 26 27 28 29 |
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 24 def valid? notifications = @xml_hashed.try(:[], 'Envelope').try(:[], 'Body').try(:[], 'notifications') organization_id = notifications.try(:[], 'OrganizationId') !notifications.try(:[], 'Notification').nil? && organization_id == @organization # we sent this to ourselves end |