rforce 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -7,3 +7,8 @@
7
7
 
8
8
  * 1 major enhancement:
9
9
  * Incorporated fixes from ActiveSalesforce project
10
+
11
+ == 0.2.1 2008-07-04
12
+
13
+ * 1 minor enhancement:
14
+ * Updated examples for SalesForce API v10
data/Manifest.txt CHANGED
@@ -6,4 +6,4 @@ lib/rforce.rb
6
6
  spec/rforce_spec.rb
7
7
  spec/spec.opts
8
8
  spec/spec_helper.rb
9
- tasks/rspec.rake
9
+ tasks/rspec.rake
data/README.txt CHANGED
@@ -1,6 +1,8 @@
1
1
  = rforce
2
2
 
3
3
  * http://rforce.rubyforge.org
4
+ * http://rubyforge.org/projects/rforce
5
+ * http://freehg.org/u/undees/rforce
4
6
 
5
7
  == DESCRIPTION:
6
8
 
@@ -12,25 +14,36 @@ Rather than enforcing adherence to the sforce.com schema, RForce assumes you are
12
14
 
13
15
  == SYNOPSIS:
14
16
 
15
- binding = RForce::Binding.new 'na1-api.salesforce.com'
16
- binding.login 'username', 'password'
17
- answer = binding.search(
17
+ binding = RForce::Binding.new \
18
+ 'https://na2.salesforce.com/services/Soap/u/10.0'
19
+
20
+ binding.login \
21
+ 'email', 'password_with_token'
22
+
23
+ answer = binding.search \
18
24
  :searchString =>
19
- 'find {Some Account Name} in name fields returning account(id)')
20
- account_id = answer.searchResponse.result.searchRecords.record.Id
21
-
22
- opportunity = {
23
- :accountId => account_id,
24
- :amount => "10.00",
25
- :name => "New sale",
26
- :closeDate => "2005-09-01",
27
- :stageName => "Closed Won"
28
- }
29
-
30
- binding.create 'sObject {"xsi:type" => "Opportunity"}' => opportunity
25
+ 'find {McFakerson Co} in name fields returning account(id)'
26
+
27
+ account = answer.searchResponse.result.searchRecords.record
28
+ account = account.first if account.is_a? Array
29
+
30
+ account_id = account.Id
31
+ account_id = account_id.first if account_id.is_a? Array
32
+
33
+ opportunity = [
34
+ :type, 'Opportunity',
35
+ :accountId, account_id,
36
+ :amount, '10.00',
37
+ :name, 'Fakey McFakerson',
38
+ :closeDate, '2008-07-04',
39
+ :stageName, 'Closed Won'
40
+ ]
41
+
42
+ binding.create :sObject => opportunity
31
43
 
32
44
  == REQUIREMENTS:
33
45
 
46
+ * Builder gem
34
47
  * A SalesForce Enterprise or Developer account
35
48
 
36
49
  == INSTALL:
data/Rakefile CHANGED
@@ -5,8 +5,9 @@ require 'hoe'
5
5
  require './lib/rforce.rb'
6
6
 
7
7
  Hoe.new('rforce', RForce::VERSION) do |p|
8
- # p.rubyforge_name = 'rforcex' # if different than lowercase project name
9
8
  p.developer('Ian Dees', 'undees@gmail.com')
9
+ p.extra_deps = [['builder', '>= 2.0.0']]
10
+ p.extra_dev_deps = [['hoe', '>= 1.7.0']]
10
11
  p.remote_rdoc_dir = ''
11
12
  end
12
13
 
data/lib/rforce.rb CHANGED
@@ -55,11 +55,12 @@ require 'stringio'
55
55
  require 'rexml/document'
56
56
  require 'rexml/xpath'
57
57
  require 'rubygems'
58
- gem 'builder', ">= 2.0.0"
58
+ gem 'builder', '>= 2.0.0'
59
+ require 'builder'
59
60
 
60
61
 
61
62
  module RForce
62
- VERSION = '0.2.0'
63
+ VERSION = '0.2.1'
63
64
 
64
65
  #Allows indexing hashes like method calls: hash.key
65
66
  #to supplement the traditional way of indexing: hash[key]
@@ -125,9 +126,45 @@ module RForce
125
126
  end
126
127
  end
127
128
 
129
+ #Expand Ruby data structures into XML.
130
+ def expand(builder, args, xmlns = nil)
131
+ #Nest arrays: [:a, 1, :b, 2] => [[:a, 1], [:b, 2]]
132
+ if (args.class == Array)
133
+ args.each_index{|i| args[i, 2] = [args[i, 2]]}
134
+ end
135
+
136
+ args.each do |key, value|
137
+ attributes = xmlns ? {:xmlns => xmlns} : {}
138
+
139
+ #If the XML tag requires attributes,
140
+ #the tag name will contain a space
141
+ #followed by a string representation
142
+ #of a hash of attributes.
143
+ #
144
+ #e.g. 'sObject {"xsi:type" => "Opportunity"}'
145
+ #becomes <sObject xsi:type="Opportunity>...</sObject>
146
+ if key.is_a? String
147
+ key, modifier = key.split(' ', 2)
148
+
149
+ attributes.merge!(eval(modifier)) if modifier
150
+ end
151
+
152
+ #Create an XML element and fill it with this
153
+ #value's sub-items.
154
+ case value
155
+ when Hash, Array
156
+ builder.tag!(key, attributes) do expand builder, value; end
128
157
 
158
+ when String
159
+ builder.tag!(key, attributes) { builder.text! value }
160
+ end
161
+ end
162
+ end
163
+
129
164
  #Implements the connection to the SalesForce server.
130
165
  class Binding
166
+ include RForce
167
+
131
168
  DEFAULT_BATCH_SIZE = 10
132
169
  attr_accessor :batch_size, :url, :assignment_rule_id, :use_default_rule, :update_mru, :client_id, :trigger_user_email,
133
170
  :trigger_other_email, :trigger_auto_response_email
@@ -162,7 +199,7 @@ module RForce
162
199
  ClientIdHeader = '<partner:CallOptions soap:mustUnderstand="1"><partner:client>%s</partner:client></partner:CallOptions>'
163
200
 
164
201
  #Connect to the server securely.
165
- def initialize(url, sid)
202
+ def initialize(url, sid = nil)
166
203
  init_server(url)
167
204
 
168
205
  @session_id = sid
@@ -212,7 +249,7 @@ module RForce
212
249
  #Create XML text from the arguments.
213
250
  expanded = ''
214
251
  @builder = Builder::XmlMarkup.new(:target => expanded)
215
- expand({method => args}, 'urn:partner.soap.sforce.com')
252
+ expand(@builder, {method => args}, 'urn:partner.soap.sforce.com')
216
253
 
217
254
  extra_headers = ""
218
255
  extra_headers << (AssignmentRuleHeaderUsingRuleId % assignment_rule_id) if assignment_rule_id
@@ -322,41 +359,5 @@ module RForce
322
359
 
323
360
  call_remote method, args[0]
324
361
  end
325
-
326
-
327
- #Expand Ruby data structures into XML.
328
- def expand(args, xmlns = nil)
329
- #Nest arrays: [:a, 1, :b, 2] => [[:a, 1], [:b, 2]]
330
- if (args.class == Array)
331
- args.each_index{|i| args[i, 2] = [args[i, 2]]}
332
- end
333
-
334
- args.each do |key, value|
335
- attributes = xmlns ? {:xmlns => xmlns} : {}
336
-
337
- #If the XML tag requires attributes,
338
- #the tag name will contain a space
339
- #followed by a string representation
340
- #of a hash of attributes.
341
- #
342
- #e.g. 'sObject {"xsi:type" => "Opportunity"}'
343
- #becomes <sObject xsi:type="Opportunity>...</sObject>
344
- if key.is_a? String
345
- key, modifier = key.split(' ', 2)
346
-
347
- attributes.merge!(eval(modifier)) if modifier
348
- end
349
-
350
- #Create an XML element and fill it with this
351
- #value's sub-items.
352
- case value
353
- when Hash, Array
354
- @builder.tag!(key, attributes) do expand value; end
355
-
356
- when String
357
- @builder.tag!(key, attributes) { @builder.text! value }
358
- end
359
- end
360
- end
361
362
  end
362
363
  end
data/spec/rforce_spec.rb CHANGED
@@ -9,3 +9,45 @@ describe FlashHash do
9
9
  h.nonexistent.should be_nil
10
10
  end
11
11
  end
12
+
13
+ describe 'expand' do
14
+ it 'turns Ruby into XML' do
15
+ xmlns = 'urn:partner.soap.sforce.com'
16
+
17
+ # 'sObject {"xsi:type" => "Opportunity"}'
18
+
19
+ expanded = ''
20
+ builder = Builder::XmlMarkup.new(:target => expanded)
21
+
22
+ data =
23
+ ['partner:create',
24
+ ['partner:sObjects',
25
+ ['spartner:type', 'Contact',
26
+ 'AccountId', '01234567890ABCD',
27
+ 'FirstName', 'Jane',
28
+ 'LastName', 'Doe'],
29
+ 'partner:sObjects',
30
+ ['spartner:type', 'Account',
31
+ 'Name', 'Acme Rockets, Inc.']]]
32
+
33
+ expand(builder, data)
34
+
35
+ expanded.should == CreateXml
36
+ end
37
+ end
38
+
39
+ CreateXml = <<HERE.gsub(/\n\s*/, '')
40
+ <partner:create>
41
+ <partner:sObjects>
42
+ <spartner:type>Contact</spartner:type>
43
+ <AccountId>01234567890ABCD</AccountId>
44
+ <FirstName>Jane</FirstName>
45
+ <LastName>Doe</LastName>
46
+ </partner:sObjects>
47
+ <partner:sObjects>
48
+ <spartner:type>Account</spartner:type>
49
+ <Name>Acme Rockets, Inc.</Name>
50
+ </partner:sObjects>
51
+ </partner:create>
52
+ HERE
53
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Dees
@@ -9,9 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-03 00:00:00 -07:00
12
+ date: 2008-07-04 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: builder
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ version:
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: hoe
17
37
  type: :development