Class: DataObject::Salesforce::Connection
- Inherits:
-
Object
- Object
- DataObject::Salesforce::Connection
- Defined in:
- lib/do_salesforce/connection.rb
Defined Under Namespace
Classes: HeaderHandler
Instance Attribute Summary collapse
-
#user_details ⇒ Object
readonly
Returns the value of attribute user_details.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #api_dir ⇒ Object
- #create(objects) ⇒ Object
- #delete(keys) ⇒ Object
- #field_name_for(klass_name, column) ⇒ Object
-
#initialize(username, password, wsdl_path, api_dir, organization_id = nil) ⇒ Connection
constructor
A new instance of Connection.
- #make_object(klass_name, values) ⇒ Object
- #organization_id ⇒ Object
- #query(string) ⇒ Object
- #update(objects) ⇒ Object
- #wsdl_path ⇒ Object
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/do_salesforce/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 (readonly)
Returns the value of attribute user_details.
23 24 25 |
# File 'lib/do_salesforce/connection.rb', line 23 def user_details @user_details end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
23 24 25 |
# File 'lib/do_salesforce/connection.rb', line 23 def user_id @user_id end |
Instance Method Details
#api_dir ⇒ Object
29 30 31 |
# File 'lib/do_salesforce/connection.rb', line 29 def api_dir @wrapper.api_dir end |
#create(objects) ⇒ Object
73 74 75 76 |
# File 'lib/do_salesforce/connection.rb', line 73 def create(objects) debugger call_api(:create, CreateError, "creating", objects) end |
#delete(keys) ⇒ Object
82 83 84 |
# File 'lib/do_salesforce/connection.rb', line 82 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/do_salesforce/connection.rb', line 50 def field_name_for(klass_name, column) klass = SalesforceAPI.const_get(klass_name) fields = [column, DataMapper::Inflector.camelize(column), "#{column}__c".downcase] = /^(#{fields.join("|")})$/i matches = klass.instance_methods(false).grep() 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
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/do_salesforce/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/do_salesforce/connection.rb', line 33 def organization_id @user_details && @user_details.organizationId end |
#query(string) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/do_salesforce/connection.rb', line 65 def query(string) with_reconnection do driver.query(:queryString => string).result end rescue SOAP::FaultError => e raise QueryError.new(e., []) end |
#update(objects) ⇒ Object
78 79 80 |
# File 'lib/do_salesforce/connection.rb', line 78 def update(objects) call_api(:update, UpdateError, "updating", objects) end |
#wsdl_path ⇒ Object
25 26 27 |
# File 'lib/do_salesforce/connection.rb', line 25 def wsdl_path @wrapper.wsdl_path end |