salesforce_exporter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +16 -0
- data/Guardfile +8 -0
- data/LICENSE +8 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/salesforce_exporter.rb +12 -0
- data/lib/salesforce_exporter/client.rb +18 -0
- data/lib/salesforce_exporter/schema.rb +84 -0
- data/lib/salesforce_exporter/sqlite_writer.rb +30 -0
- data/lib/salesforce_exporter/version.rb +3 -0
- data/salesforce_exporter.gemspec +38 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0f2d9f4858712229df6e56b8df76dbd4944a457
|
4
|
+
data.tar.gz: edcb4cc32c7b199c2011244b95337f9ba4011e77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a0c9557eb3ff568b9980506e686053840decfc9745c7587615e9e2d076c5ab832a147cd5edfe8b90b9c75e2cdbba33753f216e05ed89595e895f5e40a7dba35
|
7
|
+
data.tar.gz: c879213187fb80685bb0a81079daf7974d211dbd4654816da3c370e1bd4d623552f659a361342ed17264711b7742b0438817190de01c43d1fac8447113f7ac47
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in salesforce_exporter.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test, :development do
|
7
|
+
gem "coveralls", require: false
|
8
|
+
gem "guard"
|
9
|
+
gem "guard-rspec"
|
10
|
+
gem "simplecov"
|
11
|
+
gem "pry"
|
12
|
+
|
13
|
+
gem "rb-inotify", require: false
|
14
|
+
gem "rb-fsevent", require: false
|
15
|
+
gem "rb-fchange", require: false
|
16
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, cmd: "rspec --tag ~type:integration" do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch("spec/spec_helper.rb") { "spec" }
|
8
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright (c) 2015 Leif Gensert, Propertybase GmbH
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# SalesforceExporter
|
2
|
+
|
3
|
+
This gem can be used to export salesforce objects to an SQLite database. Datatypes and indexes will be preserved.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'salesforce_exporter'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install salesforce_exporter
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Authentication
|
25
|
+
|
26
|
+
The SalesforceExporter client just passes on the credentials to the underlying client [restforce](https://github.com/ejholmes/restforce). You can use exactly the same parameters as specified in the [README of Restforce](https://github.com/ejholmes/restforce#initialization)
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
client = SalesforceExporter.new(
|
30
|
+
oauth_token: 'access_token',
|
31
|
+
refresh_token: 'refresh token',
|
32
|
+
instance_url: 'instance url',
|
33
|
+
client_id: 'client_id',
|
34
|
+
client_secret: 'client_secret',
|
35
|
+
)
|
36
|
+
```
|
37
|
+
|
38
|
+
### Export
|
39
|
+
|
40
|
+
In order to start the export, you need to specify the objects and and SQLite connection string. The exporter will return the database object after finish.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
db = client.export(objects: ["Contact", "Account"], to: "sqlite://test.db")
|
44
|
+
```
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
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.
|
49
|
+
|
50
|
+
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).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/salesforce_exporter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
55
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "salesforce_exporter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "salesforce_exporter/schema"
|
2
|
+
require "salesforce_exporter/sqlite_writer"
|
3
|
+
|
4
|
+
module SalesforceExporter
|
5
|
+
class Client
|
6
|
+
attr_reader :sf_client
|
7
|
+
|
8
|
+
def initialize(sf_client)
|
9
|
+
@sf_client = sf_client
|
10
|
+
end
|
11
|
+
|
12
|
+
def export(objects:, to:)
|
13
|
+
object_descriptions = Array(objects).map { |o| sf_client.describe(o) }
|
14
|
+
db = SalesforceExporter::Schema.new(object_descriptions, to).create
|
15
|
+
SalesforceExporter::SqliteWriter.new(sf_client, db, object_descriptions).write
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "sequel"
|
2
|
+
require "sqlite3"
|
3
|
+
|
4
|
+
module SalesforceExporter
|
5
|
+
class Schema
|
6
|
+
attr_reader :objects
|
7
|
+
attr_reader :db
|
8
|
+
|
9
|
+
def initialize(objects, db)
|
10
|
+
@objects = objects
|
11
|
+
@db = Sequel.connect(db)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
objects.each do |object|
|
16
|
+
columns = self.class.columns(object["fields"].reject{|f| f["calculated"] })
|
17
|
+
db.create_table!(object["name"]) do
|
18
|
+
columns.each do |column_definition|
|
19
|
+
send(*column_definition)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
db
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.coulumn_type(field)
|
29
|
+
type_mapping.fetch(field["type"])
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.columns(fields)
|
33
|
+
fields.map { |f| column_options(f) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.column_options(field)
|
37
|
+
method_name, _ = coulumn_type(field)
|
38
|
+
[method_name, field["name"], nil, options(field) ]
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.options(field)
|
42
|
+
_, type = coulumn_type(field)
|
43
|
+
base = { unique: field["unique"], null: field["nillable"], type: type }
|
44
|
+
base.merge!(size: field["length"]) if field["length"] > 0
|
45
|
+
|
46
|
+
if type == :decimal
|
47
|
+
base.merge!(size: [field["precision"], field["scale"]])
|
48
|
+
end
|
49
|
+
|
50
|
+
# reference = field["referenceTo"].first
|
51
|
+
# if reference
|
52
|
+
# base.merge!(table: Sequel.identifier(reference.to_sym))
|
53
|
+
# end
|
54
|
+
|
55
|
+
if type == :integer
|
56
|
+
base.merge!(size: field["digits"])
|
57
|
+
end
|
58
|
+
|
59
|
+
if field["name"].downcase == "id"
|
60
|
+
base.merge!(primary_key: true)
|
61
|
+
end
|
62
|
+
base
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.type_mapping
|
66
|
+
@_type_mapping ||= {
|
67
|
+
"email" => [:column, "VARCHAR"],
|
68
|
+
"double" => [:column, "DECIMAL"],
|
69
|
+
"int" => [:column, "INTEGER"],
|
70
|
+
"currency" => [:column, "DECIMAL"],
|
71
|
+
"url" => [:column, "VARCHAR"],
|
72
|
+
"id" => [:column, "VARCHAR"],
|
73
|
+
"date" => [:column, "DATE"],
|
74
|
+
"datetime" => [:column, "DATETIME"],
|
75
|
+
"reference" => [:foreign_key, "VARCHAR"],
|
76
|
+
"string" => [:column, "VARCHAR"],
|
77
|
+
"picklist" => [:column, "VARCHAR"],
|
78
|
+
"phone" => [:column, "VARCHAR"],
|
79
|
+
"boolean" => [:column, "BOOLEAN"],
|
80
|
+
"textarea" => [:column, "TEXT"],
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SalesforceExporter
|
2
|
+
class SqliteWriter
|
3
|
+
attr_reader :sf_client
|
4
|
+
attr_reader :db
|
5
|
+
attr_reader :objects
|
6
|
+
|
7
|
+
def initialize(sf_client, db, objects)
|
8
|
+
@sf_client = sf_client
|
9
|
+
@db = db
|
10
|
+
@objects = objects
|
11
|
+
end
|
12
|
+
|
13
|
+
def write
|
14
|
+
objects.each do |object|
|
15
|
+
sf_client.query(self.class.build_query(object)).each do |row|
|
16
|
+
db[object["name"].to_sym] << row.attrs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
db
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.build_query(object)
|
25
|
+
record = object["name"]
|
26
|
+
fields = object["fields"].reject{|f| f["calculated"] }.map{|f| f["name"]}.join(",")
|
27
|
+
"select #{fields} from #{record}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'salesforce_exporter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "salesforce_exporter"
|
8
|
+
spec.version = SalesforceExporter::VERSION
|
9
|
+
spec.authors = ["Leif Gensert"]
|
10
|
+
spec.email = ["leif@propertybase.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem to export salesforce data to SQLite.}
|
13
|
+
spec.description = %q{This gem lets you export selected Salesforce Objects to SQLite.}
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.homepage = "http://www.propertybase.com"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "restforce", "~> 2.1"
|
31
|
+
spec.add_dependency "sequel", "~> 4.29"
|
32
|
+
spec.add_dependency "sqlite3"
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec"
|
37
|
+
spec.add_development_dependency "dotenv"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: salesforce_exporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leif Gensert
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: restforce
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sequel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.29'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.29'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
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: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
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: This gem lets you export selected Salesforce Objects to SQLite.
|
112
|
+
email:
|
113
|
+
- leif@propertybase.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- Guardfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/salesforce_exporter.rb
|
130
|
+
- lib/salesforce_exporter/client.rb
|
131
|
+
- lib/salesforce_exporter/schema.rb
|
132
|
+
- lib/salesforce_exporter/sqlite_writer.rb
|
133
|
+
- lib/salesforce_exporter/version.rb
|
134
|
+
- salesforce_exporter.gemspec
|
135
|
+
homepage: http://www.propertybase.com
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata:
|
139
|
+
allowed_push_host: https://rubygems.org
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.5.1
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Gem to export salesforce data to SQLite.
|
160
|
+
test_files: []
|