salesforce_flo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8f1c9187f49decf64aad3602dbc666dcb779efa
4
+ data.tar.gz: 6d03df17236eda0d75991259868a9b9ddb40a895
5
+ SHA512:
6
+ metadata.gz: 1e0bae2a9bc59b73225660edb54d2256b5948eca1809c1224aa46ab5bdef40d401238b92696a8fd90fb69617d24e78273c441413700d81a6cd1ea89b1c310769
7
+ data.tar.gz: d14d35b63e01e18da55d39028ec6794e449163ae5a2a7e0b9ff8fbc165a7f8246d88dcf82ac5b9e77200224d92dd8d9e11e6947938c5f228d6e7c4d842ef1d78
data/.gitignore ADDED
@@ -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,9 @@
1
+ # Copyright © 2017, Salesforce.com, Inc.
2
+ # All Rights Reserved.
3
+ # Licensed under the BSD 3-Clause license.
4
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+
6
+ source 'https://rubygems.org'
7
+
8
+ # Specify your gem's dependencies in salesforce_flo.gemspec
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2017, Salesforce.com, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # SalesforceFlo
2
+ [![Gem Version](https://badge.fury.io/rb/salesforce_flo.svg)](https://badge.fury.io/rb/salesforce_flo) [![Code Climate](https://codeclimate.com/github/codeclimate/codeclimate/badges/gpa.svg)](https://codeclimate.com/github/codeclimate/codeclimate) [![Build Status](https://semaphoreci.com/api/v1/justinpowers/salesforce_flo/branches/master/shields_badge.svg)](https://semaphoreci.com/justinpowers/salesforce_flo)
3
+
4
+ SalesforceFlo is a Salesforce plugin for the Flo workflow automation library. If you aren't familiar with Flo, then please start [here](https://github.com/salesforce/flo)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'salesforce_flo'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install salesforce_flo
21
+
22
+ ## Configuration
23
+
24
+ In your Flo configuration file, configure salesforce inside the `config` block
25
+
26
+ ```ruby
27
+ config do |cfg|
28
+ cfg.provider :salesforce_flo, { client: Restforce.new(oauth_token: 'access_token', instance_url: 'instance url', api_version: '38.0') }
29
+ end
30
+ ```
31
+
32
+ See the [RestForce gem](https://github.com/ejholmes/restforce) for information on setting up the client.
33
+
34
+ ## Oauth Authentication Flow
35
+
36
+ The RestForce gem does not provide a mechanism for initiating the oauth authorization flow to retrieve the initial access token. If you wish to authenticate with Oauth, you can use the Oauth wrapper
37
+
38
+ ```ruby
39
+ config do |cfg|
40
+ cfg.provider :salesforce_flo, { client: SalesforceFlo::Authentication::OauthWrapper.new }
41
+ end
42
+ ```
43
+
44
+ This enables the browser Oauth authorization flow. It will open up the Salesforce authorization flow in the browser so that the user can authorize SalesforceFlo to make requests on the user's behalf. It will also open up a local webserver on port 8000, which will accept the redirect at the end of the authorization flow so that SalesforceFlo can obtain the access token.
45
+
46
+ ## Usage
47
+
48
+ Specify the commands you wish to run in the `register_command` block. For example
49
+ ```ruby
50
+ # Updates the `agf__ADM_Work__c` object, so that the `agf__Status__c` field is set to 'In Progress'
51
+ perform :salesforce_flo, :update_object, { sobject: 'agf__ADM_Work__c', name: work_id, fields: { agf__Status__c: 'In Progress' } }
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it (http://github.com/your-github-username/salesforce_flo/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
61
+
62
+
63
+ ## License
64
+
65
+ >Copyright (c) 2017, Salesforce.com, Inc.
66
+ >All rights reserved.
67
+ >
68
+ >Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
69
+ >
70
+ >* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
71
+ >
72
+ >* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
73
+ >
74
+ >* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
75
+ >
76
+ >THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # Copyright © 2017, Salesforce.com, Inc.
2
+ # All Rights Reserved.
3
+ # Licensed under the BSD 3-Clause license.
4
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+
6
+ require "bundler/gem_tasks"
7
+ require "rake/testtask"
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << "test"
11
+ t.libs << "lib"
12
+ t.test_files = FileList['test/**/*_test.rb']
13
+ end
14
+
15
+ task :default => :test
@@ -0,0 +1,52 @@
1
+ # Copyright © 2017, Salesforce.com, Inc.
2
+ # All Rights Reserved.
3
+ # Licensed under the BSD 3-Clause license.
4
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+
6
+ require 'pry'
7
+
8
+ module Flo
9
+ module Provider
10
+ class SalesforceFlo
11
+
12
+
13
+ # Creates a new SalesforceFlo Provider instance
14
+ #
15
+ # @param [Hash] opts The options needed to create the provider
16
+ # @option opts [Restforce, #call] :client An instance of a Restforce client, or
17
+ # an object that will produce a client when #call is invoked
18
+ #
19
+ def initialize(opts={})
20
+ @client = if opts[:client].respond_to? :call
21
+ opts[:client].call
22
+ else
23
+ opts[:client]
24
+ end
25
+ end
26
+
27
+ # Updates a Salesforce object using the client
28
+ #
29
+ # @param [Hash] opts The options needed to update the object
30
+ # @option opts [String] :sobject The api name of the sobject to update
31
+ # @option opts [String] :name The name of the object instance you wish to update
32
+ # @option opts [Hash] :fields A mapping of the field names and values you wish to update
33
+ #
34
+ def update_object(opts={})
35
+ sobject = opts.delete(:sobject)
36
+
37
+ object = @client.find(sobject, opts.delete(:name), 'Name')
38
+ @client.update(sobject, opts[:fields].merge(Id: object.Id))
39
+ OpenStruct.new(success?: true)
40
+ end
41
+
42
+ # Provides the current state of a Salesforce object
43
+ #
44
+ # @param sobject [String] The api name of sobject to query
45
+ # @param object_name [String] The name of the object instance to search for
46
+ def object(sobject, object_name)
47
+ @client.find(sobject, object_name, 'Name')
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,123 @@
1
+ # Copyright © 2017, Salesforce.com, Inc.
2
+ # All Rights Reserved.
3
+ # Licensed under the BSD 3-Clause license.
4
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+
6
+ require 'webrick'
7
+ require 'launchy'
8
+ require 'json'
9
+ require 'restforce'
10
+
11
+ module SalesforceFlo
12
+ module Authentication
13
+ class OauthWrapper
14
+
15
+ SFDC_URI = 'https://login.salesforce.com/services/oauth2/authorize'
16
+ DEFAULT_CLIENT_ID = '3MVG9CEn_O3jvv0zPd34OzgiH037XR5Deez3GW8PpsMdzoxecdKUW1s.8oYU9GoLS2Tykr4qTrCizaQBjRXNT'
17
+ DEFAULT_REDIRECT_HOSTNAME = 'localhost'
18
+ DEFAULT_LISTEN_PORT = '3835'
19
+
20
+ # Creates a new OauthWrapper instance
21
+ #
22
+ # @param [Hash] opts The options needed to create the provider
23
+ # @option opts [String] :client_id The client id of the connected app for Oauth authorization
24
+ # @option opts [String] :redirect_hostname (http://localhost:3835) The hostname portion of the uri
25
+ # that the user will be redirected to at the end of the Oauth authorization flow. This MUST match the
26
+ # redirect URL specified in the connected app settings.
27
+ # @option opts [String] :port (3835) The port that the user will be redirected to at the end of the Oauth
28
+ # flow. This will be appended to the redirect_hostname
29
+ # @option opts [#call] :client An object that produces a client when called with initialization options
30
+ # @raise [ArgumentError] If client object does not respond_to?(:call)
31
+ #
32
+ def initialize(opts={})
33
+ @client_id = opts[:client_id] || DEFAULT_CLIENT_ID
34
+ @redirect_hostname = opts[:redirect_hostname] || DEFAULT_REDIRECT_HOSTNAME
35
+ @port = opts[:port] || DEFAULT_LISTEN_PORT
36
+ @client = opts[:client] || -> (options) { Restforce.new(options) }
37
+ raise ArgumentError.new(':client must respond to #call, try a lambda') unless @client.respond_to?(:call)
38
+ end
39
+
40
+ # Starts a temporary webserver on the specified port, and initiates an Oauth authorization flow, which will
41
+ # redirect the user back to localhost on the specified port.
42
+ #
43
+ # @param [Hash] opts Options that will be passed to the client when called, which will be merged with the response
44
+ # from the salesforce that includes the access token
45
+ # @return The result of invoking #call on the client object
46
+ def call(opts={})
47
+ server = WEBrick::HTTPServer.new :Port => @redirect_hostname
48
+ auth_details = {}
49
+
50
+ server.mount_proc('/') do |req, res|
51
+ res.body = js_template
52
+ end
53
+
54
+ server.mount_proc('/send_token') do |req, res|
55
+ auth_details = JSON.parse(req.body)
56
+ res.body = 'token sent'
57
+
58
+ server.shutdown # server will shutdown after completing the request
59
+ end
60
+
61
+ trap "INT" do server.shutdown end
62
+
63
+ Launchy.open("#{SFDC_URI}?#{oauth_query_string}")
64
+ server.start
65
+
66
+ merged_options = opts.merge(auth_details).merge(client_id: @client_id, api_version: '38.0').inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
67
+
68
+ @client.call(merged_options)
69
+ end
70
+
71
+ private
72
+
73
+ def oauth_query_string
74
+ query_string = URI.encode_www_form([['client_id', @client_id], ['response_type', 'token'], ['redirect_uri', redirect_uri]])
75
+ end
76
+
77
+ def redirect_uri
78
+ "http://#{@redirect_hostname}:#{@port}"
79
+ end
80
+
81
+ def js_template
82
+ <<-TEMPLATE
83
+ <html>
84
+ <head></head>
85
+ <body onload="sendHashParams()">
86
+ OAuth authentication completed successfully. This window will close shortly.
87
+ <script>
88
+ function getHashParams() {
89
+
90
+ var hashParams = {};
91
+ var e,
92
+ a = /\\+/g, // Regex for replacing addition symbol with a space
93
+ r = /([^&;=]+)=?([^&;]*)/g,
94
+ d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
95
+ q = window.location.hash.substring(1);
96
+
97
+ while (e = r.exec(q))
98
+ hashParams[d(e[1])] = d(e[2]);
99
+
100
+ return hashParams;
101
+ }
102
+
103
+ function sendHashParams() {
104
+ xhr = new XMLHttpRequest();
105
+ var url = "http://localhost:8000/send_token";
106
+ xhr.open("POST", url, true);
107
+ xhr.setRequestHeader("Content-type", "application/json");
108
+ var data = JSON.stringify(getHashParams());
109
+ xhr.send(data);
110
+
111
+ setTimeout(function() {
112
+ window.close;
113
+ }, (10 * 1000))
114
+ }
115
+ </script>
116
+ </body>
117
+ </html>
118
+ TEMPLATE
119
+ end
120
+
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,8 @@
1
+ # Copyright © 2017, Salesforce.com, Inc.
2
+ # All Rights Reserved.
3
+ # Licensed under the BSD 3-Clause license.
4
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+
6
+ module SalesforceFlo
7
+ VERSION = "0.0.1"
8
+ end
@@ -0,0 +1,10 @@
1
+ # Copyright © 2017, Salesforce.com, Inc.
2
+ # All Rights Reserved.
3
+ # Licensed under the BSD 3-Clause license.
4
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+
6
+ require "salesforce_flo/version"
7
+
8
+ module SalesforceFlo
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ # Copyright © 2017, Salesforce.com, Inc.
3
+ # All Rights Reserved.
4
+ # Licensed under the BSD 3-Clause license.
5
+ # For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+
7
+ lib = File.expand_path('../lib', __FILE__)
8
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ require 'salesforce_flo/version'
10
+
11
+ Gem::Specification.new do |spec|
12
+ spec.name = "salesforce_flo"
13
+ spec.version = SalesforceFlo::VERSION
14
+ spec.authors = ['Justin Powers']
15
+ spec.email = ['justin.powers@salesforce.com']
16
+
17
+ spec.summary = %q{"Salesforce plugin for Flo"}
18
+ spec.homepage = "https://github.com/salesforce/salesforce_flo"
19
+ spec.license = "BSD-3-Clause"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "pry"
28
+
29
+ spec.add_dependency 'restforce'
30
+ spec.add_dependency 'launchy'
31
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salesforce_flo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Powers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: restforce
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - justin.powers@salesforce.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/flo/provider/salesforce_flo.rb
110
+ - lib/salesforce_flo.rb
111
+ - lib/salesforce_flo/authentication/oauth_wrapper.rb
112
+ - lib/salesforce_flo/version.rb
113
+ - salesforce_flo.gemspec
114
+ homepage: https://github.com/salesforce/salesforce_flo
115
+ licenses:
116
+ - BSD-3-Clause
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.5.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: '"Salesforce plugin for Flo"'
138
+ test_files: []