Class: DataMapper::Salesforce::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-salesforce/connection/errors.rb,
lib/dm-salesforce/connection.rb

Defined Under Namespace

Classes: CreateError, DeleteError, Error, FieldNotFound, HeaderHandler, LoginFailed, QueryError, SOAPError, ServerUnavailable, SessionTimeout, UnknownStatusCode, UpdateError

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.



14
15
16
17
18
# File 'lib/dm-salesforce/connection.rb', line 14

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
  
end

Instance Attribute Details

#user_detailsObject (readonly)

Returns the value of attribute user_details.



19
20
21
# File 'lib/dm-salesforce/connection.rb', line 19

def user_details
  @user_details
end

#user_idObject (readonly)

Returns the value of attribute user_id.



19
20
21
# File 'lib/dm-salesforce/connection.rb', line 19

def user_id
  @user_id
end

Instance Method Details

#api_dirObject



25
26
27
# File 'lib/dm-salesforce/connection.rb', line 25

def api_dir
  @wrapper.api_dir
end

#create(objects) ⇒ Object



69
70
71
# File 'lib/dm-salesforce/connection.rb', line 69

def create(objects)
  call_api(:create, CreateError, "creating", objects)
end

#delete(keys) ⇒ Object



77
78
79
# File 'lib/dm-salesforce/connection.rb', line 77

def delete(keys)
  call_api(:delete, DeleteError, "deleting", keys)
end

#field_name_for(klass_name, column) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dm-salesforce/connection.rb', line 46

def field_name_for(klass_name, column)
  klass = SalesforceAPI.const_get(klass_name)
  fields = [column, column.camel_case, "#{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



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dm-salesforce/connection.rb', line 33

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_idObject



29
30
31
# File 'lib/dm-salesforce/connection.rb', line 29

def organization_id
  @user_details && @user_details.organizationId
end

#query(string) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/dm-salesforce/connection.rb', line 61

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



73
74
75
# File 'lib/dm-salesforce/connection.rb', line 73

def update(objects)
  call_api(:update, UpdateError, "updating", objects)
end

#wsdl_pathObject



21
22
23
# File 'lib/dm-salesforce/connection.rb', line 21

def wsdl_path
  @wrapper.wsdl_path
end