soapforce 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ login
2
+ describe_s_object
3
+ describe_s_objects
4
+ describe_global
5
+ describe_data_category_groups
6
+ describe_data_category_group_structures
7
+ describe_layout
8
+ describe_softphone_layout
9
+ describe_search_layouts
10
+ describe_search_scope_order
11
+ describe_tabs
12
+ create
13
+ update
14
+ upsert
15
+ merge
16
+ delete
17
+ undelete
18
+ empty_recycle_bin
19
+ retrieve
20
+ process
21
+ convert_lead
22
+ logout
23
+ invalidate_sessions
24
+ get_deleted
25
+ get_updated
26
+ query
27
+ query_all
28
+ query_more
29
+ search
30
+ get_server_timestamp
31
+ set_password
32
+ reset_password
33
+ get_user_info
34
+ send_email_message
35
+ send_email
36
+ perform_quick_actions
37
+ describe_quick_actions
38
+ describe_available_quick_actions
@@ -165,23 +165,131 @@ module Soapforce
165
165
  call_soap_api(:search, {:searchString => sosl})
166
166
  end
167
167
 
168
+ # Public: Insert a new record.
169
+ #
170
+ # sobject - String name of the sobject.
171
+ # attrs - Hash of attributes to set on the new record.
172
+ #
173
+ # Examples
174
+ #
175
+ # # Add a new account
176
+ # client.create('Account', Name: 'Foobar Inc.')
177
+ # # => '0016000000MRatd'
178
+ #
179
+ # Returns the String Id of the newly created sobject.
180
+ # Returns false if something bad happens.
168
181
  def create(sobject_type, properties)
182
+ create!(sobject_type, properties)
183
+ rescue => e
184
+ false
185
+ end
186
+
187
+ # Public: Insert a new record.
188
+ #
189
+ # sobject - String name of the sobject.
190
+ # attrs - Hash of attributes to set on the new record.
191
+ #
192
+ # Examples
193
+ #
194
+ # # Add a new account
195
+ # client.create('Account', Name: 'Foobar Inc.')
196
+ # # => '0016000000MRatd'
197
+ #
198
+ # Returns the String Id of the newly created sobject.
199
+ # Raises exceptions if an error is returned from Salesforce.
200
+ def create!(sobject_type, properties)
169
201
  call_soap_api(:create, sobjects_hash(sobject_type, properties))
170
202
  end
171
203
 
204
+ # Public: Update a record.
205
+ #
206
+ # sobject - String name of the sobject.
207
+ # attrs - Hash of attributes to set on the record.
208
+ #
209
+ # Examples
210
+ #
211
+ # # Update the Account with Id '0016000000MRatd'
212
+ # client.update('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp')
213
+ #
214
+ # Returns Hash if the sobject was successfully updated.
215
+ # Returns false if there was an error.
172
216
  def update(sobject_type, properties)
217
+ update!(sobject_type, properties)
218
+ rescue => e
219
+ false
220
+ end
221
+
222
+ # Public: Update a record.
223
+ #
224
+ # sobject - String name of the sobject.
225
+ # attrs - Hash of attributes to set on the record.
226
+ #
227
+ # Examples
228
+ #
229
+ # # Update the Account with Id '0016000000MRatd'
230
+ # client.update!('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp')
231
+ #
232
+ # Returns Hash if the sobject was successfully updated.
233
+ # Raises an exception if an error is returned from Salesforce
234
+ def update!(sobject_type, properties)
173
235
  call_soap_api(:update, sobjects_hash(sobject_type, properties))
174
236
  end
175
237
 
238
+
239
+ # Public: Update or create a record based on an external ID
240
+ #
241
+ # sobject - The name of the sobject to created.
242
+ # field - The name of the external Id field to match against.
243
+ # attrs - Hash of attributes for the record.
244
+ #
245
+ # Examples
246
+ #
247
+ # # Update the record with external ID of 12
248
+ # client.upsert!('Account', 'External__c', External__c: 12, Name: 'Foobar')
249
+ #
250
+ # Returns Hash if the record was found and updated or newly created.
251
+ # Raises an exception if an error is returned from Salesforce.
176
252
  def upsert(sobject_type, external_id_field_name, objects)
177
253
  message = {externalIDFieldName: external_id_field_name}.merge(sobjects_hash(sobject_type, objects))
178
254
  call_soap_api(:upsert, message)
179
255
  end
180
256
 
257
+ # Public: Delete a record.
258
+ #
259
+ # sobject - String name of the sobject.
260
+ # id - The Salesforce ID of the record.
261
+ #
262
+ # Examples
263
+ #
264
+ # # Delete the Account with Id '0016000000MRatd'
265
+ # client.delete('Account', '0016000000MRatd')
266
+ #
267
+ # Returns true if the sobject was successfully deleted.
268
+ # Returns false if an error is returned from Salesforce.
181
269
  def delete(id)
270
+ delete!(id)
271
+ rescue => e
272
+ false
273
+ end
274
+ alias_method :destroy, :delete
275
+
276
+ # Public: Delete a record.
277
+ #
278
+ # sobject - String name of the sobject.
279
+ # id - The Salesforce ID of the record.
280
+ #
281
+ # Examples
282
+ #
283
+ # # Delete the Account with Id '0016000000MRatd'
284
+ # client.delete!('Account', '0016000000MRatd')
285
+ #
286
+ # Returns Hash if the sobject was successfully deleted.
287
+ # Raises an exception if an error is returned from Salesforce.
288
+ def delete!(id)
182
289
  ids = id.is_a?(Array) ? id : [id]
183
290
  call_soap_api(:delete, {:ids => ids})
184
291
  end
292
+ alias_method :destroy!, :delete
185
293
 
186
294
  # Public: Finds a single record and returns all fields.
187
295
  #
@@ -308,10 +416,18 @@ module Soapforce
308
416
  end
309
417
  # Convert SOAP XML to Hash
310
418
  response = response.to_hash
419
+
311
420
  # Get Response Body
312
421
  response_body = response["#{method}_response".to_sym]
422
+
313
423
  # Grab result section if exists.
314
424
  result = response_body ? response_body[:result] : nil
425
+
426
+ # Raise error when response contains errors
427
+ if result && result.is_a?(Hash) && result[:success] == false && result[:errors]
428
+ raise Savon::Error.new("#{result[:errors][:status_code]}: #{result[:errors][:message]}")
429
+ end
430
+
315
431
  return result
316
432
  end
317
433
 
@@ -1,3 +1,3 @@
1
1
  module Soapforce
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Body>
4
+ <createResponse>
5
+ <result>
6
+ <errors>
7
+ <message>insufficient access rights on cross-reference id</message>
8
+ <statusCode>INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY</statusCode>
9
+ </errors>
10
+ <id xsi:nil="true"/>
11
+ <success>false</success>
12
+ </result>
13
+ </createResponse>
14
+ </soapenv:Body>
15
+ </soapenv:Envelope>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Body>
4
+ <deleteResponse>
5
+ <result>
6
+ <errors>
7
+ <message>bad id 006i000004DAKd</message>
8
+ <statusCode>MALFORMED_ID</statusCode>
9
+ </errors>
10
+ <id xsi:nil="true"/>
11
+ <success>false</success>
12
+ </result>
13
+ </deleteResponse>
14
+ </soapenv:Body>
15
+ </soapenv:Envelope>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Body>
4
+ <updateResponse>
5
+ <result>
6
+ <errors>
7
+ <message>insufficient access rights on cross-reference id</message>
8
+ <statusCode>INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY</statusCode>
9
+ </errors>
10
+ <id xsi:nil="true"/>
11
+ <success>false</success>
12
+ </result>
13
+ </updateResponse>
14
+ </soapenv:Body>
15
+ </soapenv:Envelope>
@@ -246,56 +246,137 @@ describe Soapforce::Client do
246
246
  end
247
247
 
248
248
  describe "#create" do
249
+ before(:each) do
250
+ @body = "<tns:create><tns:sObjects><ins0:type>Opportunity</ins0:type><tns:Name>SOAPForce Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Prospecting</tns:StageName></tns:sObjects></tns:create>"
251
+ @params = { Name: "SOAPForce Opportunity", CloseDate: '2013-08-12', StageName: 'Prospecting' }
252
+ end
253
+
249
254
  it "should create new object" do
250
255
 
251
- body = "<tns:create><tns:sObjects><ins0:type>Opportunity</ins0:type><tns:Name>SOAPForce Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Prospecting</tns:StageName></tns:sObjects></tns:create>"
252
- stub = stub_api_request(endpoint, {with_body: body, fixture: 'create_response'})
253
-
254
- params = { Name: "SOAPForce Opportunity", CloseDate: '2013-08-12', StageName: 'Prospecting' }
255
- response = subject.create("Opportunity", params)
256
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'create_response'})
257
+ response = subject.create("Opportunity", @params)
258
+
259
+ response[:success].should be_true
260
+ response[:id].should == "006A000000LbiizIAB"
261
+ end
262
+
263
+ it "should return false if object not created" do
264
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'create_response_failure'})
265
+ response = subject.create("Opportunity", @params)
266
+ response.should be_false
267
+ end
268
+
269
+ it "creates! new object" do
270
+
271
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'create_response'})
272
+ response = subject.create!("Opportunity", @params)
256
273
 
257
274
  response[:success].should be_true
258
275
  response[:id].should == "006A000000LbiizIAB"
259
276
  end
277
+
278
+ it "raises exception when create! fails" do
279
+
280
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'create_response_failure'})
281
+ expect {
282
+ response = subject.create!("Opportunity", @params)
283
+ }.to raise_error(Savon::Error)
284
+
285
+ end
260
286
  end
261
287
 
262
288
  describe "#update" do
263
- it "should update existing object" do
289
+ before(:each) do
290
+ @body = "<tns:update><tns:sObjects><ins0:type>Opportunity</ins0:type><ins0:Id>003ABCDE</ins0:Id><tns:Name>SOAPForce Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Closed Won</tns:StageName></tns:sObjects></tns:update>"
291
+ @params = { Id: '003ABCDE', Name: "SOAPForce Opportunity", CloseDate: '2013-08-12', StageName: 'Closed Won' }
292
+ end
264
293
 
265
- body = "<tns:update><tns:sObjects><ins0:type>Opportunity</ins0:type><ins0:Id>003ABCDE</ins0:Id><tns:Name>SOAPForce Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Closed Won</tns:StageName></tns:sObjects></tns:update>"
266
- stub = stub_api_request(endpoint, {with_body: body, fixture: 'update_response'})
294
+ it "updates existing object" do
295
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'update_response'})
296
+ response = subject.update("Opportunity", @params)
267
297
 
268
- params = { Id: '003ABCDE', Name: "SOAPForce Opportunity", CloseDate: '2013-08-12', StageName: 'Closed Won' }
269
- response = subject.update("Opportunity", params)
298
+ response[:success].should be_true
299
+ response[:id].should == "006A000000LbiizIAB"
300
+ end
301
+
302
+ it "updates! existing object" do
303
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'update_response'})
304
+ response = subject.update!("Opportunity", @params)
270
305
 
271
306
  response[:success].should be_true
272
307
  response[:id].should == "006A000000LbiizIAB"
273
308
  end
274
- end
275
309
 
276
- describe "#upsert" do
277
- it "should insert new and update existing objects" do
310
+ it "returns false when update fails" do
311
+
312
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'update_response_failure'})
313
+ response = subject.update("Opportunity", @params)
314
+ response.should be_false
315
+ end
278
316
 
279
- body = "<tns:upsert><tns:externalIDFieldName>External_Id__c</tns:externalIDFieldName><tns:sObjects><ins0:type>Opportunity</ins0:type><tns:Name>New Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Prospecting</tns:StageName></tns:sObjects><tns:sObjects><ins0:type>Opportunity</ins0:type><ins0:Id>003ABCDE</ins0:Id><tns:Name>Existing Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Closed Won</tns:StageName></tns:sObjects></tns:upsert>"
280
- stub = stub_api_request(endpoint, {with_body: body, fixture: 'upsert_response'})
317
+ it "raises exception when update fails" do
281
318
 
282
- objects = [
319
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'update_response_failure'})
320
+ expect {
321
+ response = subject.update!("Opportunity", @params)
322
+ }.to raise_error(Savon::Error)
323
+
324
+ end
325
+ end
326
+
327
+ describe "#upsert" do
328
+ before(:each) do
329
+ @body = "<tns:upsert><tns:externalIDFieldName>External_Id__c</tns:externalIDFieldName><tns:sObjects><ins0:type>Opportunity</ins0:type><tns:Name>New Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Prospecting</tns:StageName></tns:sObjects><tns:sObjects><ins0:type>Opportunity</ins0:type><ins0:Id>003ABCDE</ins0:Id><tns:Name>Existing Opportunity</tns:Name><tns:CloseDate>2013-08-12</tns:CloseDate><tns:StageName>Closed Won</tns:StageName></tns:sObjects></tns:upsert>"
330
+ @objects = [
283
331
  { Name: "New Opportunity", CloseDate: '2013-08-12', StageName: 'Prospecting' },
284
332
  { Id: '003ABCDE', Name: "Existing Opportunity", CloseDate: '2013-08-12', StageName: 'Closed Won' }
285
333
  ]
286
- subject.upsert("Opportunity", "External_Id__c", objects)
287
334
  end
335
+
336
+ it "inserts new and updates existing objects" do
337
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'upsert_response'})
338
+ subject.upsert("Opportunity", "External_Id__c", @objects)
339
+ end
340
+
288
341
  end
289
342
 
290
343
  describe "#delete" do
291
- it "should delete existing objects" do
292
- body = "<tns:delete><tns:ids>003ABCDE</tns:ids></tns:delete>"
293
- stub = stub_api_request(endpoint, {with_body: body, fixture: 'delete_response'})
294
- response = subject.delete("003ABCDE")
344
+ before(:each) do
345
+ @body = "<tns:delete><tns:ids>006A000000LbiizIAB</tns:ids></tns:delete>"
346
+ @id = "006A000000LbiizIAB"
347
+ end
348
+
349
+ it "deletes existing object" do
350
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response'})
351
+ response = subject.delete(@id)
295
352
 
296
353
  response[:success].should be_true
297
- response[:id].should == "006A000000LbiizIAB"
354
+ response[:id].should == @id
298
355
  end
356
+
357
+ it "returns false if delete fails" do
358
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response_failure'})
359
+ response = subject.delete(@id)
360
+
361
+ response.should be_false
362
+ end
363
+
364
+ it "deletes existing object with a bang" do
365
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response'})
366
+ response = subject.delete!(@id)
367
+
368
+ response[:success].should be_true
369
+ response[:id].should == @id
370
+ end
371
+
372
+ it "raises an exception if delete fails" do
373
+ stub = stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response_failure'})
374
+ expect {
375
+ subject.delete!(@id)
376
+ }.to raise_error(Savon::Error)
377
+ end
378
+
379
+
299
380
  end
300
381
 
301
382
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soapforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-15 00:00:00.000000000 Z
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -89,6 +89,7 @@ files:
89
89
  - README.md
90
90
  - Rakefile
91
91
  - lib/soapforce.rb
92
+ - lib/soapforce/actions
92
93
  - lib/soapforce/client.rb
93
94
  - lib/soapforce/configuration.rb
94
95
  - lib/soapforce/query_result.rb
@@ -97,7 +98,9 @@ files:
97
98
  - resources/partner.wsdl.xml
98
99
  - soapforce.gemspec
99
100
  - spec/fixtures/create_response.xml
101
+ - spec/fixtures/create_response_failure.xml
100
102
  - spec/fixtures/delete_response.xml
103
+ - spec/fixtures/delete_response_failure.xml
101
104
  - spec/fixtures/describe_global_response.xml
102
105
  - spec/fixtures/describe_s_object_response.xml
103
106
  - spec/fixtures/describe_s_objects_response.xml
@@ -110,6 +113,7 @@ files:
110
113
  - spec/fixtures/retrieve_response.xml
111
114
  - spec/fixtures/search_response.xml
112
115
  - spec/fixtures/update_response.xml
116
+ - spec/fixtures/update_response_failure.xml
113
117
  - spec/fixtures/upsert_response.xml
114
118
  - spec/lib/client_spec.rb
115
119
  - spec/lib/configuration_spec.rb
@@ -145,7 +149,9 @@ summary: Wraps Savon with helper methods and custom types for interacting with t
145
149
  Salesforce SOAP API.
146
150
  test_files:
147
151
  - spec/fixtures/create_response.xml
152
+ - spec/fixtures/create_response_failure.xml
148
153
  - spec/fixtures/delete_response.xml
154
+ - spec/fixtures/delete_response_failure.xml
149
155
  - spec/fixtures/describe_global_response.xml
150
156
  - spec/fixtures/describe_s_object_response.xml
151
157
  - spec/fixtures/describe_s_objects_response.xml
@@ -158,6 +164,7 @@ test_files:
158
164
  - spec/fixtures/retrieve_response.xml
159
165
  - spec/fixtures/search_response.xml
160
166
  - spec/fixtures/update_response.xml
167
+ - spec/fixtures/update_response_failure.xml
161
168
  - spec/fixtures/upsert_response.xml
162
169
  - spec/lib/client_spec.rb
163
170
  - spec/lib/configuration_spec.rb