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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ecbcbb39d5d19bc52e64d354e3b39422af68cb8040e3bb1a9b5823542109753
4
- data.tar.gz: 81e4fc211891bfe2908d077f6263939a220774843a2547ba9e1beba0690a2a53
3
+ metadata.gz: ecdf868bd822337896493a4e44464be396451b14873f93252378a170c1dca5f5
4
+ data.tar.gz: 23abb4b5437fe976c388871e0a0ba9a88451a84c9e69727cf303839e7c613e76
5
5
  SHA512:
6
- metadata.gz: 2d35cdf68b3ffc6f3364e1090b62ed2602e281ead52bf87aef0f322f164b1ad35ebaff28e138055184db5528fb6bd2440d3df78599688e73202a80efa0891edf
7
- data.tar.gz: 8fa8a2f9619a323b6aa162fe594c66d23348ed25bcffc022d13b68eae47c92cc0158e45caa5ea2b2e0dce9d5f15d697bf3aea2d43b42ede45b3db8479c9001a7
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
- result = fetch(salesforce_object_id)
33
- record = find_or_initialize_from_salesforce(result.binding_attributes)
34
- record.update(result.binding_attributes)
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(&:binding_attributes)
40
+ upsert_all records.map(&:for_download)
41
41
  end
42
42
  end
43
43
  end
@@ -3,7 +3,7 @@ module SfConnect
3
3
  # salesforce fields <=> object attributes
4
4
  #
5
5
  class Fields
6
- attr_reader :salesforce_object_name, :query, :fields, :result_class
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
- @result_class = Class.new(SfConnect::Result)
15
- @result_class.include(Module.new(&block)) if block
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
- result(SfConnect.find(salesforce_object_name, id, field))
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 result(sobject)
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
@@ -10,13 +10,13 @@ module SfConnect
10
10
  end
11
11
 
12
12
  def upload_payload_for_salesforce
13
- self.class.salesforce_fields.convert_to_salesforce(self)
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.convert_to_salesforce_from_hash(attributes)
19
+ salesforce_fields.payload_for_upload_from_hash(attributes)
20
20
  )
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  module SfConnect
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
data/lib/sf_connect.rb CHANGED
@@ -11,8 +11,8 @@ module SfConnect
11
11
  autoload :Uploader
12
12
  autoload :Downloader
13
13
 
14
- # fetch salseforce result
15
- Result = Struct.new(:record, :binding_attributes, keyword_init: true)
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.1.1
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-23 00:00:00.000000000 Z
11
+ date: 2023-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restforce