-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accepts Headers #25
Open
Nerdenberger
wants to merge
3
commits into
congaengr:master
Choose a base branch
from
Nerdenberger:all_the_headers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Accepts Headers #25
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ class Client | |
def initialize(options = {}) | ||
@describe_cache = {} | ||
@describe_layout_cache = {} | ||
@headers = {} | ||
@headers = {} | ||
|
||
@wsdl = options[:wsdl] || File.dirname(__FILE__) + '/../../resources/partner.wsdl.xml' | ||
|
||
|
@@ -19,6 +19,9 @@ def initialize(options = {}) | |
# to make SOAP calls in Professional/Group Edition organizations. | ||
|
||
client_id = options[:client_id] || Soapforce.configuration.client_id | ||
|
||
@headers = options[:headers] if options[:headers] | ||
|
||
@headers = { 'tns:CallOptions' => { 'tns:client' => client_id } } if client_id | ||
|
||
@version = options[:version] || Soapforce.configuration.version || 28.0 | ||
|
@@ -204,21 +207,21 @@ def describe_layout(sobject_type, layout_id=nil) | |
response | ||
end | ||
|
||
def query(soql) | ||
call_soap_api(:query, {:queryString => soql}) | ||
def query(soql, header={}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing |
||
call_soap_api(:query, {:queryString => soql}, header) | ||
end | ||
|
||
# Includes deleted (isDeleted) or archived (isArchived) records | ||
def query_all(soql) | ||
call_soap_api(:query_all, {:queryString => soql}) | ||
def query_all(soql, header={}) | ||
call_soap_api(:query_all, {:queryString => soql}, header) | ||
end | ||
|
||
def query_more(locator) | ||
call_soap_api(:query_more, {:queryLocator => locator}) | ||
def query_more(locator, header={}) | ||
call_soap_api(:query_more, {:queryLocator => locator}, header) | ||
end | ||
|
||
def search(sosl) | ||
call_soap_api(:search, {:searchString => sosl}) | ||
def search(sosl, header={}) | ||
call_soap_api(:search, {:searchString => sosl}, header) | ||
end | ||
|
||
# Public: Insert a new record. | ||
|
@@ -234,8 +237,8 @@ def search(sosl) | |
# | ||
# Returns the String Id of the newly created sobject. | ||
# Returns false if something bad happens. | ||
def create(sobject_type, properties) | ||
create!(sobject_type, properties) | ||
def create(sobject_type, properties, header={}) | ||
create!(sobject_type, properties, header) | ||
rescue | ||
false | ||
end | ||
|
@@ -253,8 +256,8 @@ def create(sobject_type, properties) | |
# | ||
# Returns the String Id of the newly created sobject. | ||
# Raises exceptions if an error is returned from Salesforce. | ||
def create!(sobject_type, properties) | ||
call_soap_api(:create, sobjects_hash(sobject_type, properties)) | ||
def create!(sobject_type, properties, header={}) | ||
call_soap_api(:create, sobjects_hash(sobject_type, properties), header) | ||
end | ||
|
||
# Public: Update a record. | ||
|
@@ -269,8 +272,8 @@ def create!(sobject_type, properties) | |
# | ||
# Returns Hash if the sobject was successfully updated. | ||
# Returns false if there was an error. | ||
def update(sobject_type, properties) | ||
update!(sobject_type, properties) | ||
def update(sobject_type, properties, header={}) | ||
update!(sobject_type, properties, header) | ||
rescue | ||
false | ||
end | ||
|
@@ -287,8 +290,8 @@ def update(sobject_type, properties) | |
# | ||
# Returns Hash if the sobject was successfully updated. | ||
# Raises an exception if an error is returned from Salesforce | ||
def update!(sobject_type, properties) | ||
call_soap_api(:update, sobjects_hash(sobject_type, properties)) | ||
def update!(sobject_type, properties, header={}) | ||
call_soap_api(:update, sobjects_hash(sobject_type, properties), header) | ||
end | ||
|
||
# Public: Update or create a record based on an external ID | ||
|
@@ -304,8 +307,8 @@ def update!(sobject_type, properties) | |
# | ||
# Returns Hash if the record was found and updated or newly created. | ||
# Raises an exception if an error is returned from Salesforce. | ||
def upsert(sobject_type, external_id_field_name, objects) | ||
upsert!(sobject_type, external_id_field_name, objects) | ||
def upsert(sobject_type, external_id_field_name, objects, header={}) | ||
upsert!(sobject_type, external_id_field_name, objects, header) | ||
rescue | ||
false | ||
end | ||
|
@@ -323,9 +326,9 @@ def upsert(sobject_type, external_id_field_name, objects) | |
# | ||
# Returns Hash if the record was found and updated or newly created. | ||
# Raises an exception if an error is returned from Salesforce. | ||
def upsert!(sobject_type, external_id_field_name, objects) | ||
def upsert!(sobject_type, external_id_field_name, objects, header={}) | ||
message = {externalIDFieldName: external_id_field_name}.merge(sobjects_hash(sobject_type, objects)) | ||
call_soap_api(:upsert, message) | ||
call_soap_api(:upsert, message, header) | ||
end | ||
|
||
# Public: Delete a record. | ||
|
@@ -340,8 +343,8 @@ def upsert!(sobject_type, external_id_field_name, objects) | |
# | ||
# Returns true if the sobject was successfully deleted. | ||
# Returns false if an error is returned from Salesforce. | ||
def delete(id) | ||
delete!(id) | ||
def delete(id, header = {}) | ||
delete!(id, header) | ||
rescue | ||
false | ||
end | ||
|
@@ -359,9 +362,9 @@ def delete(id) | |
# | ||
# Returns Hash if the sobject was successfully deleted. | ||
# Raises an exception if an error is returned from Salesforce. | ||
def delete!(id) | ||
def delete!(id, header={}) | ||
ids = id.is_a?(Array) ? id : [id] | ||
call_soap_api(:delete, {:ids => ids}) | ||
call_soap_api(:delete, {:ids => ids}, header) | ||
end | ||
alias_method :destroy!, :delete | ||
|
||
|
@@ -376,9 +379,9 @@ def delete!(id) | |
# convertedStatus: 'Closed - Converted') | ||
# | ||
# Returns Soapforce::Result | ||
def convert_lead(attributes) | ||
def convert_lead(attributes, header={}) | ||
leads = attributes.is_a?(Array) ? attributes : [attributes] | ||
call_soap_api(:convert_lead, leadConverts: leads) | ||
call_soap_api(:convert_lead, {leadConverts: leads}, header) | ||
end | ||
|
||
# Public: Merges records together | ||
|
@@ -402,7 +405,6 @@ def merge!(sobject_type, master_record_hash, ids) | |
} | ||
) | ||
end | ||
|
||
# Public: Merges records together | ||
# | ||
# sobject - String name of the sobject | ||
|
@@ -590,10 +592,20 @@ def key_name(key) | |
end | ||
end | ||
|
||
def call_soap_api(method, message_hash={}) | ||
|
||
def header_hash(header) | ||
xml_header = header.map do |k,v| | ||
header_fields = v.map {|k,v| ["tns:#{k}",v]}.to_h | ||
header_name = "tns:#{k}" | ||
[header_name, header_fields] | ||
end | ||
xml_header.to_h | ||
end | ||
|
||
def call_soap_api(method, message_hash={}, header={}) | ||
|
||
response = @client.call(method.to_sym) do |locals| | ||
locals.message message_hash | ||
locals.soap_header header_hash(header) unless header.empty? | ||
end | ||
|
||
# Convert SOAP XML to Hash | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This combination of
client_id
would not work with optional headers. What if you merge the hashes?@headers.merge(options[:headers]) if options[:headers].is_a?(Hash)