restforce-db 3.1.8 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/restforce/db/version.rb +1 -1
- data/lib/restforce/db.rb +23 -11
- data/lib/tasks/restforce.rake +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab0eecfbe7d96562d9b473a036e8b84b95ea1394
|
4
|
+
data.tar.gz: cb384f1779f4c48d8e654affc00e205ba5a86a8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f800c5e374fdb8b3929cd9e23e2b17d31df13d9f74181985edd502248856a1cd39104dcf6131422d19fc4d0f598dd858d71983bda9f88ec52b5aff5cccf2dc
|
7
|
+
data.tar.gz: 518570b3d2d27b7b0bf2b3a3aee7f1403eb98d6932e767aecb535f4e0a772ce8b2104674af6fa5f6105fda4ba6a90a45ef8618cdef7d1e2139bb0f9ac8b35e40
|
data/README.md
CHANGED
@@ -252,6 +252,19 @@ The task takes several arguments, most of which are optional:
|
|
252
252
|
- `end_time` (optional): The latest point in time for which records should be gathered.
|
253
253
|
- `config` (optional): The path to the file containing your Restforce::DB credentials. If not explicitly provided, the default installation file path (see above) will be used.
|
254
254
|
|
255
|
+
### Pull down missing fields
|
256
|
+
|
257
|
+
To populate existing synchronized records with data from newly-mapped fields, you can run the `populate` rake task. This will iterate through _all_ records in your database for the specified model, and populate the specified field on each record. This could potentially take a while if you have a large number of
|
258
|
+
records.
|
259
|
+
|
260
|
+
$ bundle exec rake restforce:populate[<model>,<salesforce_model>,<field>]
|
261
|
+
|
262
|
+
This task takes a handful of required arguments:
|
263
|
+
|
264
|
+
- `model`: The name of the ActiveRecord model you wish to sync. This can be any model you've defined a mapping for in your application.
|
265
|
+
- `salesforce_model`: The name of the specfic Salesforce model to which the desired field is mapped. This object type will be used as the data source.
|
266
|
+
- `field`: The name of the attribute to populate on your ActiveRecord model. Will usually correspond to a database column name.
|
267
|
+
|
255
268
|
### Run the daemon
|
256
269
|
|
257
270
|
To actually perform this system synchronization, you'll want to run the binstub installed through the generator (see above). This will daemonize a process which loops repeatedly to continuously synchronize your database and your Salesforce account, according to the established mappings.
|
data/lib/restforce/db/version.rb
CHANGED
data/lib/restforce/db.rb
CHANGED
@@ -84,17 +84,29 @@ module Restforce
|
|
84
84
|
#
|
85
85
|
# Returns a Restforce::Data::Client instance.
|
86
86
|
def self.client
|
87
|
-
@client ||=
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
87
|
+
@client ||= begin
|
88
|
+
client = DB::Client.new(
|
89
|
+
username: configuration.username,
|
90
|
+
password: configuration.password,
|
91
|
+
security_token: configuration.security_token,
|
92
|
+
client_id: configuration.client_id,
|
93
|
+
client_secret: configuration.client_secret,
|
94
|
+
host: configuration.host,
|
95
|
+
api_version: configuration.api_version,
|
96
|
+
timeout: configuration.timeout,
|
97
|
+
adapter: configuration.adapter,
|
98
|
+
)
|
99
|
+
|
100
|
+
# NOTE: By default, the Retry middleware will catch timeout exceptions,
|
101
|
+
# and retry up to two times. For more information, see:
|
102
|
+
# https://github.com/lostisland/faraday/blob/master/lib/faraday/request/retry.rb
|
103
|
+
client.middleware.request(
|
104
|
+
:retry,
|
105
|
+
methods: [:get, :head, :options, :put, :patch, :delete],
|
106
|
+
)
|
107
|
+
|
108
|
+
client
|
109
|
+
end
|
98
110
|
end
|
99
111
|
|
100
112
|
# Public: Get the ID of the Salesforce user which is being used to access
|
data/lib/tasks/restforce.rake
CHANGED
@@ -18,6 +18,33 @@ namespace :restforce do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
desc "Pull down the requested Salesforce data for the specified model"
|
22
|
+
task :populate, [:model, :salesforce_model, :field] => :environment do |_, args|
|
23
|
+
raise ArgumentError, "An ActiveRecord model name must be supplied" unless args[:model]
|
24
|
+
raise ArgumentError, "A Salesforce model name must be supplied" unless args[:salesforce_model]
|
25
|
+
raise ArgumentError, "An attribute name must be supplied" unless args[:field]
|
26
|
+
|
27
|
+
Rails.application.eager_load!
|
28
|
+
|
29
|
+
model = args[:model].constantize
|
30
|
+
field = args[:field].to_sym
|
31
|
+
|
32
|
+
mapping = Restforce::DB::Registry[model].detect do |m|
|
33
|
+
m.salesforce_model == args[:salesforce_model]
|
34
|
+
end
|
35
|
+
|
36
|
+
raise ArgumentError, "No Mapping was found between #{args[:model]} and #{args[:salesforce_model]}" unless mapping
|
37
|
+
|
38
|
+
model.where.not(mapping.lookup_column => nil).find_each do |record|
|
39
|
+
salesforce_id = record.send(mapping.lookup_column)
|
40
|
+
salesforce_instance = mapping.salesforce_record_type.find(salesforce_id)
|
41
|
+
next unless salesforce_instance
|
42
|
+
|
43
|
+
attributes = mapping.convert(model, salesforce_instance.attributes)
|
44
|
+
record.update_columns field => attributes[field]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
21
48
|
desc "Get the 18-character version of a 15-character Salesforce ID"
|
22
49
|
task :convertid, [:salesforce_id] do |_, args|
|
23
50
|
sfid = args[:salesforce_id]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|