sf_connect 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sf_connect/downloader.rb +4 -4
- data/lib/sf_connect/fields.rb +24 -16
- data/lib/sf_connect/uploader.rb +2 -2
- data/lib/sf_connect/version.rb +1 -1
- data/lib/sf_connect.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecdf868bd822337896493a4e44464be396451b14873f93252378a170c1dca5f5
|
4
|
+
data.tar.gz: 23abb4b5437fe976c388871e0a0ba9a88451a84c9e69727cf303839e7c613e76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac5c9cc89043d242166bdea4725c0bdba29519eb20e2b16fbac111eec86eae5ae43a483e67c49a9de4c938b15d0c90f317f47163be145ad8aa5e57fe2cf1318
|
7
|
+
data.tar.gz: c5d8c8c6bdf7dbf2773145ee2b7d7c779a566c07fd0ebf2afad800edff2e9f259de8e6c745f61f7fc3bd67c301cc916ab7f744011740f274533e49b00003b8a3
|
@@ -29,15 +29,15 @@ module SfConnect
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def download_salesforce_record(salesforce_object_id)
|
32
|
-
|
33
|
-
record = find_or_initialize_from_salesforce(
|
34
|
-
record.update(
|
32
|
+
payload = fetch(salesforce_object_id)
|
33
|
+
record = find_or_initialize_from_salesforce(payload.for_download)
|
34
|
+
record.update(payload.for_download)
|
35
35
|
record
|
36
36
|
end
|
37
37
|
|
38
38
|
def download_salesforce_records(batch_size = 1000)
|
39
39
|
fetch_all.each_slice(batch_size) do |records|
|
40
|
-
upsert_all records.map(&:
|
40
|
+
upsert_all records.map(&:for_download)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/sf_connect/fields.rb
CHANGED
@@ -3,7 +3,7 @@ module SfConnect
|
|
3
3
|
# salesforce fields <=> object attributes
|
4
4
|
#
|
5
5
|
class Fields
|
6
|
-
attr_reader :salesforce_object_name
|
6
|
+
attr_reader :salesforce_object_name
|
7
7
|
|
8
8
|
def initialize(salesforce_object_name:, where:, fields:, block:)
|
9
9
|
@fields = fields
|
@@ -11,20 +11,38 @@ module SfConnect
|
|
11
11
|
@query = "select #{fields.keys.join(",")} from #{salesforce_object_name}"
|
12
12
|
@query = "#{@query} where #{where}" if where
|
13
13
|
|
14
|
-
@
|
15
|
-
@
|
14
|
+
@payload = Class.new(SfConnect::Payload)
|
15
|
+
@payload.include(Module.new(&block)) if block
|
16
16
|
end
|
17
17
|
|
18
18
|
def fetch(id, field = nil)
|
19
|
-
|
19
|
+
payload_for_download(SfConnect.find(salesforce_object_name, id, field))
|
20
20
|
end
|
21
21
|
|
22
22
|
def fetch_all(query_option)
|
23
|
-
SfConnect.query(query + query_option).each do |sobject|
|
24
|
-
yield
|
23
|
+
SfConnect.query(@query + query_option).each do |sobject|
|
24
|
+
yield payload_for_download(sobject)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def payload_for_upload_from_hash(record)
|
29
|
+
@payload.new(record:, for_upload: convert_to_salesforce_from_hash(record)).for_upload
|
30
|
+
end
|
31
|
+
|
32
|
+
def payload_for_upload(record)
|
33
|
+
@payload.new(record:, for_upload: convert_to_salesforce(record)).for_upload
|
34
|
+
end
|
35
|
+
|
36
|
+
def payload_for_download(record)
|
37
|
+
@payload.new(record:, for_download: convert_from_salesforce(record))
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def convert(&)
|
43
|
+
@fields.compact.filter_map(&).to_h
|
44
|
+
end
|
45
|
+
|
28
46
|
def convert_to_salesforce_from_hash(target)
|
29
47
|
convert do |saeslforce_field_name, object_field_name|
|
30
48
|
[
|
@@ -51,15 +69,5 @@ module SfConnect
|
|
51
69
|
]
|
52
70
|
end
|
53
71
|
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def result(record)
|
58
|
-
result_class.new(record:, binding_attributes: convert_from_salesforce(record))
|
59
|
-
end
|
60
|
-
|
61
|
-
def convert(&)
|
62
|
-
@fields.compact.filter_map(&).to_h
|
63
|
-
end
|
64
72
|
end
|
65
73
|
end
|
data/lib/sf_connect/uploader.rb
CHANGED
@@ -10,13 +10,13 @@ module SfConnect
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def upload_payload_for_salesforce
|
13
|
-
self.class.salesforce_fields.
|
13
|
+
self.class.salesforce_fields.payload_for_upload(self)
|
14
14
|
end
|
15
15
|
|
16
16
|
class_methods do
|
17
17
|
def upload_salesforce_record(**attributes)
|
18
18
|
create_salesforce_record(
|
19
|
-
salesforce_fields.
|
19
|
+
salesforce_fields.payload_for_upload_from_hash(attributes)
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
data/lib/sf_connect/version.rb
CHANGED
data/lib/sf_connect.rb
CHANGED
@@ -11,8 +11,8 @@ module SfConnect
|
|
11
11
|
autoload :Uploader
|
12
12
|
autoload :Downloader
|
13
13
|
|
14
|
-
#
|
15
|
-
|
14
|
+
# upload and download payload
|
15
|
+
Payload = Struct.new(:record, :for_upload, :for_download, keyword_init: true)
|
16
16
|
|
17
17
|
class << self
|
18
18
|
def define(salesforce_object_name, where: nil, **fields, &)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sf_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masa (Aileron inc)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: restforce
|