salesforce_connector 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,14 +2,42 @@
2
2
 
3
3
  Rails gem to connect an application to Salesforce accounts.
4
4
 
5
- == Install
5
+ == Install in your Gemfile
6
6
 
7
- gem install salesforce_connector
7
+ gem 'salesforce_connector'
8
8
 
9
+ == Dependencies
10
+
11
+ Salesforce Connector is based on HTTParty to access Salesforce API and on OmniAuth to retrieve OAuth2 tokens.
9
12
 
10
13
  == Usage
11
14
 
15
+ In your initiliazer (Rails3) or config.ru file (Sinatra or Padrino) add the 4 following elements
16
+
17
+ Add the Forcedotcom OAuth Strategy
18
+ module OmniAuth
19
+ module Strategies
20
+ #tell omniauth to load our strategy
21
+ autoload :Forcedotcom, '???'
22
+ end
23
+ end
24
+
25
+ Define the current host:
26
+ OmniAuth.config.full_host = 'https://localhost:3000'
27
+
28
+ Configure the Salesforce remote server URL and version
29
+ ENV['sfdc_instance_url'] = "https://eu1.salesforce.com"
30
+ ENV['sfdc_api_version'] = "21.0"
31
+
32
+ Load the Forcedotcom OAuth strategy
33
+ use OmniAuth::Builder do
34
+ provider :forcedotcom, '3MVG9PhR6g6B7ps6in8a_o8S1IvXGM41y725iSJXhSWZm5GJ0gZgvuQkLdT7YWOLciMWxn5yDglwAcjkGzcal', '2539130913145733702'
35
+ end
36
+
37
+ == Note
12
38
 
39
+ Salesforce OAuth only implement https authentication.
40
+ Be sure that your server (requester) is also running behing https.
13
41
 
14
42
  == License
15
43
 
@@ -0,0 +1,43 @@
1
+ #require "salesforce_connector/version"
2
+ require 'omniauth/oauth'
3
+ require 'multi_json'
4
+
5
+
6
+ # Omniauth strategy for using oauth2 and force.com
7
+ # Author: vzmind@gmail.com
8
+ #
9
+ module OmniAuth
10
+ module Strategies
11
+ class Forcedotcom < OAuth2
12
+ # Initialize the middleware
13
+ #
14
+ # @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
15
+ # @option options [Boolean, false] :mobile When true, use the mobile sign-in interface.
16
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
17
+ client_options = {
18
+ :site => "https://login.salesforce.com",
19
+ :authorize_path => "/services/oauth2/authorize",
20
+ :access_token_path => "/services/oauth2/token"
21
+ }
22
+ super(app, :forcedotcom, client_id, client_secret, client_options, &block)
23
+ end
24
+
25
+ def request_phase
26
+ options[:response_type] ||= 'code'
27
+ super
28
+ end
29
+
30
+ def callback_phase
31
+ options[:grant_type] ||= 'authorization_code'
32
+ super
33
+ end
34
+
35
+ def auth_hash
36
+ OmniAuth::Utils.deep_merge(super, {
37
+ 'instance_url' => @access_token['instance_url']
38
+ })
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,7 @@
1
1
  require "salesforce_connector/version"
2
+ require "salesforce_connector/account"
3
+ require "forcedotcom"
2
4
 
3
5
  module SalesforceConnector
4
- # Your code goes here...
6
+
5
7
  end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ module SalesforceConnector
5
+ class Account
6
+ include HTTParty
7
+ #doesn't seem to pick up env variable correctly if I set it here
8
+ #headers 'Authorization' => "OAuth #{ENV['sfdc_token']}"
9
+ format :json
10
+ #debug_output $stderr
11
+
12
+ def self.set_headers
13
+ headers 'Authorization' => "OAuth #{ENV['sfdc_token']}"
14
+ end
15
+
16
+ def self.root_url
17
+ @root_url = ENV['sfdc_instance_url']+"/services/data/v"+ENV['sfdc_api_version']
18
+ end
19
+
20
+ def self.get_first_hundred
21
+ SalesforceConnector::Account.set_headers
22
+ get(SalesforceConnector::Account.root_url+"/query/?q=#{CGI::escape('SELECT Name, Id from Account LIMIT 100')}")
23
+ end
24
+
25
+ def self.get_all_by_last_name(last_name)
26
+ #TODO
27
+ end
28
+ end
29
+ end
30
+
@@ -1,3 +1,3 @@
1
1
  module SalesforceConnector
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Vzmind
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-01 00:00:00 Z
18
+ date: 2011-08-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: omniauth
@@ -63,7 +63,9 @@ files:
63
63
  - Gemfile
64
64
  - README.rdoc
65
65
  - Rakefile
66
+ - lib/forcedotcom.rb
66
67
  - lib/salesforce_connector.rb
68
+ - lib/salesforce_connector/account.rb
67
69
  - lib/salesforce_connector/version.rb
68
70
  - salesforce_connector.gemspec
69
71
  homepage: http://github.com/vzmind