yasd 0.1.0
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.
- checksums.yaml +7 -0
- data/.dockerignore +1 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +5 -0
- data/Dockerfile +9 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +21 -0
- data/Makefile +25 -0
- data/README.md +56 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/yasd +11 -0
- data/lib/yasd.rb +7 -0
- data/lib/yasd/cli.rb +87 -0
- data/lib/yasd/config.rb +13 -0
- data/lib/yasd/converter.rb +34 -0
- data/lib/yasd/dataloader.rb +136 -0
- data/lib/yasd/mapper.rb +17 -0
- data/lib/yasd/version.rb +5 -0
- data/yasd.gemspec +32 -0
- metadata +166 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 40b161d558405beb2eecc10156838716b0bf814792a03b61b6e2c9ec00c5d1ae
|
|
4
|
+
data.tar.gz: c3ac3245d39f333a051896dbeb1ad9ba681112fa714865fea01566a6614b56e1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d77d33263d907c6ea126dba8ba76e54941bc2dad890f2397e53c4ba680b236288f49cb1643b721be4d7831e78c01690e710b0933cbd8b2eed0e017dc992ae291
|
|
7
|
+
data.tar.gz: eed37c9ec5cfc42a2768e0ef23bc4992d063bab3daec11e178511af7b5a0a7ac62008e4ab2ccd6952f246c40de0f71ec33c1d76c6ca3dec6ef0e3a2e036aadec
|
data/.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/vendor/bundle
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
yasd (0.1.0)
|
|
5
|
+
soapforce (~> 0.7.0)
|
|
6
|
+
thor (~> 0.20.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
akami (1.3.1)
|
|
12
|
+
gyoku (>= 0.4.0)
|
|
13
|
+
nokogiri
|
|
14
|
+
ast (2.4.0)
|
|
15
|
+
builder (3.2.3)
|
|
16
|
+
byebug (10.0.2)
|
|
17
|
+
coderay (1.1.2)
|
|
18
|
+
diff-lcs (1.3)
|
|
19
|
+
dotenv (2.5.0)
|
|
20
|
+
gyoku (1.3.1)
|
|
21
|
+
builder (>= 2.1.2)
|
|
22
|
+
httpi (2.4.3)
|
|
23
|
+
rack
|
|
24
|
+
socksify
|
|
25
|
+
jaro_winkler (1.5.1)
|
|
26
|
+
method_source (0.9.0)
|
|
27
|
+
mini_portile2 (2.3.0)
|
|
28
|
+
nokogiri (1.8.4)
|
|
29
|
+
mini_portile2 (~> 2.3.0)
|
|
30
|
+
nori (2.6.0)
|
|
31
|
+
onkcop (0.53.0.1)
|
|
32
|
+
rubocop (>= 0.53.0)
|
|
33
|
+
rubocop-rspec (>= 1.24.0)
|
|
34
|
+
parallel (1.12.1)
|
|
35
|
+
parser (2.5.1.2)
|
|
36
|
+
ast (~> 2.4.0)
|
|
37
|
+
powerpack (0.1.2)
|
|
38
|
+
pry (0.11.3)
|
|
39
|
+
coderay (~> 1.1.0)
|
|
40
|
+
method_source (~> 0.9.0)
|
|
41
|
+
pry-byebug (3.6.0)
|
|
42
|
+
byebug (~> 10.0)
|
|
43
|
+
pry (~> 0.10)
|
|
44
|
+
rack (2.0.5)
|
|
45
|
+
rainbow (3.0.0)
|
|
46
|
+
rake (10.5.0)
|
|
47
|
+
rspec (3.8.0)
|
|
48
|
+
rspec-core (~> 3.8.0)
|
|
49
|
+
rspec-expectations (~> 3.8.0)
|
|
50
|
+
rspec-mocks (~> 3.8.0)
|
|
51
|
+
rspec-core (3.8.0)
|
|
52
|
+
rspec-support (~> 3.8.0)
|
|
53
|
+
rspec-expectations (3.8.1)
|
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
55
|
+
rspec-support (~> 3.8.0)
|
|
56
|
+
rspec-mocks (3.8.0)
|
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
58
|
+
rspec-support (~> 3.8.0)
|
|
59
|
+
rspec-support (3.8.0)
|
|
60
|
+
rubocop (0.58.2)
|
|
61
|
+
jaro_winkler (~> 1.5.1)
|
|
62
|
+
parallel (~> 1.10)
|
|
63
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
64
|
+
powerpack (~> 0.1)
|
|
65
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
66
|
+
ruby-progressbar (~> 1.7)
|
|
67
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
68
|
+
rubocop-rspec (1.29.0)
|
|
69
|
+
rubocop (>= 0.58.0)
|
|
70
|
+
ruby-progressbar (1.10.0)
|
|
71
|
+
savon (2.12.0)
|
|
72
|
+
akami (~> 1.2)
|
|
73
|
+
builder (>= 2.1.2)
|
|
74
|
+
gyoku (~> 1.2)
|
|
75
|
+
httpi (~> 2.3)
|
|
76
|
+
nokogiri (>= 1.8.1)
|
|
77
|
+
nori (~> 2.4)
|
|
78
|
+
wasabi (~> 3.4)
|
|
79
|
+
soapforce (0.7.0)
|
|
80
|
+
savon (>= 2.3.0, < 3.0.0)
|
|
81
|
+
socksify (1.7.1)
|
|
82
|
+
thor (0.20.0)
|
|
83
|
+
unicode-display_width (1.4.0)
|
|
84
|
+
wasabi (3.5.0)
|
|
85
|
+
httpi (~> 2.0)
|
|
86
|
+
nokogiri (>= 1.4.2)
|
|
87
|
+
|
|
88
|
+
PLATFORMS
|
|
89
|
+
ruby
|
|
90
|
+
|
|
91
|
+
DEPENDENCIES
|
|
92
|
+
bundler (~> 1.16)
|
|
93
|
+
dotenv
|
|
94
|
+
onkcop
|
|
95
|
+
pry-byebug
|
|
96
|
+
rake (~> 10.0)
|
|
97
|
+
rspec (~> 3.0)
|
|
98
|
+
rubocop
|
|
99
|
+
yasd!
|
|
100
|
+
|
|
101
|
+
BUNDLED WITH
|
|
102
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Makoto Tajitsu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.PHONY: insert
|
|
2
|
+
insert:
|
|
3
|
+
bundle exec exe/yasd insert -f examples/accounts.csv \
|
|
4
|
+
-c examples/config.rb \
|
|
5
|
+
-o Account \
|
|
6
|
+
-m examples/account.sdl.yml \
|
|
7
|
+
-C examples/account.cvt.rb
|
|
8
|
+
|
|
9
|
+
.PHONY: export
|
|
10
|
+
export:
|
|
11
|
+
bundle exec exe/yasd export \
|
|
12
|
+
-c examples/config.yml \
|
|
13
|
+
-q "SELECT Id, Name FROM Message__c"
|
|
14
|
+
|
|
15
|
+
.PHONY: rubocop
|
|
16
|
+
rubocop:
|
|
17
|
+
bundle exec rubocop -a
|
|
18
|
+
|
|
19
|
+
.PHONY: test
|
|
20
|
+
test:
|
|
21
|
+
bundle exec rspec
|
|
22
|
+
|
|
23
|
+
.PHONY: build
|
|
24
|
+
build:
|
|
25
|
+
docker build -t tzmfreedom/yasd .
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Yasd
|
|
2
|
+
|
|
3
|
+
Yet Another Salesforce Dataloader
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
$ gem install yasd
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
or
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
$ docker run -it --rm tzmfreedom/yasd
|
|
15
|
+
```
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Export
|
|
19
|
+
```bash
|
|
20
|
+
$ yasd export -q "SELECT id FROM Account"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Insert
|
|
24
|
+
```bash
|
|
25
|
+
$ yasd insert -f /path/to/insert.csv
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Update
|
|
29
|
+
```bash
|
|
30
|
+
$ yasd update -f /path/to/update.csv
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Upsert
|
|
34
|
+
```bash
|
|
35
|
+
$ yasd upsert -f /path/to/upsert.csv -k externalkey__c
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Delete
|
|
39
|
+
```bash
|
|
40
|
+
$ yasd delete -f /path/to/delete.csv
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
47
|
+
|
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
49
|
+
|
|
50
|
+
## Contributing
|
|
51
|
+
|
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yasd.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'yasd'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/yasd
ADDED
data/lib/yasd.rb
ADDED
data/lib/yasd/cli.rb
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'yasd/dataloader'
|
|
6
|
+
|
|
7
|
+
module Yasd
|
|
8
|
+
class CLI < Thor
|
|
9
|
+
desc 'load', 'Load to Salesforce with local file'
|
|
10
|
+
method_option :query, type: :string, aliases: ['-q']
|
|
11
|
+
method_option :config, type: :string, aliases: ['-c']
|
|
12
|
+
method_option :username, type: :string, aliases: ['-u'], default: ENV['SALESFORCE_USERNAME']
|
|
13
|
+
method_option :password, type: :string, aliases: ['-p'], default: ENV['SALESFORCE_PASSWORD']
|
|
14
|
+
method_option :api_version, type: :string, default: ENV['SALESFORCE_API_VERSION']
|
|
15
|
+
def export
|
|
16
|
+
config = create_config(options.config)
|
|
17
|
+
dataloader = Dataloader.new(config)
|
|
18
|
+
dataloader.export(config.query)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc 'insert', 'Insert records'
|
|
22
|
+
method_option :file, type: :string, aliases: ['-f']
|
|
23
|
+
method_option :object, type: :string, aliases: ['-o']
|
|
24
|
+
method_option :config, type: :string, aliases: ['-c']
|
|
25
|
+
method_option :mapping, type: :string, aliases: ['-m']
|
|
26
|
+
method_option :convert, type: :string, aliases: ['-C']
|
|
27
|
+
method_option :username, type: :string, aliases: ['-u'], default: ENV['SALESFORCE_USERNAME']
|
|
28
|
+
method_option :password, type: :string, aliases: ['-p'], default: ENV['SALESFORCE_PASSWORD']
|
|
29
|
+
method_option :api_version, type: :string, default: ENV['SALESFORCE_API_VERSION']
|
|
30
|
+
def insert
|
|
31
|
+
config = create_config(options.config)
|
|
32
|
+
dataloader = Dataloader.new(config)
|
|
33
|
+
dataloader.insert(config.object, config.file)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
desc 'update', 'Update records'
|
|
37
|
+
method_option :file, type: :string, aliases: ['-f']
|
|
38
|
+
method_option :object, type: :string, aliases: ['-o']
|
|
39
|
+
method_option :config, type: :string, aliases: ['-c']
|
|
40
|
+
method_option :mapping, type: :string, aliases: ['-m']
|
|
41
|
+
method_option :convert, type: :string, aliases: ['-C']
|
|
42
|
+
method_option :username, type: :string, aliases: ['-u'], default: ENV['SALESFORCE_USERNAME']
|
|
43
|
+
method_option :password, type: :string, aliases: ['-p'], default: ENV['SALESFORCE_PASSWORD']
|
|
44
|
+
method_option :api_version, type: :string, default: ENV['SALESFORCE_API_VERSION']
|
|
45
|
+
def update
|
|
46
|
+
config = create_config(options.config)
|
|
47
|
+
dataloader = Dataloader.new(config)
|
|
48
|
+
dataloader.update(config.object, config.file)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
desc 'upsert', 'Upsert records'
|
|
52
|
+
method_option :file, type: :string, aliases: ['-f']
|
|
53
|
+
method_option :object, type: :string, aliases: ['-o']
|
|
54
|
+
method_option :upsert_key, type: :string, aliases: ['-k']
|
|
55
|
+
method_option :mapping, type: :string, aliases: ['-m']
|
|
56
|
+
method_option :convert, type: :string, aliases: ['-C']
|
|
57
|
+
method_option :config, type: :string, aliases: ['-c']
|
|
58
|
+
method_option :username, type: :string, aliases: ['-u'], default: ENV['SALESFORCE_USERNAME']
|
|
59
|
+
method_option :password, type: :string, aliases: ['-p'], default: ENV['SALESFORCE_PASSWORD']
|
|
60
|
+
method_option :api_version, type: :string, default: ENV['SALESFORCE_API_VERSION']
|
|
61
|
+
def upsert
|
|
62
|
+
config = create_config(options.config)
|
|
63
|
+
dataloader = Dataloader.new(config)
|
|
64
|
+
dataloader.upsert(config.object, config.upsert_key, config.file)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
desc 'delete', 'Delete records'
|
|
68
|
+
method_option :file, type: :string, aliases: ['-f']
|
|
69
|
+
method_option :object, type: :string, aliases: ['-o']
|
|
70
|
+
method_option :config, type: :string, aliases: ['-c']
|
|
71
|
+
method_option :username, type: :string, aliases: ['-u'], default: ENV['SALESFORCE_USERNAME']
|
|
72
|
+
method_option :password, type: :string, aliases: ['-p'], default: ENV['SALESFORCE_PASSWORD']
|
|
73
|
+
method_option :api_version, type: :string, default: ENV['SALESFORCE_API_VERSION']
|
|
74
|
+
def delete
|
|
75
|
+
config = create_config(options.config)
|
|
76
|
+
dataloader = Dataloader.new(config)
|
|
77
|
+
dataloader.delete(config.object, config.file)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def create_config(filepath)
|
|
83
|
+
config = YAML.load_file(filepath)
|
|
84
|
+
options.merge(config)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
data/lib/yasd/config.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Yasd
|
|
4
|
+
class Converter
|
|
5
|
+
def initialize(filename)
|
|
6
|
+
@converters = {}
|
|
7
|
+
if filename
|
|
8
|
+
contents = File.read(filename)
|
|
9
|
+
instance_eval(contents)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call(data)
|
|
14
|
+
data.headers.each_with_object({}) do |field, new_object|
|
|
15
|
+
new_object[field] = convert_field(field, data[field])
|
|
16
|
+
new_object
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
# for DSL
|
|
23
|
+
def convert(header, &block)
|
|
24
|
+
@converters[header] ||= []
|
|
25
|
+
@converters[header] << block
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def convert_field(header, value)
|
|
29
|
+
(@converters[header] || []).reduce(value) do |_result, proc|
|
|
30
|
+
proc.call(value)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'soapforce'
|
|
6
|
+
require 'yasd/mapper'
|
|
7
|
+
require 'yasd/converter'
|
|
8
|
+
|
|
9
|
+
module Yasd
|
|
10
|
+
class Dataloader
|
|
11
|
+
attr_accessor :client
|
|
12
|
+
|
|
13
|
+
BATCH_SIZE = 400
|
|
14
|
+
|
|
15
|
+
def initialize(config)
|
|
16
|
+
@client = Soapforce::Client.new
|
|
17
|
+
@client.authenticate(username: config.username, password: config.password)
|
|
18
|
+
@success_logger = Logger.new(config.success_log_path || "./results/#{Time.now.strftime("%Y-%m-%d")}_success.log")
|
|
19
|
+
@error_logger = Logger.new(config.success_log_path || "./results/#{Time.now.strftime("%Y-%m-%d")}_error.log")
|
|
20
|
+
@mapper = Mapper.new(config.mapping)
|
|
21
|
+
@converter = Converter.new(config.convert)
|
|
22
|
+
@batch_size = config.batch_size || BATCH_SIZE
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def export(query)
|
|
26
|
+
query_result = client.query(query)
|
|
27
|
+
return if query_result.size == 0
|
|
28
|
+
|
|
29
|
+
CSV do |csv_out|
|
|
30
|
+
header = create_csv_header(query_result)
|
|
31
|
+
csv_out << header
|
|
32
|
+
|
|
33
|
+
query_result.each do |record|
|
|
34
|
+
csv_out << header.map {|field| record[field] }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def insert(object, filename)
|
|
40
|
+
insert_records = []
|
|
41
|
+
total_record_size = 0
|
|
42
|
+
|
|
43
|
+
CSV.foreach(filename, headers: true) do |data|
|
|
44
|
+
total_record_size += 1
|
|
45
|
+
insert_records << convert_and_mapping(data)
|
|
46
|
+
if insert_records.length == @batch_size
|
|
47
|
+
insert_results = client.create!(object, insert_records)
|
|
48
|
+
log(insert_results)
|
|
49
|
+
insert_records = []
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
if insert_records.length > 0
|
|
53
|
+
insert_results = client.create!(object, insert_records)
|
|
54
|
+
log(insert_results)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def update(object, filename)
|
|
59
|
+
update_records = []
|
|
60
|
+
total_record_size = 0
|
|
61
|
+
|
|
62
|
+
CSV.foreach(filename, headers: true) do |data|
|
|
63
|
+
total_record_size += 1
|
|
64
|
+
update_records << convert_and_mapping(data)
|
|
65
|
+
if update_records.length == @batch_size
|
|
66
|
+
update_results = client.update(object, update_records)
|
|
67
|
+
log(update_results)
|
|
68
|
+
update_records = []
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
if update_records.length > 0
|
|
72
|
+
update_results = client.update(object, update_records)
|
|
73
|
+
log(update_results)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def delete(object, filename)
|
|
78
|
+
delete_records = []
|
|
79
|
+
total_record_size = 0
|
|
80
|
+
|
|
81
|
+
CSV.foreach(filename, headers: true) do |data|
|
|
82
|
+
total_record_size += 1
|
|
83
|
+
delete_records << data[:Id]
|
|
84
|
+
if delete_records.length == @batch_size
|
|
85
|
+
delete_results = client.delete(object, delete_records)
|
|
86
|
+
log(delete_results)
|
|
87
|
+
delete_records = []
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
if delete_records.length > 0
|
|
91
|
+
delete_results = client.delete(object, delete_records)
|
|
92
|
+
log(delete_results)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def upsert(object, upsert_key, filename)
|
|
97
|
+
upsert_records = []
|
|
98
|
+
total_record_size = 0
|
|
99
|
+
|
|
100
|
+
CSV.foreach(filename, headers: true) do |data|
|
|
101
|
+
total_record_size += 1
|
|
102
|
+
upsert_records << convert_and_mapping(data)
|
|
103
|
+
if upsert_records.length == @batch_size
|
|
104
|
+
upsert_results = client.upsert(object, upsert_key, upsert_records)
|
|
105
|
+
log(upsert_results)
|
|
106
|
+
upsert_records = []
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
if upsert_records.length > 0
|
|
110
|
+
upsert_results = client.upsert(object, upsert_key, upsert_records)
|
|
111
|
+
log(upsert_results)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def log(results)
|
|
118
|
+
results.each do |result|
|
|
119
|
+
if result[:success]
|
|
120
|
+
@success_logger.info(result.values.join(','))
|
|
121
|
+
else
|
|
122
|
+
@error_logger.info(result.values.join(','))
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def convert_and_mapping(data)
|
|
128
|
+
converted_data = @converter.call(data)
|
|
129
|
+
@mapper.call(converted_data)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def create_csv_header(query_result)
|
|
133
|
+
query_result.first.to_h.reject {|k, _v| %i[type @xsi:type].include?(k) }.keys
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
data/lib/yasd/mapper.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Yasd
|
|
4
|
+
class Mapper
|
|
5
|
+
def initialize(filepath)
|
|
6
|
+
@mappings = filepath ? YAML.load_file(filepath) : {}
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(data)
|
|
10
|
+
data.each_with_object({}) do |(field, value), new_object|
|
|
11
|
+
new_key = @mappings[field] || field
|
|
12
|
+
new_object[new_key] = value
|
|
13
|
+
new_object
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/yasd/version.rb
ADDED
data/yasd.gemspec
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'yasd/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'yasd'
|
|
9
|
+
spec.version = Yasd::VERSION
|
|
10
|
+
spec.authors = ['tzmfreedom']
|
|
11
|
+
spec.email = ['makoto_tajitsu@hotmail.co.jp']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Yet Another Salesforce Detaloader'
|
|
14
|
+
spec.description = 'Yet Another Salesforce Dataloader'
|
|
15
|
+
spec.homepage = 'https://github.com/tzmfreedom/yasd'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
|
20
|
+
end
|
|
21
|
+
spec.bindir = 'exe'
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ['lib']
|
|
24
|
+
|
|
25
|
+
spec.add_runtime_dependency 'soapforce', '~> 0.7.0'
|
|
26
|
+
spec.add_runtime_dependency 'thor', '~> 0.20.0'
|
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
28
|
+
spec.add_development_dependency 'onkcop'
|
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
31
|
+
spec.add_development_dependency 'rubocop'
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: yasd
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tzmfreedom
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: soapforce
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.7.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.7.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: thor
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.20.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.20.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.16'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.16'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: onkcop
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rubocop
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
description: Yet Another Salesforce Dataloader
|
|
112
|
+
email:
|
|
113
|
+
- makoto_tajitsu@hotmail.co.jp
|
|
114
|
+
executables:
|
|
115
|
+
- yasd
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".dockerignore"
|
|
120
|
+
- ".gitignore"
|
|
121
|
+
- ".rspec"
|
|
122
|
+
- ".rubocop.yml"
|
|
123
|
+
- ".travis.yml"
|
|
124
|
+
- Dockerfile
|
|
125
|
+
- Gemfile
|
|
126
|
+
- Gemfile.lock
|
|
127
|
+
- LICENSE.txt
|
|
128
|
+
- Makefile
|
|
129
|
+
- README.md
|
|
130
|
+
- Rakefile
|
|
131
|
+
- bin/console
|
|
132
|
+
- bin/setup
|
|
133
|
+
- exe/yasd
|
|
134
|
+
- lib/yasd.rb
|
|
135
|
+
- lib/yasd/cli.rb
|
|
136
|
+
- lib/yasd/config.rb
|
|
137
|
+
- lib/yasd/converter.rb
|
|
138
|
+
- lib/yasd/dataloader.rb
|
|
139
|
+
- lib/yasd/mapper.rb
|
|
140
|
+
- lib/yasd/version.rb
|
|
141
|
+
- yasd.gemspec
|
|
142
|
+
homepage: https://github.com/tzmfreedom/yasd
|
|
143
|
+
licenses:
|
|
144
|
+
- MIT
|
|
145
|
+
metadata: {}
|
|
146
|
+
post_install_message:
|
|
147
|
+
rdoc_options: []
|
|
148
|
+
require_paths:
|
|
149
|
+
- lib
|
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
|
+
requirements:
|
|
152
|
+
- - ">="
|
|
153
|
+
- !ruby/object:Gem::Version
|
|
154
|
+
version: '0'
|
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
requirements: []
|
|
161
|
+
rubyforge_project:
|
|
162
|
+
rubygems_version: 2.7.7
|
|
163
|
+
signing_key:
|
|
164
|
+
specification_version: 4
|
|
165
|
+
summary: Yet Another Salesforce Detaloader
|
|
166
|
+
test_files: []
|