Class: SalesforceAdapter::Connection
- Inherits:
-
Object
- Object
- SalesforceAdapter::Connection
show all
- Includes:
- Errors
- Defined in:
- lib/dm-salesforce-adapter/connection.rb,
lib/dm-salesforce-adapter/connection/errors.rb
Defined Under Namespace
Modules: Errors
Classes: HeaderHandler
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(username, password, wsdl_path, api_dir, organization_id = nil) ⇒ Connection
Returns a new instance of Connection.
18
19
20
21
22
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 18
def initialize(username, password, wsdl_path, api_dir, organization_id = nil)
@wrapper = SoapWrapper.new("SalesforceAPI", "Soap", wsdl_path, api_dir)
@username, @password, @organization_id = URI.unescape(username), password, organization_id
login
end
|
Instance Attribute Details
#user_details ⇒ Object
Returns the value of attribute user_details.
23
24
25
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 23
def user_details
@user_details
end
|
#user_id ⇒ Object
Returns the value of attribute user_id.
23
24
25
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 23
def user_id
@user_id
end
|
Instance Method Details
#api_dir ⇒ Object
29
30
31
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 29
def api_dir
@wrapper.api_dir
end
|
#create(objects) ⇒ Object
80
81
82
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 80
def create(objects)
call_api(:create, CreateError, "creating", objects)
end
|
#delete(keys) ⇒ Object
88
89
90
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 88
def delete(keys)
call_api(:delete, DeleteError, "deleting", keys)
end
|
#field_name_for(klass_name, column) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 50
def field_name_for(klass_name, column)
klass = SalesforceAPI.const_get(klass_name)
fields = [column, Inflector.camelize(column.to_s), "#{Inflector.camelize(column.to_s)}__c", "#{column}__c".downcase]
options = /^(#{fields.join("|")})$/i
matches = klass.instance_methods(false).grep(options)
if matches.any?
matches.first
else
raise FieldNotFound,
"You specified #{column} as a field, but none of the expected field names exist: #{fields.join(", ")}. " \
"Either manually specify the field name with :field, or check to make sure you have " \
"provided a correct field name."
end
end
|
#make_object(klass_name, values) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 37
def make_object(klass_name, values)
obj = SalesforceAPI.const_get(klass_name).new
values.each do |property, value|
field = field_name_for(klass_name, property)
if value.nil? or value == ""
obj.fieldsToNull.push(field)
else
obj.send("#{field}=", value)
end
end
obj
end
|
#organization_id ⇒ Object
33
34
35
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 33
def organization_id
@user_details && @user_details.organizationId
end
|
#query(string) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 65
def query(string)
with_reconnection do
res = driver.query(:queryString => string).result
records = res.records
while !res.done
res = driver.queryMore(:queryLocator => res.queryLocator).result
records += res.records
end
res.records = records
res
end
rescue SOAP::FaultError => e
raise QueryError.new(e.message, [])
end
|
#update(objects) ⇒ Object
84
85
86
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 84
def update(objects)
call_api(:update, UpdateError, "updating", objects)
end
|
#wsdl_path ⇒ Object
25
26
27
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 25
def wsdl_path
@wrapper.wsdl_path
end
|