SFDO-API 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee72501902798d88fe262d4de5a4116e2ad25c0f
4
+ data.tar.gz: 5561b32e32ed186f309f254356ed0d7664fa185b
5
+ SHA512:
6
+ metadata.gz: 49aa21b2262711aa7496cd78f1ec5f2eabee87c29ae5f11877876ed9bf104799877ffb91297dd46c502520eea9d6c2e9116d87dab7f38df732ef5b03445887b8
7
+ data.tar.gz: 5129c3ccfbe7ad2b077df709647797295159d0fb97fe2dc76994fb51675ab25bbcd8114e0f244f701537e2846253d0990118017b79e353eab277585307a63a9d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in SFDO-API.gemspec
4
+ gemspec
@@ -0,0 +1,53 @@
1
+ # SFDO::API
2
+
3
+ SFDO-API is a convenient way to manipulate valid Salesforce objects in a target environment. It accepts commands from
4
+ the calling script, and then lets the restforce Ruby gem deal directly with the Salesforce API.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'SFDO-API'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install SFDO-API
21
+
22
+ ## Usage
23
+
24
+ To create a simple Account and get the ID for that Account:
25
+ ```ruby
26
+ def create_account_via_api(client_name)
27
+ @account_id = create 'Account', Name: client_name
28
+ end
29
+ ```
30
+ You can also address the Restforce API client directly if you want, for example to issue a 'select' query:
31
+ ```ruby
32
+ def create_contact_via_api(client_name, street = '', city = '', state = '', country = '', zip = '')
33
+ @contact_id = create 'Contact', LastName: client_name,
34
+ MailingStreet: street,
35
+ MailingCity: city,
36
+ MailingState: state,
37
+ MailingCountry: country,
38
+ MailingPostalCode: zip
39
+ account_object = @api_client.query("select AccountId from Contact where Id = '#{@contact_id}'")
40
+ my_account_object = account_object.first
41
+ @account_id_for_contact = my_account_object.AccountId
42
+ end
43
+ ```
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SalesforceFoundation/SFDO-API.
53
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'SFDO/API/version'
5
+
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "SFDO-API"
9
+ spec.version = SFDO::API::VERSION
10
+ spec.authors = ["Chris McMahon", "Kevin Poorman"]
11
+ spec.email = ["cmcmahon@salesforce.com"]
12
+
13
+ spec.summary = %q{Manipulates records via the Salesforce API using Restforce}
14
+ spec.description = %q{Primarily used for automated browser tests, this is a convenient way to manipulate generic Salesforce objects}
15
+ spec.homepage = "https://github.com/SalesforceFoundation/SFDO-API"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "restforce", "~> 2.1.1"
25
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "SFDO/API"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,55 @@
1
+ require 'SFDO/API/version'
2
+
3
+ module SfdoAPI
4
+
5
+ def api_client
6
+ @api_client ||= Restforce.new api_version: '32.0',
7
+ refresh_token: ENV['SF_REFRESH_TOKEN'],
8
+ client_id: ENV['SF_CLIENT_KEY'],
9
+ client_secret: ENV['SF_CLIENT_SECRET']
10
+ yield
11
+ end
12
+
13
+ def create(type, obj_hash)
14
+ if is_valid_obj_hash?(type, obj_hash, @fields_acceptibly_nil)
15
+ obj_id = api_client do
16
+ @api_client.create! type, obj_hash
17
+ end
18
+ end
19
+ obj_id
20
+ end
21
+
22
+ def is_valid_obj_hash?(object_name, obj_hash, fields_acceptibly_nil)
23
+ required_fields = get_object_describe(object_name).map(&:fieldName)
24
+ # [name, id, required_field_1__c, etc]
25
+ valid = true
26
+ required_fields.each do |f|
27
+
28
+ valid = false if (!obj_hash.key? f.to_sym) && (begin
29
+ !fields_acceptibly_nil[object_name].contains? f
30
+ puts 'This field must be populated in order to create this object in this environment: ' + f.inspect
31
+ rescue
32
+ false
33
+ end)
34
+ end
35
+ valid
36
+ end
37
+
38
+ def get_object_describe(object_name)
39
+ api_client do
40
+ @description = @api_client.get("/services/data/v35.0/sobjects/#{object_name}/describe")
41
+
42
+ describeobject = Hashie::Mash.new(@description.body)
43
+
44
+ required = describeobject.fields.map do |x|
45
+ Hashie::Mash.new(
46
+ fieldName: x.name,
47
+ required: (!x.nillable && !x.defaultedOnCreate),
48
+ default: x.defaultValue)
49
+ end
50
+ required.select(&:required)
51
+ end
52
+ end
53
+ end
54
+ # INCLUDE HERE RATHER THAN IN THE PRODUCT-SPECIFIC CODE USING THIS GEM
55
+ include SfdoAPI
@@ -0,0 +1,5 @@
1
+ module SFDO
2
+ module API
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+
2
+ Copyright (c) 2015, 2016
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ * Neither the name of NPSP-Browser-Tests nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SFDO-API
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris McMahon
8
+ - Kevin Poorman
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: restforce
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.1.1
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 2.1.1
56
+ description: Primarily used for automated browser tests, this is a convenient way
57
+ to manipulate generic Salesforce objects
58
+ email:
59
+ - cmcmahon@salesforce.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - SFDO-API.gemspec
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/SFDO/API.rb
72
+ - lib/SFDO/API/version.rb
73
+ - lib/SFDO/LICENSE.md
74
+ homepage: https://github.com/SalesforceFoundation/SFDO-API
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Manipulates records via the Salesforce API using Restforce
97
+ test_files: []