use_salesforce_dataloader 0.0.6 → 0.0.8

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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/use_salesforce_dataloader.rb +123 -45
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0ab36d2a09a460f3b092870ace1bedbd63332784
4
- data.tar.gz: 3d6d104e5b0357c3091c74e158e28b99e1e89a57
2
+ SHA256:
3
+ metadata.gz: 8ddaf30c25c5ec5c092d0de40e2477b622bfb441eae8fd9556432de57a19498d
4
+ data.tar.gz: 6f2c3c603164383be7326b7690d104cbbd394882476fe1e96b74234896b38916
5
5
  SHA512:
6
- metadata.gz: 5fa2faaf0084cfe2418d37ed56564e7baedd8a9dbd580aa2027db08a071ba3a270e249cc1d33295276869bb75dba30db9e0096d0496ede68c311f817d211c0be
7
- data.tar.gz: f17d8bb60aa544ba798a1746af208557332c01c102928461673aced76f5ad2c3d27cb475001f191b991257ae3cb1fa88abf9a418f2aeb31ffa27ef56982bf808
6
+ metadata.gz: 5e909679727ea08bc3f7e84c885821ba38e6241fbdaffe70cba12510fcf860d20c388fd0e772f721d4eb7ad29de30be17a7321d13a05cdb713c043ea0034d763
7
+ data.tar.gz: 7cdbe099b7a94449b8fe637246f78e16c6d78b417a0ab2a9ccc09430938784571e88db077cf653fa2d50fe3c2007861654a9b3d7eeb35d08c77a586619bd27a9
@@ -1,38 +1,83 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'open3'
3
3
 
4
- # see https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/loader_params.htm
4
+ # @see https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/loader_params.htm
5
+ # Standard file layout (allow different layout):
6
+ # - <tt>conf_dir/</tt>
7
+ # - <tt>key.txt</tt>
8
+ # - <tt>process-conf.xml</tt>
9
+ # - <tt>map.sdl</tt>
10
+ #
5
11
  class UseSalesforceDataLoader
12
+ VERSION = '0.0.8'
6
13
 
7
- # File layout:
8
- # conf_dir/key.txt
9
- # conf_dir/process-conf.xml
10
- # conf_dir/map.sdl
11
- attr_accessor :conf_dir
12
- attr_accessor :conf_key_file
13
- attr_accessor :conf_process_xml_file
14
- attr_accessor :conf_map_file
14
+ # Setter for <tt>@conf_dir</tt>, set values <tt>@conf_key_file</tt>, <tt>@conf_process_xml_file</tt> and <tt>@conf_map_file</tt> at the same time.
15
15
  def conf_dir=(path)
16
16
  @conf_dir = path
17
17
  @conf_key_file = @conf_dir + '/key.txt'
18
- @conf_process_xml_file = @conf_dir + '/process-conf.xml'
19
18
  @conf_map_file = @conf_dir + '/map.sdl'
19
+ @conf_process_xml_file = @conf_dir + '/process-conf.xml'
20
+ @conf_dir
20
21
  end
21
22
 
22
- # process-conf.xml
23
+ # @return [String] path of conf_dir
24
+ # @see #conf_dir=
25
+ def conf_dir
26
+ @conf_dir
27
+ end
28
+
29
+ # @return [String] path of conf_key_file.
30
+ # @see #conf_dir=
31
+ attr_accessor :conf_key_file
32
+
33
+ # @return [String] path of conf_process_xml_file
34
+ # @see #conf_dir=
35
+ attr_accessor :conf_process_xml_file
36
+
37
+ # @return [String] path of conf_map_file
38
+ # @see #conf_dir=
39
+ attr_accessor :conf_map_file
40
+
41
+ # Set/get <tt>sfdc.endpoint</tt> in XML config.
42
+ # @return [String]
43
+ # @example
44
+ # dataloader.endpoint = 'https://' + 'test.salesforce.com'
45
+ attr_accessor :endpoint
46
+
47
+ # Set/get <tt>sfdc.username</tt> in XML config.
48
+ # @return [String]
49
+ # @example
50
+ # dataloader.usrname = 'foo@example.com'
51
+ attr_accessor :username
52
+
53
+ # Set/get <tt>sfdc.password</tt> in XML config.
54
+ # @return [String]
55
+ # @example
56
+ # dataloader.password = '0123456789'
57
+ attr_accessor :password
58
+
59
+ # @return [String]
60
+ # @see PROCESS_XML_TEMPLATE
23
61
  attr_accessor :bean_id
62
+
63
+ # @return [String]
64
+ # @see PROCESS_XML_TEMPLATE
24
65
  attr_accessor :bean_description
66
+
67
+ # @return [String]
68
+ # @see PROCESS_XML_TEMPLATE
25
69
  attr_accessor :property_name
26
- attr_accessor :overwrite_entries
27
70
 
28
- # Salesforce.com authentication data
29
- attr_accessor :endpoint # ex. https://test.salesforce.com
30
- attr_accessor :username # ex. foo@example.com
31
- attr_accessor :password # ex. 0123456789
71
+ # @return [String]
72
+ # @see BASE_ENTRIES
73
+ attr_accessor :overwrite_entries
32
74
 
33
- # jar: path of dataloader-NN.N.N-uber.jar, ex. "/usr/lib/dataloader-41.0.0-uber.jar"
34
- # java: command line of java runtime, ex. "/usr/bin/java"
35
- # java_opt: ex. "-Dfile.encoding=UTF-8"
75
+ # @param jar [String] path of dataloader-NN.N.N-uber.jar.
76
+ # @param java [String] path of java runtime.
77
+ # @param java_opt [String] command line option for java runtime.
78
+ # @example
79
+ # UseSalesforceDataLoader.new('/usr/lib/dataloader-41.0.0-uber.jar', '/usr/bin/java', '-Dfile.encoding=UTF-8')
80
+ #
36
81
  def initialize(jar, java = nil, java_opt = nil)
37
82
  java = exec_command('which java') unless java
38
83
  path_check(java)
@@ -42,22 +87,17 @@ class UseSalesforceDataLoader
42
87
  @process = "#{j} -Dsalesforce.config.dir=%s com.salesforce.dataloader.process.ProcessRunner process.name=%s"
43
88
  end
44
89
 
45
- # Original: dataloader/bin/encrypt.sh
46
- # Usage: dataloader/bin/encrypt.sh
47
- # Utility to encrypt a string based on a static or a provided key
48
- # Options (mutually exclusive - use one at a time):
49
- # -g <seed text> Generate key based on seed
50
- # -v <encrypted> <decrypted value> [Path to Key] Validate whether decryption of encrypted value matches the decrypted value, optionally provide key file
51
- # -e <plain text> [Path to Key] Encrypt a plain text value, optionally provide key file (generate key using option -g)
90
+ # @note
52
91
  #
53
- def encrypt(args)
54
- cmd = "#{@encrypt} #{args} | sed 's/^.*) \- //g'"
55
- exec_command(cmd)
56
- end
57
-
58
- # Original: dataloader/bin/process.sh
59
- # Usage: dataloader/bin/process.sh [conf-dir] <process-name>
92
+ # Original:
93
+ #
94
+ # dataloader/bin/process.sh
60
95
  #
96
+ # Usage: dataloader/bin/process.sh [conf-dir] <process-name>
97
+ #
98
+ # Return command line string for execute dataloader by named process.
99
+ # @param name [String]
100
+ # @return [String] command line
61
101
  def process_cmd(name)
62
102
  path_check(@conf_dir)
63
103
  path_check(@conf_process_xml_file)
@@ -65,6 +105,8 @@ class UseSalesforceDataLoader
65
105
  end
66
106
 
67
107
  # Save encrypt key file
108
+ # @see #conf_key_file
109
+ # @return [String] conf_key_file
68
110
  def save_conf_key_file
69
111
  @conf_key_file.tap do |f|
70
112
  open(f, 'w:UTF-8') do |o|
@@ -74,6 +116,8 @@ class UseSalesforceDataLoader
74
116
  end
75
117
 
76
118
  # Save conf xml file
119
+ # @see #conf_process_xml
120
+ # @return [String] conf_process_xml_file
77
121
  def save_conf_process_xml_file
78
122
  @conf_process_xml_file.tap do |f|
79
123
  open(f, 'w:UTF-8') do |o|
@@ -83,6 +127,7 @@ class UseSalesforceDataLoader
83
127
  end
84
128
 
85
129
  # Generate XML config
130
+ # @return [String] xml config
86
131
  def conf_process_xml
87
132
  entries = BASE_ENTRIES.merge(default_overwrite_entries)
88
133
  entries.merge!(@overwrite_entries) if @overwrite_entries
@@ -97,9 +142,35 @@ class UseSalesforceDataLoader
97
142
  entries_xml]
98
143
  end
99
144
 
100
- private
145
+ # @note
146
+ #
147
+ # Original:
148
+ #
149
+ # dataloader/bin/encrypt.sh
150
+ #
151
+ # Usage: dataloader/bin/encrypt.sh
152
+ #
153
+ # Utility to encrypt a string based on a static or a provided key
154
+ #
155
+ # Options (mutually exclusive - use one at a time):
156
+ #
157
+ # -g <seed text> Generate key based on seed
158
+ #
159
+ # -v <encrypted> <decrypted value> [Path to Key] Validate whether decryption of encrypted value matches the decrypted value, optionally provide key file
160
+ #
161
+ # -e <plain text> [Path to Key] Encrypt a plain text value, optionally provide key file (generate key using option -g)
162
+ #
163
+ # internal use
164
+ # @param [String] options
165
+ # @return [String]
166
+ def encrypt(options)
167
+ cmd = "#{@encrypt} #{options} | sed 's/^.*) \- //g'"
168
+ exec_command(cmd)
169
+ end
101
170
 
102
171
  # internal use
172
+ # @see #conf_process_xml
173
+ # @return [Hash]
103
174
  def default_overwrite_entries
104
175
  path_check(@conf_key_file)
105
176
  encrypt_password = encrypt("-e '#{@password}' '#{@conf_key_file}'")
@@ -115,22 +186,27 @@ class UseSalesforceDataLoader
115
186
  end
116
187
 
117
188
  # interal use
118
- def text_seed
189
+ # @return [String] random seed
190
+ private def text_seed
119
191
  rand(0xffff_ffff).to_s(16)
120
192
  end
121
193
 
122
194
  # internal use
123
- def path_check(f)
195
+ # @return [true, false]
196
+ private def path_check(f)
124
197
  raise "Path not found: #{f}" unless File.exist?(f)
125
198
  end
126
199
 
127
200
  # internal use
128
- def exec_command(cmd)
201
+ # @param [String] cmd
202
+ # @return [String] stdout of cmd
203
+ private def exec_command(cmd)
129
204
  o, e, s = Open3.capture3(cmd)
130
205
  raise "Something wrong" unless e.empty? and s.success?
131
206
  o.chomp
132
207
  end
133
208
 
209
+ # @note internal use
134
210
  PROCESS_XML_TEMPLATE = <<'PROCESS_XML'
135
211
  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
136
212
  <beans>
@@ -148,10 +224,12 @@ class UseSalesforceDataLoader
148
224
  </beans>
149
225
  PROCESS_XML
150
226
 
227
+ # @note internal use
151
228
  ENTRIES_XML_TEMPLATE = <<'ENTRIES_XML'
152
229
  <entry key="%s" value="%s"/>
153
230
  ENTRIES_XML
154
231
 
232
+ # @note internal use
155
233
  BASE_ENTRIES = {
156
234
  'dataAccess.readUTF8' => 'true',
157
235
  'dataAccess.writeUTF8' => 'true',
@@ -161,13 +239,13 @@ ENTRIES_XML
161
239
  'dataAccess.writeBatchSize' => nil,
162
240
  'process.enableExtractStatusOutput' => 'false',
163
241
  'process.enableLastRunOutput' => 'true',
164
- 'process.encryptionKeyFile' => nil,
242
+ 'process.encryptionKeyFile' => nil, # see also #conf_dir
165
243
  'process.initialLastRunDate' => nil,
166
- 'process.lastRunOutputDirectory' => nil,
244
+ 'process.lastRunOutputDirectory' => nil, # see also #conf_dir
167
245
  'process.loadRowToStartAt' => nil,
168
- 'process.mappingFile' => nil,
246
+ 'process.mappingFile' => nil, # see also #conf_dir
169
247
  'process.operation' => nil,
170
- 'process.statusOutputDirectory' => nil,
248
+ 'process.statusOutputDirectory' => nil, # see also #conf_dir
171
249
  'process.outputError' => nil,
172
250
  'process.outputSuccess' => nil,
173
251
  'process.useEuropeanDates' => nil,
@@ -179,17 +257,17 @@ ENTRIES_XML
179
257
  'sfdc.debugMessages' => nil,
180
258
  'sfdc.debugMessagesFile' => nil,
181
259
  'sfdc.enableRetries' => nil,
182
- 'sfdc.endpoint' => nil,
260
+ 'sfdc.endpoint' => nil, # see also #endpoint
183
261
  'sfdc.entity' => nil,
184
262
  'sfdc.externalIdField' => nil,
185
263
  'sfdc.extractionRequestSize' => nil,
186
264
  'sfdc.extractionSOQL' => nil,
187
265
  'sfdc.insertNulls' => 'true',
188
- 'sfdc.loadBatchSize' => nil,
266
+ 'sfdc.loadBatchSize' => nil, # recommended value? -> 200(Not Bulk API) / 2000(Bulk API)
189
267
  'sfdc.maxRetries' => nil,
190
268
  'sfdc.minRetrySleepSecs' => nil,
191
269
  'sfdc.noCompression' => nil,
192
- 'sfdc.password' => nil,
270
+ 'sfdc.password' => nil, # see also #password
193
271
  'sfdc.proxyHost' => nil,
194
272
  'sfdc.proxyPassword' => nil,
195
273
  'sfdc.proxyPort' => nil,
@@ -199,6 +277,6 @@ ENTRIES_XML
199
277
  'sfdc.timezone' => nil,
200
278
  'sfdc.truncateFields' => 'false',
201
279
  'sfdc.useBulkApi' => nil,
202
- 'sfdc.username' => nil,
280
+ 'sfdc.username' => nil, # see also #username
203
281
  }
204
282
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use_salesforce_dataloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroaki Nagoya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: hnagoya@gmail.com
@@ -19,7 +19,7 @@ files:
19
19
  - lib/use_salesforce_dataloader.rb
20
20
  homepage: https://rubygems.org/gems/use_salesforce_dataloader
21
21
  licenses:
22
- - Apache 2.0
22
+ - Apache-2.0
23
23
  metadata: {}
24
24
  post_install_message:
25
25
  rdoc_options: []
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.2.0
40
+ rubygems_version: 2.7.3
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: Force.com Apex Data Loader for Ruby/Linux - command line version