salesforce_client_app 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: 13fa871a5236b7b39d1a8ed6601bb02d8d8ac024
4
+ data.tar.gz: 85a37896bb5403296e44bc31e8402736e7434013
5
+ SHA512:
6
+ metadata.gz: 53f26b4a07afd59a694b06f4bb159b3687dcb3a168b987eb11a2cc5a536b470c1129cca18b28214f6af086a511223249ac1a9ff2f2ace55f1c342c380218e137
7
+ data.tar.gz: 7d6e1b9a3a210d1aa23cc4af0676403cf6f25a90e39991e728e402ccc15098b96c75ea666797de18e9f30437d10efa462a23bcce809511688bc99b1a7690577d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in salesforce_client_app.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 KAWANO Shinobu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # SalesforceClientApp
2
+
3
+ A simple Sinatra app which is integrated with Force.com and some of its API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'salesforce_client_app'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install salesforce_client_app
18
+
19
+ ## Usage
20
+
21
+ Create an app directory, then make Gemfile.
22
+
23
+ mkdir myapp && cd myapp && touch Gemfile
24
+
25
+ Edit Gemfile as followings.
26
+
27
+ # A sample Gemfile
28
+ source "https://rubygems.org"
29
+
30
+ gem 'salesforce_client_app'
31
+
32
+ then `Bundle install`.
33
+
34
+ Or you can use `init` command of `twitter_client_app`.
35
+
36
+ $ salesforce_client_app init PROJECT_NAME
37
+
38
+ If you want to use CLI, you should install 'salesforce_client_app' gem directory.
39
+
40
+ Also make public directory, and put the index.html file. After that, please make app.rb and edit it as following.
41
+
42
+ require 'salesforce_client_app'
43
+
44
+ SalesforceClientApp::App.setRoot(File.expand_path(File.dirname(__FILE__)))
45
+ SalesforceClientApp::App.run!
46
+
47
+ and then, create `.env` file and describe following configs.
48
+
49
+ SALESFORCE_KEY=<insert key here>
50
+ SALESFORCE_SECRET=<insert secret here>
51
+ SECRET=some_random_text_string
52
+
53
+ That's all! After you have to do is use it. :)
54
+
55
+ $ foreman start
56
+
57
+ 13:12:47 web.1 | started with pid 2743
58
+ 13:12:48 web.1 | [2014-06-12 13:12:48] INFO WEBrick 1.3.1
59
+ ...
60
+ 13:12:48 web.1 | [2014-06-12 13:12:48] INFO WEBrick::HTTPServer#start: pid=2743 port=5000
61
+
62
+ For more information, please see the files of `example` directory.
63
+
64
+ ![alt tag](https://raw.githubusercontent.com/kawanoshinobu/salesforce_client_app/master/images/1.png)
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/[my-github-username]/salesforce_client_app/fork )
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'salesforce_client_app'
3
+
4
+ SalesforceClientApp::CLI.start
data/example/.env ADDED
@@ -0,0 +1,3 @@
1
+ SALESFORCE_KEY=<insert key here>
2
+ SALESFORCE_SECRET=<insert secret here>
3
+ SECRET=some_random_text_string
data/example/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec ruby app.rb -p $PORT
data/example/app.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'salesforce_client_app'
2
+
3
+ SalesforceClientApp::App.setRoot(File.expand_path(File.dirname(__FILE__)))
4
+ SalesforceClientApp::App.run!
@@ -0,0 +1,87 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Salesforce Client App</title>
5
+ <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
6
+ </head>
7
+ <body>
8
+ <h2>Salesforce Client App</h2>
9
+ <div>
10
+ <a href='/login'>Login</a>
11
+ </div>
12
+ <div>
13
+ <a href='/logout'>Logout</a>
14
+ </div>
15
+ <div>
16
+ <a href='/connected'>Connected?</a>
17
+ </div>
18
+ <br>
19
+ <div>
20
+ <a href='/accounts'>Get Accounts</a>
21
+ </div>
22
+ <br>
23
+ <div>
24
+ <form action="/accounts" method="post">
25
+ <div>
26
+ NAME:<input type=text name="name">
27
+ </div>
28
+ <div>
29
+ <input type="submit" name="submit" value="Create Account" />
30
+ </div>
31
+ </form>
32
+ <br>
33
+ <form id="update-form">
34
+ <div>
35
+ ID:<input type=text name="id">
36
+ </div>
37
+ <div>
38
+ NAME:<input type=text name="name">
39
+ </div>
40
+ <div>
41
+ <input type="button" onclick="doPut()" value="Update Account" />
42
+ </div>
43
+ </form>
44
+ <br>
45
+ <form id="delete-form">
46
+ <div>
47
+ ID:<input type=text name="id">
48
+ </div>
49
+ <div>
50
+ <input type="button" onclick="doDelete()" value="Delete Account" />
51
+ </div>
52
+ </form>
53
+ </div>
54
+ <br>
55
+ <div>
56
+ <a href='/campaigns'>Get Campaigns</a>
57
+ </div>
58
+ <div>
59
+ <a href='/leads'>Get Leads</a>
60
+ </div>
61
+ <script type="text/javascript">
62
+ function doPut() {
63
+ var id = $('#update-form [name=id]').val();
64
+ var name = $('#update-form [name=name]').val();
65
+ $.ajax({
66
+ url: 'accounts',
67
+ type: 'PUT',
68
+ data: {
69
+ id: id,
70
+ name: name
71
+ }
72
+ });
73
+ }
74
+
75
+ function doDelete() {
76
+ var id = $('#update-form [name=id]').val();
77
+ $.ajax({
78
+ url: 'accounts',
79
+ type: 'DELETE',
80
+ data: {
81
+ id: id
82
+ }
83
+ });
84
+ }
85
+ </script>
86
+ </body>
87
+ </html>
data/images/1.png ADDED
Binary file
@@ -0,0 +1,11 @@
1
+ require 'thor'
2
+
3
+ module SalesforceClientApp
4
+ class CLI < Thor
5
+ desc "init PROJECT_NAME", "Generate the application project files."
6
+ def init(project_name)
7
+ FileUtils.cp_r(File.expand_path('../../../example/', __FILE__), project_name)
8
+ say("Files of \"#{project_name}\" project was generated.", :green)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module SalesforceClientApp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,156 @@
1
+ require "salesforce_client_app/version"
2
+ require "salesforce_client_app/cli"
3
+
4
+ require 'sinatra'
5
+ require 'sinatra/json'
6
+ require 'force'
7
+ require "omniauth"
8
+ require "omniauth-salesforce"
9
+ require 'pry'
10
+
11
+ module SalesforceClientApp
12
+
13
+ class App < Sinatra::Base
14
+ set :server, 'webrick'
15
+ enable :sessions
16
+
17
+ configure do
18
+ enable :logging
19
+ enable :sessions
20
+ set :show_exceptions, false
21
+ set :session_secret, ENV['SECRET']
22
+ end
23
+
24
+ use OmniAuth::Builder do
25
+ provider :salesforce, ENV['SALESFORCE_KEY'], ENV['SALESFORCE_SECRET']
26
+ end
27
+
28
+ helpers do
29
+ def client
30
+ @client ||= Force.new instance_url: session['instance_url'],
31
+ oauth_token: session['token'],
32
+ refresh_token: session['refresh_token'],
33
+ client_id: ENV['SALESFORCE_KEY'],
34
+ client_secret: ENV['SALESFORCE_SECRET']
35
+ end
36
+ end
37
+
38
+ def self.setRoot(root_directory)
39
+ set :root, root_directory
40
+ end
41
+
42
+ get '/' do
43
+ send_file File.join(settings.public_folder, 'index.html')
44
+ end
45
+
46
+ get '/login' do
47
+ redirect "/auth/salesforce"
48
+ end
49
+
50
+ get '/auth/salesforce/callback' do
51
+ logger.info "#{env["omniauth.auth"]["extra"]["display_name"]} just authenticated"
52
+ credentials = env["omniauth.auth"]["credentials"]
53
+ session['token'] = credentials["token"]
54
+ session['refresh_token'] = credentials["refresh_token"]
55
+ session['instance_url'] = credentials["instance_url"]
56
+ redirect '/'
57
+ end
58
+
59
+ error Force::UnauthorizedError do
60
+ redirect "/auth/salesforce"
61
+ end
62
+
63
+ get '/auth/failure' do
64
+ params[:message]
65
+ end
66
+
67
+ get '/logout' do
68
+ session.clear
69
+ redirect '/'
70
+ end
71
+
72
+ get '/connected' do
73
+ token = session[:token]
74
+ json connect: !token.nil?
75
+ end
76
+
77
+ get '/accounts' do
78
+ result= client.query("SELECT Id, Name, BillingStreet, BillingState, phone, fax FROM Account")
79
+ data = result.map do |record|
80
+ {
81
+ type: record.attributes.type,
82
+ id: record.Id,
83
+ name: record.Name,
84
+ BillingState: record.BillingState,
85
+ BillingStreet: record.BillingStreet,
86
+ phone: record.phone,
87
+ fax: record.fax,
88
+ }
89
+ end
90
+
91
+ data.to_json
92
+ end
93
+
94
+ post '/accounts' do
95
+ id = client.create('Account',
96
+ Name: params[:name],
97
+ BillingState: params[:billingstate],
98
+ BillingStreet: params[:billingstreet],
99
+ phone: params[:phone],
100
+ fax: params[:fax])
101
+
102
+ json success: true, id: id
103
+ end
104
+
105
+ put '/accounts' do
106
+ success = client.update('Account',
107
+ Id: params[:id],
108
+ Name: params[:name],
109
+ BillingStreet: params[:billingstreet],
110
+ phone: params[:phone],
111
+ fax: params[:fax])
112
+
113
+ json success: success
114
+ end
115
+
116
+ delete '/accounts' do
117
+ success = client.destroy('Account', params[:id])
118
+ json success: success
119
+ end
120
+
121
+ get '/campaigns' do
122
+ result= client.query("SELECT Id, Name, StartDate, EndDate, BudgetedCost, ActualCost, Type FROM Campaign")
123
+ data = result.map do |record|
124
+ {
125
+ type: record.attributes.type,
126
+ id: record.Id,
127
+ name: record.Name,
128
+ startDate: record.StartDate,
129
+ endDate: record.EndDate,
130
+ budgetedCost: record.BudgetedCost,
131
+ actualCost: record.ActualCost,
132
+ campainType: record.Type
133
+ }
134
+ end
135
+
136
+ data.to_json
137
+ end
138
+
139
+ get '/leads' do
140
+ result= client.query("SELECT Id, Name, Company, Status FROM Lead")
141
+ data = result.map do |record|
142
+ {
143
+ type: record.attributes.type,
144
+ id: record.Id,
145
+ name: record.Name,
146
+ company: record.Company,
147
+ status: record.Status
148
+ }
149
+ end
150
+
151
+ data.to_json
152
+ end
153
+
154
+ end
155
+
156
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'salesforce_client_app/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "salesforce_client_app"
8
+ spec.version = SalesforceClientApp::VERSION
9
+ spec.authors = ["KAWANO Shinobu"]
10
+ spec.email = ["kawanoshinobu@gmail.com"]
11
+ spec.summary = "A simple Sinatra app which is integrated with Force.com and some of its API."
12
+ spec.description = "This gem aims for the example of Sencha app."
13
+ spec.homepage = "https://github.com/kawanoshinobu/salesforce_client_app"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "sinatra"
22
+ spec.add_dependency "sinatra-contrib"
23
+ spec.add_dependency "foreman"
24
+ spec.add_dependency "omniauth-salesforce"
25
+ spec.add_dependency "certified"
26
+ spec.add_dependency "force"
27
+ spec.add_dependency "thor"
28
+ spec.add_dependency "pry"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.6"
31
+ spec.add_development_dependency "rake"
32
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salesforce_client_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - KAWANO Shinobu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra-contrib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: foreman
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: omniauth-salesforce
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: certified
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: force
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
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: This gem aims for the example of Sencha app.
154
+ email:
155
+ - kawanoshinobu@gmail.com
156
+ executables:
157
+ - salesforce_client_app
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - Gemfile
163
+ - LICENSE.txt
164
+ - README.md
165
+ - Rakefile
166
+ - bin/salesforce_client_app
167
+ - example/.env
168
+ - example/Procfile
169
+ - example/app.rb
170
+ - example/public/index.html
171
+ - images/1.png
172
+ - lib/salesforce_client_app.rb
173
+ - lib/salesforce_client_app/cli.rb
174
+ - lib/salesforce_client_app/version.rb
175
+ - salesforce_client_app.gemspec
176
+ homepage: https://github.com/kawanoshinobu/salesforce_client_app
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.2.0
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: A simple Sinatra app which is integrated with Force.com and some of its API.
200
+ test_files: []