sf_cli 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/README.rdoc +30 -8
  4. data/lib/sf_cli/sf/core/base.rb +80 -0
  5. data/lib/sf_cli/sf/data/bulk_result_v2.rb +77 -0
  6. data/lib/sf_cli/sf/data/core.rb +39 -0
  7. data/lib/sf_cli/sf/data/create_record.rb +30 -0
  8. data/lib/sf_cli/sf/data/delete_bulk.rb +47 -0
  9. data/lib/sf_cli/sf/data/delete_record.rb +33 -0
  10. data/lib/sf_cli/sf/data/delete_resume.rb +47 -0
  11. data/lib/sf_cli/sf/data/get_record.rb +42 -0
  12. data/lib/sf_cli/sf/data/helper_methods.rb +47 -0
  13. data/lib/sf_cli/sf/data/query.rb +120 -0
  14. data/lib/sf_cli/sf/data/query_helper.rb +57 -0
  15. data/lib/sf_cli/sf/data/resume.rb +87 -0
  16. data/lib/sf_cli/sf/data/search.rb +50 -0
  17. data/lib/sf_cli/sf/data/update_record.rb +38 -0
  18. data/lib/sf_cli/sf/data/upsert_bulk.rb +50 -0
  19. data/lib/sf_cli/sf/data/upsert_resume.rb +47 -0
  20. data/lib/sf_cli/sf/main.rb +31 -0
  21. data/lib/sf_cli/sf/model/class_definition.rb +112 -0
  22. data/lib/sf_cli/sf/model/generator.rb +27 -0
  23. data/lib/sf_cli/sf/model/schema.rb +33 -0
  24. data/lib/sf_cli/sf/model.rb +21 -0
  25. data/lib/sf_cli/sf/org/core.rb +23 -0
  26. data/lib/sf_cli/sf/org/display.rb +41 -0
  27. data/lib/sf_cli/sf/org/list.rb +67 -0
  28. data/lib/sf_cli/sf/org/login.rb +64 -0
  29. data/lib/sf_cli/sf/project/core.rb +83 -0
  30. data/lib/sf_cli/sf/sobject/core.rb +50 -0
  31. data/lib/sf_cli.rb +19 -1
  32. metadata +38 -15
  33. data/lib/sf_cli/sf/base.rb +0 -34
  34. data/lib/sf_cli/sf/data.rb +0 -148
  35. data/lib/sf_cli/sf/org.rb +0 -49
  36. data/lib/sf_cli/sf/project.rb +0 -68
  37. data/lib/sf_cli/sf/sobject.rb +0 -41
  38. data/lib/sf_cli/sf.rb +0 -87
@@ -0,0 +1,23 @@
1
+ require_relative '../core/base'
2
+ require_relative './login'
3
+ require_relative './display'
4
+ require_relative './list'
5
+
6
+ module SfCli
7
+ module Sf
8
+ module Org
9
+ #
10
+ # ==== description
11
+ # The class representing *sf* *org*.
12
+ #
13
+ # https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm
14
+ #
15
+ class Core
16
+ include ::SfCli::Sf::Core::Base
17
+ include Login
18
+ include Display
19
+ include List
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ module SfCli::Sf::Org
2
+ module Display
3
+ ConnectionInfo = Struct.new(:id, :access_token, :alias, :instance_url, :user_name, :api_version, :status)
4
+
5
+ #
6
+ # returns the org's connection information. (equivalent to *sf* *org* *display*)
7
+ #
8
+ # *target_org* --- an alias of paticular org, or username can be used<br>
9
+ #
10
+ # ======
11
+ # # example (in irb):
12
+ #
13
+ # > sf.org.display
14
+ # =>
15
+ # #<struct SfCli::Sf::Org::Display::ConnectionInfo
16
+ # id="00D5j00000DiuxmEAB",
17
+ # access_token="<some access token>",
18
+ # alias="dev",
19
+ # instance_url="https://hoge-bar-baz.abc.my.salesforce.com.example",
20
+ # user_name="user@example.sandbox",
21
+ # api_version="61.0",
22
+ # status="Connected">
23
+ #
24
+ # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_display_unified]
25
+ #
26
+ def display(target_org: nil)
27
+ flags = {:"target-org" => target_org}
28
+ json = exec(__method__, flags: flags, redirection: :null_stderr)
29
+
30
+ ConnectionInfo.new(
31
+ id: json['result']['id'],
32
+ access_token: json['result']['accessToken'],
33
+ alias: json['result']['alias'],
34
+ instance_url: json['result']['instanceUrl'],
35
+ user_name: json['result']['username'],
36
+ api_version: json['result']['apiVersion'],
37
+ status: json['result']['connectedStatus']
38
+ )
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,67 @@
1
+ module SfCli::Sf::Org
2
+ module List
3
+ OrgConfig = Struct.new( :accessToken, :instanceUrl, :orgId, :username, :loginUrl,
4
+ :clientId, :isDevHub, :instanceApiVersion, :instanceApiVersionLastRetrieved, :name,
5
+ :instanceName, :namespacePrefix, :isSandbox, :isScratch, :trailExpirationDate, :tracksSource,
6
+ :alias, :isDefaultDevHubUsername, :isDefaultUsername, :lastUsed, :connectedStatus) do
7
+ def devhub?
8
+ isDevHub
9
+ end
10
+
11
+ def sandbox?
12
+ isSandbox
13
+ end
14
+
15
+ def scratch?
16
+ isScratch
17
+ end
18
+
19
+ def default?
20
+ isDefaultUsername
21
+ end
22
+
23
+ def default_devhub?
24
+ isDefaultDevHubUsername
25
+ end
26
+
27
+ def connected?
28
+ connectedStatus == 'Connected'
29
+ end
30
+ end
31
+
32
+ # \List orgs you’ve created or authenticated to
33
+ #
34
+ # ======
35
+ # org_config_list = sf.org.list # returns a list of OrgConfig
36
+ #
37
+ # \OrgConfig object has a org information including security sensitive things such as access token, username and so on.
38
+ #
39
+ # It also has some methods to identify its org type:
40
+ # - devhub?
41
+ # - sandbox?
42
+ # - scratch?
43
+ # - default?
44
+ # - default_devhub?
45
+ #
46
+ # and you can check the org connected like this:
47
+ # org_config_list = sf.org.list # returns a list of OrgConfig
48
+ # org_config.first.conncected?
49
+ #
50
+ # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_list_unified]
51
+ #
52
+ def list
53
+ flags = {
54
+ # reserved for later option addition
55
+ }
56
+ json = exec(__method__, flags: flags, redirection: :null_stderr)
57
+
58
+ others = json['result']['other'].map{|config| OrgConfig.new(**config)}
59
+ sandboxes = json['result']['sandboxes'].map{|config| OrgConfig.new(**config)}
60
+ non_scratch_orgs = json['result']['nonScratchOrgs'].map{|config| OrgConfig.new(**config)}
61
+ devhubs = json['result']['devHubs'].map{|config| OrgConfig.new(**config)}
62
+ scratch_orgs = json['result']['scratchOrgs'].map{|config| OrgConfig.new(**config)}
63
+
64
+ (others + sandboxes + non_scratch_orgs + devhubs + scratch_orgs).uniq{|config| config.alias}
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,64 @@
1
+ module SfCli::Sf::Org
2
+ module Login
3
+ # login to the org by the browser.
4
+ #
5
+ # *target_org* --- an alias of paticular org, or username can be used<br>
6
+ #
7
+ # *instance_url* --- URL of the instance that the org lives on.
8
+ #
9
+ # *browser* --- browser in which to open the org.
10
+ #
11
+ # == examples:
12
+ # sf.org.login_web
13
+ # sf.org.login_web target_org: :dev
14
+ #
15
+ # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_login_web_unified]
16
+ #
17
+ def login_web(target_org: nil, instance_url: nil, browser: nil)
18
+ flags = {
19
+ :"alias" => target_org,
20
+ :"instance-url" => instance_url,
21
+ :"browser" => browser,
22
+ }
23
+ action = __method__.to_s.tr('_', ' ')
24
+ exec(action, flags: flags)
25
+ end
26
+
27
+ # login to the org by access token.
28
+ #
29
+ # NOTE: this method doesn't support user interactive mode, so *SF_ACCESS_TOKEN* environment variable must be set before call this method.
30
+ #
31
+ # *instance_url* --- URL of the instance that the org lives on.
32
+ #
33
+ # *target_org* --- an alias of paticular org, or username can be used<br>
34
+ #
35
+ # ======
36
+ # ENV['SF_ACCESS_TOKEN'] = 'xxxxxxxxxx'
37
+ # sf.org.login_access_token instance_url: https://hoge.bar.baz.salesforce.com
38
+ #
39
+ # == how to set env variable outside of ruby
40
+ # In Unix/mac:
41
+ # $ SF_ACCESS_TOKEN='xxxxxxxxxx'
42
+ # $ ruby app_using_sfcli.rb
43
+ # or
44
+ # $ SF_ACCESS_TOKEN='xxxxxxxxxx' ruby app_using_sfcli.rb
45
+ #
46
+ # In Windows:
47
+ # $ set SF_ACCESS_TOKEN=xxxxxxxxxx
48
+ # $ ruby app_using_sfcli.rb
49
+ #
50
+ # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_login_access-token_unified]
51
+ #
52
+ def login_access_token(instance_url:, target_org: nil)
53
+ flags = {
54
+ :"instance-url" => instance_url,
55
+ :"alias" => target_org,
56
+ }
57
+ switches = {
58
+ :"no-prompt" => true,
59
+ }
60
+ action = __method__.to_s.tr('_', '-').sub('-', ' ')
61
+ exec action, flags: flags, switches: switches, redirection: :null_stderr
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,83 @@
1
+ require_relative '../core/base'
2
+
3
+ module SfCli
4
+ module Sf
5
+ module Project
6
+ # ==== description
7
+ # The class representing *sf* *project*
8
+ #
9
+ # command reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm
10
+ #
11
+ class Core
12
+ include ::SfCli::Sf::Core::Base
13
+
14
+ GenerateResult = Struct.new(:output_dir, :files, :raw_output, :warnings)
15
+
16
+ #
17
+ # generate a Salesforce project
18
+ #
19
+ # *name* --- project name<br>
20
+ #
21
+ # *template* --- project template name<br>
22
+ #
23
+ # *output_dir* --- output directory<br>
24
+ #
25
+ # *manifest* --- switch to create manifest file in the project directory (manifest/package.xml). default: false
26
+ #
27
+ # For more command details, see the {reference document}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm#cli_reference_project_generate_unified]
28
+ #
29
+ def generate(name, manifest: false, template: nil, output_dir: nil)
30
+ flags = {
31
+ :name => name,
32
+ :template => template,
33
+ :"output-dir" => output_dir,
34
+ }
35
+ switches = {
36
+ manifest: manifest,
37
+ }
38
+ json = exec(__method__, flags: flags, switches: switches, redirection: :null_stderr)
39
+
40
+ GenerateResult.new(
41
+ output_dir: json['result']['outputDir'],
42
+ files: json['result']['created'],
43
+ raw_output: json['result']['rawOutput'],
44
+ warnings: json['warnings']
45
+ )
46
+ end
47
+
48
+ # generate the manifest file of a Salesforce project
49
+ #
50
+ # *metadata* --- an array that consists of metadata type like CustomObject, Layout and so on. (default: [])<br>
51
+ #
52
+ # *api_verson* --- api version (default: nil)<br>
53
+ #
54
+ # *output_dir* --- manifest's output directory in the project directory. You can use relative path from the project root (default: nil)<br>
55
+ #
56
+ # *from_org* --- username or alias of the org that contains the metadata components from which to build a manifest (default: nil)<br>
57
+ #
58
+ # *source_dir* --- paths to the local source files to include in the manifest (default: nil)
59
+ #
60
+ # ======
61
+ # sf.project.generate_manifest metadata: %w[CustomObject Layout] # creates a package.xml, which is initialized with CustomObject and Layout
62
+ # sf.project.generate_manifest from_org: <org_name> # creates a package.xml, which is initialized with all metadata types in the org
63
+ #
64
+ # For more command details, see the {reference document}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm#cli_reference_project_generate_manifest_unified]
65
+ #
66
+ def generate_manifest(name: nil, output_dir: nil, api_version: nil, metadata: [], from_org: nil, source_dir: nil)
67
+ flags = {
68
+ :name => name,
69
+ :"metadata" => (metadata.empty? ? nil : metadata.join(' ')),
70
+ :"from-org" => from_org,
71
+ :"source-dir" => source_dir,
72
+ :"output-dir" => output_dir,
73
+ :"api-version" => api_version,
74
+ }
75
+ action = __method__.to_s.tr('_', ' ')
76
+ json = exec(action, flags: flags, redirection: :null_stderr)
77
+
78
+ json['result']['path']
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,50 @@
1
+ require_relative '../core/base'
2
+
3
+ module SfCli
4
+ module Sf
5
+ module Sobject
6
+ # ==== description
7
+ # The class representing *sf* *sobject*
8
+ #
9
+ # command reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm
10
+ #
11
+ class Core
12
+ include ::SfCli::Sf::Core::Base
13
+
14
+ # returns a hash object containing the Salesforce object schema
15
+ #
16
+ # *objectType* --- object type (ex: Account)<br>
17
+ #
18
+ # *target_org* --- an alias of paticular org, or username can be used<br>
19
+ #
20
+ # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_describe_unified]
21
+ #
22
+ def describe(object_type, target_org: nil)
23
+ flags = {
24
+ :"sobject" => object_type,
25
+ :"target-org" => target_org,
26
+ }
27
+ json = exec(__method__, flags: flags, redirection: :null_stderr)
28
+ json['result']
29
+ end
30
+
31
+ # returns a list of Salesforce object name
32
+ #
33
+ # *object_type* --- all or custom<br>
34
+ #
35
+ # *target_org* --- an alias of paticular org, or username can be used<br>
36
+ #
37
+ # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_list_unified]
38
+ #
39
+ def list(object_type, target_org: nil)
40
+ flags = {
41
+ :"sobject" => (object_type.to_sym == :custom ? :custom : :all),
42
+ :"target-org" => target_org,
43
+ }
44
+ json = exec(__method__, flags: flags, redirection: :null_stderr)
45
+ json['result']
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/sf_cli.rb CHANGED
@@ -1 +1,19 @@
1
- require 'sf_cli/sf'
1
+ require 'sf_cli/sf/main'
2
+ #
3
+ # the global method that represents *sf* command.
4
+ #
5
+ # With method chaining, you can use similar syntax as original command.
6
+ #
7
+ # == examples
8
+ #
9
+ # ======
10
+ # sf.org.display # => returns the org information object
11
+ #
12
+ # ======
13
+ # sf.data.query "SELECT Name FROM Account" # => [{"Name"=>"Aethna Home Products"}]
14
+ #
15
+ # For details of sf command, see the {reference guide}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_unified.htm]
16
+ #
17
+ def sf
18
+ SfCli::Sf::Main.instance
19
+ end
metadata CHANGED
@@ -1,37 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sf_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takanobu Maekawa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-25 00:00:00.000000000 Z
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: This is a class library for introducing Salesforce CLI.Currenty only
14
- sf command is the target of development.
15
- email:
13
+ description: This is a class library for introducing Salesforce CLI to Ruby scripting.
14
+ Currenty only sf command is the target of development.
15
+ email:
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files:
19
19
  - README.rdoc
20
+ - CHANGELOG.md
20
21
  files:
22
+ - CHANGELOG.md
21
23
  - README.rdoc
22
24
  - lib/sf_cli.rb
23
- - lib/sf_cli/sf.rb
24
- - lib/sf_cli/sf/base.rb
25
- - lib/sf_cli/sf/data.rb
26
- - lib/sf_cli/sf/org.rb
27
- - lib/sf_cli/sf/project.rb
28
- - lib/sf_cli/sf/sobject.rb
25
+ - lib/sf_cli/sf/core/base.rb
26
+ - lib/sf_cli/sf/data/bulk_result_v2.rb
27
+ - lib/sf_cli/sf/data/core.rb
28
+ - lib/sf_cli/sf/data/create_record.rb
29
+ - lib/sf_cli/sf/data/delete_bulk.rb
30
+ - lib/sf_cli/sf/data/delete_record.rb
31
+ - lib/sf_cli/sf/data/delete_resume.rb
32
+ - lib/sf_cli/sf/data/get_record.rb
33
+ - lib/sf_cli/sf/data/helper_methods.rb
34
+ - lib/sf_cli/sf/data/query.rb
35
+ - lib/sf_cli/sf/data/query_helper.rb
36
+ - lib/sf_cli/sf/data/resume.rb
37
+ - lib/sf_cli/sf/data/search.rb
38
+ - lib/sf_cli/sf/data/update_record.rb
39
+ - lib/sf_cli/sf/data/upsert_bulk.rb
40
+ - lib/sf_cli/sf/data/upsert_resume.rb
41
+ - lib/sf_cli/sf/main.rb
42
+ - lib/sf_cli/sf/model.rb
43
+ - lib/sf_cli/sf/model/class_definition.rb
44
+ - lib/sf_cli/sf/model/generator.rb
45
+ - lib/sf_cli/sf/model/schema.rb
46
+ - lib/sf_cli/sf/org/core.rb
47
+ - lib/sf_cli/sf/org/display.rb
48
+ - lib/sf_cli/sf/org/list.rb
49
+ - lib/sf_cli/sf/org/login.rb
50
+ - lib/sf_cli/sf/project/core.rb
51
+ - lib/sf_cli/sf/sobject/core.rb
29
52
  homepage: https://github.com/tmkw/sf_cli
30
53
  licenses:
31
54
  - MIT
32
55
  metadata:
33
56
  homepage_url: https://github.com/tmkw/sf_cli
34
- post_install_message:
57
+ post_install_message:
35
58
  rdoc_options: []
36
59
  require_paths:
37
60
  - lib
@@ -46,9 +69,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
69
  - !ruby/object:Gem::Version
47
70
  version: '0'
48
71
  requirements:
49
- - 'Salesforce CLI ( >= 2.54.0): https://developer.salesforce.com/tools/salesforcecli'
72
+ - 'Salesforce CLI ( >= 2.56.7): https://developer.salesforce.com/tools/salesforcecli'
50
73
  rubygems_version: 3.5.11
51
- signing_key:
74
+ signing_key:
52
75
  specification_version: 4
53
76
  summary: A library for using Salesforce CLI in Ruby
54
77
  test_files: []
@@ -1,34 +0,0 @@
1
- module SfCli
2
- class Sf
3
- class Base
4
- def initialize(_sf)
5
- @sf = _sf
6
- end
7
-
8
- private
9
-
10
- def exec(action, flags: {}, switches: {}, redirection: nil)
11
- sf.exec(category, action, flags: flags, switches: switches, redirection: redirection)
12
- end
13
-
14
- def category
15
- self.class.name.split('::').last.downcase
16
- end
17
-
18
- def field_value_pairs(hash)
19
- return nil if hash.nil?
20
- return nil if hash.empty?
21
-
22
- hash.each_with_object([]) do|(k,v), arr|
23
- value = v.instance_of?(String) ? %|'#{v}'| : v
24
- arr << %(#{k}=#{value})
25
- end
26
- .join(' ')
27
- end
28
-
29
- def sf
30
- @sf
31
- end
32
- end
33
- end
34
- end
@@ -1,148 +0,0 @@
1
- require_relative './base'
2
-
3
- module SfCli
4
- class Sf
5
- #
6
- # ==== description
7
- # The class representing *sf* *data*
8
- #
9
- # https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm
10
- #
11
- class Data < Base
12
-
13
- # get object records using SQOL. (eqivalent to *sf* *data* *query*)
14
- #
15
- # *soql* --- SOQL<br>
16
- # *target_org* --- an alias of paticular org, not default one<br>
17
- # *model_class* --- the data model class representing the record object.<br>
18
- #
19
- # ==== examples
20
- # sf.data.query('SELECT Id, Name From Account Limit 3') # returns an array of Hash object
21
- #
22
- # Account = Struct.new(:Id, :Name)
23
- # sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
24
- #
25
- def query(soql, target_org: nil, model_class: nil)
26
- flags = {
27
- :"query" => %("#{soql}"),
28
- :"target-org" => target_org,
29
- }
30
- json = exec(__method__, flags: flags, redirection: :null_stderr)
31
-
32
- json['result']['records'].each_with_object([]) do |h, a|
33
- h.delete "attributes"
34
- a << (model_class ? model_class.new(**h) : h)
35
- end
36
- end
37
-
38
- # get a object record. (eqivalent to *sf* *data* *get* *record*)
39
- #
40
- # *object_type* --- Object Type (ex. Account)<br>
41
- # *record_id* --- id of the object<br>
42
- # *where* --- hash object that is used to identify a record<br>
43
- # *target_org* --- an alias of paticular org, not default one<br>
44
- # *model_class* --- the data model class representing the record object.<br>
45
- #
46
- # ==== examples
47
- # sf.data.get_record :Account, record_id: 'xxxxxxx'
48
- # sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
49
- #
50
- # CustomObject = Struct.new(:Id, :Name)
51
- # sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject # returns a CustomObject struct object
52
- #
53
- def get_record(object_type, record_id: nil, where: nil, target_org: nil, model_class: nil)
54
- where_conditions = field_value_pairs(where)
55
- flags = {
56
- :"sobject" => object_type,
57
- :"record-id" => record_id,
58
- :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
59
- :"target-org" => target_org,
60
- }
61
- action = __method__.to_s.tr('_', ' ')
62
- json = exec(action, flags: flags, redirection: :null_stderr)
63
-
64
- result = json['result']
65
- result.delete 'attributes'
66
-
67
- model_class ? model_class.new(**result) : result
68
- end
69
-
70
- # update a object record. (eqivalent to *sf* *data* *update* *record*)
71
- #
72
- # *object_type* --- Object Type (ex. Account)<br>
73
- # *record_id* --- id of the object<br>
74
- # *where* --- field values that is used to identify a record<br>
75
- # *values* --- field values for update<br>
76
- # *target_org* --- an alias of paticular org, not default one<br>
77
- #
78
- # ==== examples
79
- # sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
80
- # sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
81
- #
82
- def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil)
83
- where_conditions = field_value_pairs(where)
84
- field_values = field_value_pairs(values)
85
- flags = {
86
- :"sobject" => object_type,
87
- :"record-id" => record_id,
88
- :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
89
- :"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
90
- :"target-org" => target_org,
91
- }
92
- action = __method__.to_s.tr('_', ' ')
93
- json = exec(action, flags: flags, redirection: :null_stderr)
94
-
95
- json['result']['id']
96
- end
97
-
98
- # create a object record. (eqivalent to *sf* *data* *create* *record*)
99
- #
100
- # *object_type* --- Object Type (ex. Account)<br>
101
- # *values* --- field values to be assigned<br>
102
- # *target_org* --- an alias of paticular org, not default one<br>
103
- #
104
- # ==== examples
105
- #
106
- # sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33} # creating a TheCustomObject record with name and age
107
- #
108
- def create_record(object_type, values: {}, target_org: nil)
109
- field_values = field_value_pairs(values)
110
- flags = {
111
- :"sobject" => object_type,
112
- :"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
113
- :"target-org" => target_org,
114
- }
115
- action = __method__.to_s.tr('_', ' ')
116
- json = exec(action, flags: flags, redirection: :null_stderr)
117
-
118
- json['result']['id']
119
- end
120
-
121
- # delete a object record. (eqivalent to *sf* *data* *delete* *record*)
122
- #
123
- # *object_type* --- Object Type (ex. Account)<br>
124
- # *record_id* --- id of the object<br>
125
- # *where* --- hash object that is used to identify a record<br>
126
- # *target_org* --- an alias of paticular org, not default one<br>
127
- #
128
- # ==== examples
129
- # sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
130
- # sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
131
- #
132
- #
133
- def delete_record(object_type, record_id: nil, where: nil, target_org: nil)
134
- where_conditions = field_value_pairs(where)
135
- flags = {
136
- :"sobject" => object_type,
137
- :"record-id" => record_id,
138
- :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
139
- :"target-org" => target_org,
140
- }
141
- action = __method__.to_s.tr('_', ' ')
142
- json = exec(action, flags: flags, redirection: :null_stderr)
143
-
144
- json['result']['id']
145
- end
146
- end
147
- end
148
- end
data/lib/sf_cli/sf/org.rb DELETED
@@ -1,49 +0,0 @@
1
- require_relative './base'
2
-
3
- module SfCli
4
- class Sf
5
- #
6
- # ==== description
7
- # The class representing *sf* *org*.
8
- #
9
- # https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm
10
- #
11
- class Org < Base
12
- ConnectionInfo = Struct.new(:id, :access_token, :alias, :instance_url, :user_name, :api_version, :status)
13
-
14
- # login to the org by the browser. (equivalent to *sf* *org* *login* *web*)
15
- #
16
- # *target_org* --- an alias of paticular org, not default one<br>
17
- # *instance_url* --- custom login url.
18
- #
19
- def login_web(target_org: nil, instance_url: nil)
20
- flags = {
21
- :"alias" => target_org,
22
- :"instance-url" => instance_url,
23
- }
24
- action = __method__.to_s.tr('_', ' ')
25
- exec(action, flags: flags)
26
- end
27
-
28
- #
29
- # returns the org's connection information. (equivalent to *sf* *org* *display*)
30
- #
31
- # *target_org* --- an alias of paticular org, not default one<br>
32
- #
33
- def display(target_org: nil)
34
- flags = {:"target-org" => target_org}
35
- json = exec(__method__, flags: flags, redirection: :null_stderr)
36
-
37
- ConnectionInfo.new(
38
- id: json['result']['id'],
39
- access_token: json['result']['accessToken'],
40
- alias: json['result']['alias'],
41
- instance_url: json['result']['instanceUrl'],
42
- user_name: json['result']['username'],
43
- api_version: json['result']['apiVersion'],
44
- status: json['result']['connectedStatus']
45
- )
46
- end
47
- end
48
- end
49
- end