Class: SalesforceArSync::SoapHandler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce_ar_sync/soap_handler/base.rb

Direct Known Subclasses

Delete

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {}
  @options = options
  @xml_hashed = options
  @organization = SalesforceArSync.config["ORGANIZATION_ID"]
  @sobjects = collect_sobjects if valid?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 4

def options
  @options
end

#sobjectsObject (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_hashedObject (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



51
52
53
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 51

def self.deletion_map(field)
  SalesforceArSync.config['DELETION_MAP'].fetch(field, field)
end

.namespaced(field) ⇒ Object



45
46
47
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 45

def self.namespaced(field)
   SalesforceArSync.config["NAMESPACE_PREFIX"].present? ? :"#{SalesforceArSync.config["NAMESPACE_PREFIX"]}__#{field}" : :"#{field}"
end

Instance Method Details

#batch_process(&block) ⇒ Object



28
29
30
31
32
33
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 28

def batch_process(&block)
  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



37
38
39
40
41
42
43
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 37

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
  return "<?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
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 14

def process_notifications(priority = 90)
  batch_process do |sobject|
    options[:klass].camelize.constantize.delay(:priority => priority, :run_at => 5.seconds.from_now).salesforce_update(sobject)
  end
end

#valid?Boolean

ensures that the received message is properly formed, and that it comes from the expected Salesforce Org

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/salesforce_ar_sync/soap_handler/base.rb', line 21

def valid?
  notifications = @xml_hashed.try(:[], "Envelope").try(:[], "Body").try(:[], "notifications")

  organization_id = notifications.try(:[], "OrganizationId")
  return !notifications.try(:[], "Notification").nil? && organization_id == @organization # we sent this to ourselves
end