Class: DataMapper::Adapters::SalesforceAdapter::Connection
- Inherits:
-
Object
- Object
- DataMapper::Adapters::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.
20
21
22
23
24
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 20
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.
25
26
27
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 25
def user_details
@user_details
end
|
#user_id ⇒ Object
Returns the value of attribute user_id.
25
26
27
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 25
def user_id
@user_id
end
|
Instance Method Details
#api_dir ⇒ Object
31
32
33
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 31
def api_dir
@wrapper.api_dir
end
|
#create(objects) ⇒ Object
76
77
78
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 76
def create(objects)
call_api(:create, CreateError, "creating", objects)
end
|
#delete(keys) ⇒ Object
84
85
86
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 84
def delete(keys)
call_api(:delete, DeleteError, "deleting", keys)
end
|
#field_name_for(klass_name, column) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 52
def field_name_for(klass_name, column)
klass = SalesforceAPI.const_get(klass_name)
fields = [column, DataMapper::Inflector.camelize(column), "#{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 neither #{fields.join(" or ")} exist. " \
"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
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 39
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
35
36
37
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 35
def organization_id
@user_details && @user_details.organizationId
end
|
#query(string) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 68
def query(string)
with_reconnection do
driver.query(:queryString => string).result
end
rescue SOAP::FaultError => e
raise QueryError.new(e.message, [])
end
|
#update(objects) ⇒ Object
80
81
82
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 80
def update(objects)
call_api(:update, UpdateError, "updating", objects)
end
|
#wsdl_path ⇒ Object
27
28
29
|
# File 'lib/dm-salesforce-adapter/connection.rb', line 27
def wsdl_path
@wrapper.wsdl_path
end
|