sf_connect 0.1.1 → 0.2.1
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/payload.rb +12 -0
- data/lib/sf_connect/uploader.rb +2 -2
- data/lib/sf_connect/version.rb +1 -1
- data/lib/sf_connect.rb +1 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bbd8b629514161ddfce2d6e3b7339dec55eec9f83239fa35900e455afcf8c74
|
4
|
+
data.tar.gz: 34254fdbe07ce3b7a5d57ae7147f6237293880900470ee06f78188c7ecaeb5a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91e4bc66a5470b3b0cd4fc46652f7b7d0d7f862cf74d411541de0b20b261599641472e2a37e48a26cf1c2750cbaf959506b466946a065b998dcf5ce712f677e1
|
7
|
+
data.tar.gz: 760587c3c70be8694c11e90470efef931c9730d9d2cbbe361f3455a0a640797536ab463ee78a91da9f0ca2ec8e2d4bb6452c02cef09347c9af0c99bbacf503cf
|
@@ -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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SfConnect
|
2
|
+
# payload for salesforce
|
3
|
+
class Payload
|
4
|
+
attr_reader :record, :for_upload, :for_download
|
5
|
+
|
6
|
+
def initialize(record:, for_upload: nil, for_download: nil)
|
7
|
+
@record = record
|
8
|
+
@for_upload = for_upload
|
9
|
+
@for_download = for_download
|
10
|
+
end
|
11
|
+
end
|
12
|
+
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
@@ -7,13 +7,11 @@ require "active_support/all"
|
|
7
7
|
module SfConnect
|
8
8
|
extend ActiveSupport::Autoload
|
9
9
|
autoload :Define
|
10
|
+
autoload :Payload
|
10
11
|
autoload :Fields
|
11
12
|
autoload :Uploader
|
12
13
|
autoload :Downloader
|
13
14
|
|
14
|
-
# fetch salseforce result
|
15
|
-
Result = Struct.new(:record, :binding_attributes, keyword_init: true)
|
16
|
-
|
17
15
|
class << self
|
18
16
|
def define(salesforce_object_name, where: nil, **fields, &)
|
19
17
|
SfConnect::Define.new(salesforce_object_name, where:, fields:, &).call
|
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.1
|
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
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/sf_connect/define.rb
|
57
57
|
- lib/sf_connect/downloader.rb
|
58
58
|
- lib/sf_connect/fields.rb
|
59
|
+
- lib/sf_connect/payload.rb
|
59
60
|
- lib/sf_connect/uploader.rb
|
60
61
|
- lib/sf_connect/version.rb
|
61
62
|
- sig/sf_connect.rbs
|