asf-rest-adapter 0.3.3 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,6 +5,9 @@ source "http://rubygems.org"
5
5
 
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
+ gem "rforce"
9
+ gem "omniauth"
10
+
8
11
  group :development do
9
12
  #gem "shoulda", ">= 0"
10
13
  gem "bundler", "~> 1.0.0"
@@ -1,12 +1,76 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ addressable (2.2.5)
5
+ builder (3.0.0)
6
+ faraday (0.6.1)
7
+ addressable (~> 2.2.4)
8
+ multipart-post (~> 1.1.0)
9
+ rack (< 2, >= 1.1.0)
4
10
  git (1.2.5)
5
11
  jeweler (1.5.2)
6
12
  bundler (~> 1.0.0)
7
13
  git (>= 1.2.5)
8
14
  rake
15
+ mime-types (1.16)
16
+ multi_json (0.0.5)
17
+ multipart-post (1.1.0)
18
+ net-ldap (0.1.1)
19
+ nokogiri (1.4.4)
20
+ oa-basic (0.2.2)
21
+ multi_json (~> 0.0.2)
22
+ nokogiri (~> 1.4.2)
23
+ oa-core (= 0.2.2)
24
+ rest-client (~> 1.6.0)
25
+ oa-core (0.2.2)
26
+ rack (~> 1.1)
27
+ oa-enterprise (0.2.2)
28
+ net-ldap (~> 0.1.1)
29
+ nokogiri (~> 1.4.2)
30
+ oa-core (= 0.2.2)
31
+ pyu-ruby-sasl (~> 0.0.3.1)
32
+ rubyntlm (~> 0.1.1)
33
+ oa-more (0.2.2)
34
+ multi_json (~> 0.0.2)
35
+ oa-core (= 0.2.2)
36
+ rest-client (~> 1.6.0)
37
+ oa-oauth (0.2.2)
38
+ faraday (~> 0.6.1)
39
+ multi_json (~> 0.0.2)
40
+ nokogiri (~> 1.4.2)
41
+ oa-core (= 0.2.2)
42
+ oauth (~> 0.4.0)
43
+ oauth2 (~> 0.3.0)
44
+ oa-openid (0.2.2)
45
+ oa-core (= 0.2.2)
46
+ rack-openid (~> 1.2.0)
47
+ ruby-openid-apps-discovery
48
+ oauth (0.4.4)
49
+ oauth2 (0.3.0)
50
+ faraday (~> 0.6.0)
51
+ multi_json (~> 0.0.4)
52
+ omniauth (0.2.2)
53
+ oa-basic (= 0.2.2)
54
+ oa-core (= 0.2.2)
55
+ oa-enterprise (= 0.2.2)
56
+ oa-more (= 0.2.2)
57
+ oa-oauth (= 0.2.2)
58
+ oa-openid (= 0.2.2)
59
+ pyu-ruby-sasl (0.0.3.2)
60
+ rack (1.2.2)
61
+ rack-openid (1.2.0)
62
+ rack (>= 1.1.0)
63
+ ruby-openid (>= 2.1.8)
9
64
  rake (0.8.7)
65
+ rest-client (1.6.1)
66
+ mime-types (>= 1.16)
67
+ rforce (0.7)
68
+ builder (~> 3.0)
69
+ oauth (~> 0.4)
70
+ ruby-openid (2.1.8)
71
+ ruby-openid-apps-discovery (1.2.0)
72
+ ruby-openid (>= 2.1.7)
73
+ rubyntlm (0.1.1)
10
74
 
11
75
  PLATFORMS
12
76
  ruby
@@ -14,3 +78,5 @@ PLATFORMS
14
78
  DEPENDENCIES
15
79
  bundler (~> 1.0.0)
16
80
  jeweler (~> 1.5.2)
81
+ omniauth
82
+ rforce
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.4.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{asf-rest-adapter}
8
- s.version = "0.3.3"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Raymond Gao @ Are4Us Technologies"]
12
- s.date = %q{2011-04-11}
12
+ s.date = %q{2011-04-20}
13
13
  s.description = %q{REST based adapter for Salesforce}
14
14
  s.email = %q{raygao2000@yahoo.com}
15
15
  s.extra_rdoc_files = [
@@ -26,9 +26,10 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "asf-rest-adapter.gemspec",
29
+ "lib/Salesforce/oauth2/config_file/asf_rest_config.yml",
29
30
  "lib/Salesforce/oauth2/enviornments/environment.rb",
30
31
  "lib/Salesforce/oauth2/forcedotcom.rb",
31
- "lib/Salesforce/oauth2/initializers/omniauth.rb",
32
+ "lib/Salesforce/oauth2/initializers/asf_rest_adapter.rb",
32
33
  "lib/Salesforce/oauth2/routes/routes.rb",
33
34
  "lib/Salesforce/oauth2/templates/rails",
34
35
  "lib/Salesforce/oauth2/templates/ssl_templates/README",
@@ -82,7 +83,6 @@ Gem::Specification.new do |s|
82
83
  "lib/asf-rest-adapter.rb",
83
84
  "nbproject/private/private.properties",
84
85
  "nbproject/private/private.xml",
85
- "nbproject/private/rake-d.txt",
86
86
  "nbproject/project.properties",
87
87
  "nbproject/project.xml",
88
88
  "test/asf-rest-adapter-rails-app/.gitignore",
@@ -280,17 +280,23 @@ Gem::Specification.new do |s|
280
280
  s.specification_version = 3
281
281
 
282
282
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
283
+ s.add_runtime_dependency(%q<rforce>, [">= 0"])
284
+ s.add_runtime_dependency(%q<omniauth>, [">= 0"])
283
285
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
284
286
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
285
287
  s.add_runtime_dependency(%q<asf-soap-adapter>, [">= 0"])
286
288
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
287
289
  else
290
+ s.add_dependency(%q<rforce>, [">= 0"])
291
+ s.add_dependency(%q<omniauth>, [">= 0"])
288
292
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
289
293
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
290
294
  s.add_dependency(%q<asf-soap-adapter>, [">= 0"])
291
295
  s.add_dependency(%q<httparty>, [">= 0"])
292
296
  end
293
297
  else
298
+ s.add_dependency(%q<rforce>, [">= 0"])
299
+ s.add_dependency(%q<omniauth>, [">= 0"])
294
300
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
295
301
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
296
302
  s.add_dependency(%q<asf-soap-adapter>, [">= 0"])
@@ -0,0 +1,12 @@
1
+ asf-rest-config:
2
+ # Either "username_password" or "omni_auth"
3
+ auth_scheme: <username_password> or <omni_auth>
4
+ #username_password
5
+ adapter: activesalesforce
6
+ url: https://login.salesforce.com
7
+ username: <e-mail address>
8
+ password: <password + security_token>
9
+ api_version: 21.0
10
+ #omni_auth
11
+ consumer_key: <your consumer key>
12
+ consumer_secret: <your consumer secret>
@@ -0,0 +1,65 @@
1
+ #require 'forcedotcom' # no longer needed, it is a part of the asf-rest-adapter
2
+ require 'asf-rest-adapter'
3
+
4
+ # Set the default hostname for omniauth to send callbacks to.
5
+ # seems to be a bug in omniauth that it drops the httpS
6
+ # this still exists in 0.2.0
7
+ OmniAuth.config.full_host = 'https://localhost:3000'
8
+
9
+ module OmniAuth
10
+ module Strategies
11
+ #tell omniauth to load our strategy
12
+ autoload :Forcedotcom, 'lib/forcedotcom'
13
+ end
14
+ end
15
+
16
+
17
+ #Read the config
18
+ asf_rest_config_file = Rails.root.to_s + "/config/asf_rest_config.yml"
19
+ ASF_REST_CONFIG = YAML::load(File.open(asf_rest_config_file))
20
+
21
+ auth_scheme = ASF_REST_CONFIG["asf-rest-config"] ["auth_scheme"]
22
+ puts "ASF-REST-Adapter setting:"
23
+ puts "Auth name:" + auth_scheme
24
+
25
+ #setup the default adapter with relevant auth schema (username/password) or (Omniauth)
26
+ case auth_scheme
27
+ when "username_password":
28
+ puts 'Setting up adapter using username/password'
29
+ username = ASF_REST_CONFIG["asf-rest-config"]["username"]
30
+ password = ASF_REST_CONFIG["asf-rest-config"]["password"]
31
+ login_svr = ASF_REST_CONFIG["asf-rest-config"]["api_version"].to_s
32
+ api_version = ASF_REST_CONFIG["asf-rest-config"]["api_version"].to_s
33
+
34
+ puts "Salesforce url: " + ASF_REST_CONFIG["asf-rest-config"]["url"]
35
+ puts "Username: " + username
36
+ puts "Password: " + password
37
+ puts "API Version " + login_svr
38
+
39
+ security_token, rest_svr, rest_version = Salesforce::Rest::AsfRest.bootup_rest_adapter(username, password, api_version)
40
+ puts 'Security Token: ' + security_token
41
+ puts 'rest_svr: ' + rest_svr
42
+ puts 'rest_version: ' + rest_version
43
+ when"omni_auth":
44
+ consumer_key = ASF_REST_CONFIG["asf-rest-config"]["consumer_key"]
45
+ consumer_secret = ASF_REST_CONFIG["asf-rest-config"]["consumer_secret"]
46
+
47
+ puts "Salesforce consumer_key is:" + consumer_key.to_s
48
+ puts "Salesforce consumser_secret is: " + consumer_secret.to_s
49
+
50
+ Rails.application.config.middleware.use OmniAuth::Builder do
51
+ provider :forcedotcom, consumer_key, consumer_secret
52
+ end
53
+ end
54
+
55
+
56
+
57
+ OT2::Application.routes.draw do
58
+ # The priority is based upon order of creation:
59
+ # first created -> highest priority.
60
+
61
+ #add our oauth redirect route - qw
62
+ match '/auth/:provider/callbackzzz', :to => 'sessions#create'
63
+ match '/auth/failurezzz', :to => 'sessions#fail'
64
+
65
+ end
@@ -1,15 +1,11 @@
1
1
  # This is a template for the Route file
2
2
  OmniauthDemo::Application.routes.draw do
3
- get "sessions/create"
4
-
5
3
  # The priority is based upon order of creation:
6
4
  # first created -> highest priority.
7
5
 
8
6
  #add our oauth redirect route - qw
9
7
  match '/auth/:provider/callback', :to => 'sessions#create'
10
8
  match '/auth/failure', :to => 'sessions#fail'
11
-
12
-
13
9
  end
14
10
 
15
11
  #TODO, need to dynamically add to the Application's Route class.
@@ -17,6 +17,7 @@ require 'net/https'
17
17
  require 'net/http'
18
18
  require 'active_resource'
19
19
  require 'httparty'
20
+ require 'rforce'
20
21
 
21
22
 
22
23
  module Salesforce
@@ -21,29 +21,6 @@ module Authenticate
21
21
  #class methods
22
22
  def self.included(base)
23
23
  class << base
24
- # Initializes the adapter, the 1st step of using the adapter. A good place to invoke
25
- # it includes 'setup()' method in the 'test_helper' and Rails init file.
26
- # TODO, to be removed in the 1.0 version
27
- # usage -> bootup_rest_adapter_old_adapter()
28
- def bootup_rest_adapter_with_old_adapter()
29
- #require 'asf-soap-adapter'
30
- p "*" * 80
31
- p 'Set up code'
32
- @u = Salesforce::User.first
33
- @version = "v" + @u.connection.config[:api_version].to_s
34
- puts "Sf User name is: " + @u.name
35
-
36
- @oauth_token = @u.connection.binding.instance_variable_get("@session_id")
37
- puts "oauth token is: " + @oauth_token
38
-
39
- @soap_url = @u.connection.binding.instance_variable_get("@server").address
40
- @rest_svr = @soap_url.gsub(/-api\S*/mi, "") + ".salesforce.com"
41
- puts 'rest_svr' + @rest_svr
42
-
43
- self.setup(@oauth_token, @rest_svr, @version)
44
- return [@oauth_token, @rest_svr, @version]
45
- end
46
-
47
24
  # Initializes the adapter, using username, password. A good place to invoke
48
25
  # it includes 'setup()' method in the 'test_helper' and Rails init files.
49
26
  # usage -> bootup_rest_adapter(username, password, api_version)
@@ -75,6 +52,55 @@ module Authenticate
75
52
 
76
53
  return [security_token, rest_svr, rest_version]
77
54
  end
55
+
56
+ # Ignite the adapter, using the config_file, This will in term invoke
57
+ # bootup_rest_adapter(username, password, api_version) or set up with
58
+ # consumer key/secret with omniauth
59
+ def ignite_adapter(config_file)
60
+ #Read the configuration file
61
+
62
+ begin
63
+ asf_rest_config = YAML::load(File.open(config_file))
64
+
65
+ auth_scheme = asf_rest_config["asf-rest-config"] ["auth_scheme"]
66
+ puts "ASF-REST-Adapter setting:"
67
+ puts "Auth name:" + auth_scheme
68
+
69
+ #setup the default adapter with relevant auth schema (username/password) or (Omniauth)
70
+ case auth_scheme
71
+ when "username_password":
72
+ puts 'Setting up adapter using username/password'
73
+ username = asf_rest_config["asf-rest-config"]["username"]
74
+ password = asf_rest_config["asf-rest-config"]["password"]
75
+ login_svr = asf_rest_config["asf-rest-config"]["api_version"].to_s
76
+ api_version = asf_rest_config["asf-rest-config"]["api_version"].to_s
77
+
78
+ puts "Salesforce url: " + asf_rest_config["asf-rest-config"]["url"]
79
+ puts "Username: " + username
80
+ puts "Password: " + password
81
+ puts "API Version " + login_svr
82
+
83
+ security_token, rest_svr, rest_version = Salesforce::Rest::AsfRest.bootup_rest_adapter(username, password, api_version)
84
+ puts 'Security Token: ' + security_token
85
+ puts 'rest_svr: ' + rest_svr
86
+ puts 'rest_version: ' + rest_version
87
+ when"omni_auth":
88
+ consumer_key = asf_rest_config["asf-rest-config"]["consumer_key"]
89
+ consumer_secret = asf_rest_config["asf-rest-config"]["consumer_secret"]
90
+
91
+ puts "Salesforce consumer_key is:" + consumer_key.to_s
92
+ puts "Salesforce consumser_secret is: " + consumer_secret.to_s
93
+
94
+ Rails.application.config.middleware.use OmniAuth::Builder do
95
+ provider :forcedotcom, consumer_key, consumer_secret
96
+ end
97
+ end
98
+ rescue Exception => e
99
+ puts e.message
100
+ end
101
+ end
102
+
103
+
78
104
  end
79
105
  end
80
106
 
@@ -56,3 +56,6 @@ require File.dirname(__FILE__) + '/Salesforce/rest/classes/user.rb'
56
56
  require File.dirname(__FILE__) + '/Salesforce/rest/classes/user_feed.rb'
57
57
  require File.dirname(__FILE__) + '/Salesforce/rest/classes/user_role.rb'
58
58
  require File.dirname(__FILE__) + '/Salesforce/rest/classes/user_profile_feed.rb'
59
+
60
+ # OmniAuth/Salesforce Library
61
+ require File.dirname(__FILE__) + '/Salesforce/oauth2/forcedotcom.rb'
@@ -16,10 +16,7 @@ class ActiveSupport::TestCase
16
16
 
17
17
 
18
18
  def setup
19
- # initalize_adapter()
20
- # either use the classic ASF-SOAP-ADAPTER dependency
21
- #Salesforce::Rest::AsfRest.bootup_rest_adapter_with_old_adapter()
22
- # Or, use RFORCE to create a session directly.
19
+ # use RFORCE to create a session directly or use consumer secret/key with omniauth
23
20
 
24
21
  username = 'your SF usermame'
25
22
  password = 'SF password + token'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asf-rest-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
8
+ - 4
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Raymond Gao @ Are4Us Technologies
@@ -15,11 +15,39 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-11 00:00:00 -05:00
18
+ date: 2011-04-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ name: rforce
32
+ version_requirements: *id001
33
+ prerelease: false
34
+ type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ name: omniauth
46
+ version_requirements: *id002
47
+ prerelease: false
48
+ type: :runtime
49
+ - !ruby/object:Gem::Dependency
50
+ requirement: &id003 !ruby/object:Gem::Requirement
23
51
  none: false
24
52
  requirements:
25
53
  - - ~>
@@ -30,12 +58,12 @@ dependencies:
30
58
  - 0
31
59
  - 0
32
60
  version: 1.0.0
33
- version_requirements: *id001
34
61
  name: bundler
62
+ version_requirements: *id003
35
63
  prerelease: false
36
64
  type: :development
37
65
  - !ruby/object:Gem::Dependency
38
- requirement: &id002 !ruby/object:Gem::Requirement
66
+ requirement: &id004 !ruby/object:Gem::Requirement
39
67
  none: false
40
68
  requirements:
41
69
  - - ~>
@@ -46,12 +74,12 @@ dependencies:
46
74
  - 5
47
75
  - 2
48
76
  version: 1.5.2
49
- version_requirements: *id002
50
77
  name: jeweler
78
+ version_requirements: *id004
51
79
  prerelease: false
52
80
  type: :development
53
81
  - !ruby/object:Gem::Dependency
54
- requirement: &id003 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
55
83
  none: false
56
84
  requirements:
57
85
  - - ">="
@@ -60,12 +88,12 @@ dependencies:
60
88
  segments:
61
89
  - 0
62
90
  version: "0"
63
- version_requirements: *id003
64
91
  name: asf-soap-adapter
92
+ version_requirements: *id005
65
93
  prerelease: false
66
94
  type: :runtime
67
95
  - !ruby/object:Gem::Dependency
68
- requirement: &id004 !ruby/object:Gem::Requirement
96
+ requirement: &id006 !ruby/object:Gem::Requirement
69
97
  none: false
70
98
  requirements:
71
99
  - - ">="
@@ -74,8 +102,8 @@ dependencies:
74
102
  segments:
75
103
  - 0
76
104
  version: "0"
77
- version_requirements: *id004
78
105
  name: httparty
106
+ version_requirements: *id006
79
107
  prerelease: false
80
108
  type: :runtime
81
109
  description: REST based adapter for Salesforce
@@ -97,9 +125,10 @@ files:
97
125
  - Rakefile
98
126
  - VERSION
99
127
  - asf-rest-adapter.gemspec
128
+ - lib/Salesforce/oauth2/config_file/asf_rest_config.yml
100
129
  - lib/Salesforce/oauth2/enviornments/environment.rb
101
130
  - lib/Salesforce/oauth2/forcedotcom.rb
102
- - lib/Salesforce/oauth2/initializers/omniauth.rb
131
+ - lib/Salesforce/oauth2/initializers/asf_rest_adapter.rb
103
132
  - lib/Salesforce/oauth2/routes/routes.rb
104
133
  - lib/Salesforce/oauth2/templates/rails
105
134
  - lib/Salesforce/oauth2/templates/ssl_templates/README
@@ -153,7 +182,6 @@ files:
153
182
  - lib/asf-rest-adapter.rb
154
183
  - nbproject/private/private.properties
155
184
  - nbproject/private/private.xml
156
- - nbproject/private/rake-d.txt
157
185
  - nbproject/project.properties
158
186
  - nbproject/project.xml
159
187
  - test/asf-rest-adapter-rails-app/.gitignore
@@ -1,19 +0,0 @@
1
- # Initializer template
2
- require 'forcedotcom'
3
-
4
- # Set the default hostname for omniauth to send callbacks to.
5
- # seems to be a bug in omniauth that it drops the httpS
6
- # this still exists in 0.2.0
7
- OmniAuth.config.full_host = 'https://localhost:3000'
8
-
9
- module OmniAuth
10
- module Strategies
11
- #tell omniauth to load our strategy
12
- autoload :Forcedotcom, 'lib/forcedotcom'
13
- end
14
- end
15
-
16
-
17
- Rails.application.config.middleware.use OmniAuth::Builder do
18
- provider :forcedotcom, '3MVG9yZ.WNe6byQDkN5SfIbP0HhAvCqdjOcGL9cXboLq5TeFN9eHOdTuEn443ELqv4ka8ZmzXSbY_kUeg7zMn', '953858431687220560'
19
- end
@@ -1,26 +0,0 @@
1
- build=Build gem into pkg/
2
- clobber=
3
- clobber_rdoc=Remove rdoc products
4
- console[script]=Start IRB with all runtime dependencies loaded
5
- default=
6
- gemcutter\:release=Release gem to Gemcutter
7
- gemspec=Generate and validate gemspec
8
- gemspec\:debug=Display the gemspec for debugging purposes, as jeweler knows it (not from the filesystem)
9
- gemspec\:generate=Regenreate the gemspec on the filesystem
10
- gemspec\:release=Regenerate and validate gemspec, and then commits and pushes to git
11
- gemspec\:validate=Validates the gemspec on the filesystem
12
- gemspec_required=
13
- git\:release=Tag and push release to git. (happens by default with `rake release`)
14
- install=Build and install gem using `gem install`
15
- rcov=
16
- rdoc=Build the rdoc HTML Files
17
- rdoc/index.html=
18
- release=Release gem
19
- rerdoc=Force a rebuild of the RDOC files
20
- test=Run tests
21
- version=Displays the current version
22
- version\:bump\:major=Bump the major version by 1
23
- version\:bump\:minor=Bump the a minor version by 1
24
- version\:bump\:patch=Bump the patch version by 1
25
- version\:write=Writes out an explicit version. Respects the following environment variables, or defaults to 0: MAJOR, MINOR, PATCH. Also recognizes BUILD, which defaults to nil
26
- version_required=