salesforce-chatter 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +20 -0
- data/README.md +24 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/faraday/request/multipart_with_file.rb +30 -0
- data/lib/faraday/request/salesforce_oauth.rb +24 -0
- data/lib/faraday/response/raise_http_4xx.rb +45 -0
- data/lib/faraday/response/raise_http_5xx.rb +24 -0
- data/lib/salesforce-chatter.rb +28 -0
- data/lib/salesforce-chatter/api.rb +24 -0
- data/lib/salesforce-chatter/authentication.rb +33 -0
- data/lib/salesforce-chatter/client.rb +9 -0
- data/lib/salesforce-chatter/client/feed_items.rb +25 -0
- data/lib/salesforce-chatter/configuration.rb +99 -0
- data/lib/salesforce-chatter/connection.rb +43 -0
- data/lib/salesforce-chatter/request.rb +32 -0
- data/lib/salesforce-chatter/version.rb +4 -0
- data/spec/salesforce-chatter_spec.rb +75 -0
- data/spec/spec_helper.rb +12 -0
- metadata +236 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'yajl-ruby'
|
4
|
+
gem 'simple_oauth'
|
5
|
+
gem "hashie"
|
6
|
+
gem "omniauth"
|
7
|
+
gem "faraday"
|
8
|
+
gem "faraday_middleware"
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.5.2"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.5)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
faraday (0.6.1)
|
7
|
+
addressable (~> 2.2.4)
|
8
|
+
multipart-post (~> 1.1.0)
|
9
|
+
rack (>= 1.1.0, < 2)
|
10
|
+
faraday_middleware (0.6.5)
|
11
|
+
faraday (~> 0.6.0)
|
12
|
+
git (1.2.5)
|
13
|
+
hashie (0.1.8)
|
14
|
+
jeweler (1.5.2)
|
15
|
+
bundler (~> 1.0.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
mime-types (1.16)
|
19
|
+
multi_json (0.0.5)
|
20
|
+
multipart-post (1.1.0)
|
21
|
+
net-ldap (0.1.1)
|
22
|
+
nokogiri (1.4.7)
|
23
|
+
oa-basic (0.2.3)
|
24
|
+
multi_json (~> 0.0.2)
|
25
|
+
nokogiri (~> 1.4.2)
|
26
|
+
oa-core (= 0.2.3)
|
27
|
+
rest-client (~> 1.6.0)
|
28
|
+
oa-core (0.2.3)
|
29
|
+
rack (~> 1.1)
|
30
|
+
oa-enterprise (0.2.3)
|
31
|
+
net-ldap (~> 0.1.1)
|
32
|
+
nokogiri (~> 1.4.2)
|
33
|
+
oa-core (= 0.2.3)
|
34
|
+
pyu-ruby-sasl (~> 0.0.3.1)
|
35
|
+
rubyntlm (~> 0.1.1)
|
36
|
+
oa-more (0.2.3)
|
37
|
+
multi_json (~> 0.0.2)
|
38
|
+
oa-core (= 0.2.3)
|
39
|
+
rest-client (~> 1.6.0)
|
40
|
+
oa-oauth (0.2.3)
|
41
|
+
faraday (~> 0.6.1)
|
42
|
+
multi_json (>= 0.0.5)
|
43
|
+
nokogiri (~> 1.4.2)
|
44
|
+
oa-core (= 0.2.3)
|
45
|
+
oauth (~> 0.4.0)
|
46
|
+
oauth2 (~> 0.3.0)
|
47
|
+
oa-openid (0.2.3)
|
48
|
+
oa-core (= 0.2.3)
|
49
|
+
rack-openid (~> 1.2.0)
|
50
|
+
ruby-openid-apps-discovery
|
51
|
+
oauth (0.4.5)
|
52
|
+
oauth2 (0.3.0)
|
53
|
+
faraday (~> 0.6.0)
|
54
|
+
multi_json (~> 0.0.4)
|
55
|
+
omniauth (0.2.3)
|
56
|
+
oa-basic (= 0.2.3)
|
57
|
+
oa-core (= 0.2.3)
|
58
|
+
oa-enterprise (= 0.2.3)
|
59
|
+
oa-more (= 0.2.3)
|
60
|
+
oa-oauth (= 0.2.3)
|
61
|
+
oa-openid (= 0.2.3)
|
62
|
+
pyu-ruby-sasl (0.0.3.3)
|
63
|
+
rack (1.2.1)
|
64
|
+
rack-openid (1.2.0)
|
65
|
+
rack (>= 1.1.0)
|
66
|
+
ruby-openid (>= 2.1.8)
|
67
|
+
rake (0.9.2)
|
68
|
+
rcov (0.9.9)
|
69
|
+
rest-client (1.6.3)
|
70
|
+
mime-types (>= 1.16)
|
71
|
+
rspec (2.3.0)
|
72
|
+
rspec-core (~> 2.3.0)
|
73
|
+
rspec-expectations (~> 2.3.0)
|
74
|
+
rspec-mocks (~> 2.3.0)
|
75
|
+
rspec-core (2.3.1)
|
76
|
+
rspec-expectations (2.3.0)
|
77
|
+
diff-lcs (~> 1.1.2)
|
78
|
+
rspec-mocks (2.3.0)
|
79
|
+
ruby-openid (2.1.8)
|
80
|
+
ruby-openid-apps-discovery (1.2.0)
|
81
|
+
ruby-openid (>= 2.1.7)
|
82
|
+
rubyntlm (0.1.1)
|
83
|
+
simple_oauth (0.1.4)
|
84
|
+
yajl-ruby (0.8.2)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
ruby
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
bundler (~> 1.0.0)
|
91
|
+
faraday
|
92
|
+
faraday_middleware
|
93
|
+
hashie
|
94
|
+
jeweler (~> 1.5.2)
|
95
|
+
omniauth
|
96
|
+
rcov
|
97
|
+
rspec (~> 2.3.0)
|
98
|
+
simple_oauth
|
99
|
+
yajl-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Dylan Vaughn
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
Salesforce Chatter Ruby Gem
|
3
|
+
===========================
|
4
|
+
A Ruby wrapper for the Salesforce Chatter REST API
|
5
|
+
|
6
|
+
|
7
|
+
Contributing to salesforce-chatter
|
8
|
+
==================================
|
9
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
10
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
11
|
+
* Fork the project
|
12
|
+
* Start a feature/bugfix branch
|
13
|
+
* Commit and push until you are happy with your contribution
|
14
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
+
|
17
|
+
Acknowledgements
|
18
|
+
================
|
19
|
+
The design for this project was based on the [Twitter](https://github.com/jnunemaker/twitter) gem.
|
20
|
+
|
21
|
+
Copyright
|
22
|
+
=========
|
23
|
+
Copyright (c) 2011 Dylan Vaughn. See LICENSE.txt for further details.
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "salesforce-chatter"
|
16
|
+
gem.homepage = "http://github.com/dylanvaughn/salesforce-chatter"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Ruby Client for Salesforce Chatter REST API}
|
19
|
+
gem.description = %Q{Ruby Client for Salesforce Chatter REST API}
|
20
|
+
gem.email = "dylancvaughn@gmail.com"
|
21
|
+
gem.authors = ["Dylan Vaughn"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "salesforce-chatter #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Request::MultipartWithFile < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
if env[:body].is_a?(Hash)
|
9
|
+
env[:body].each do |key, value|
|
10
|
+
if value.is_a?(File)
|
11
|
+
env[:body][key] = Faraday::UploadIO.new(value, mime_type(value), value.path)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def mime_type(file)
|
22
|
+
case file.path
|
23
|
+
when /\.jpe?g/i then 'image/jpeg'
|
24
|
+
when /\.gif$/i then 'image/gif'
|
25
|
+
when /\.png$/i then 'image/png'
|
26
|
+
else 'application/octet-stream'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Request::SalesforceOAuth < Faraday::Middleware
|
5
|
+
dependency 'simple_oauth'
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
params = env[:body] || {}
|
9
|
+
signature_params = params
|
10
|
+
|
11
|
+
params.map{ |k,v| signature_params = {} if v.respond_to?(:content_type) }
|
12
|
+
|
13
|
+
if SalesforceChatter.authenticated?
|
14
|
+
env[:request_headers]['Authorization'] = "OAuth #{SalesforceChatter.oauth_token}"
|
15
|
+
end
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(app, options)
|
21
|
+
@app, @options = app, options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Response::RaiseHttp4xx < Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status].to_i
|
9
|
+
when 400
|
10
|
+
raise SalesforceChatter::BadRequest.new(error_message(env), env[:response_headers])
|
11
|
+
when 401
|
12
|
+
raise SalesforceChatter::Unauthorized.new(error_message(env), env[:response_headers])
|
13
|
+
when 403
|
14
|
+
raise SalesforceChatter::Forbidden.new(error_message(env), env[:response_headers])
|
15
|
+
when 404
|
16
|
+
raise SalesforceChatter::NotFound.new(error_message(env), env[:response_headers])
|
17
|
+
when 406
|
18
|
+
raise SalesforceChatter::NotAcceptable.new(error_message(env), env[:response_headers])
|
19
|
+
when 420
|
20
|
+
raise SalesforceChatter::EnhanceYourCalm.new(error_message(env), env[:response_headers])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def error_message(env)
|
27
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_body(body)
|
31
|
+
if body.nil?
|
32
|
+
nil
|
33
|
+
elsif body['error']
|
34
|
+
": #{body['error']}"
|
35
|
+
elsif body['errors']
|
36
|
+
first = Array(body['errors']).first
|
37
|
+
if first.kind_of? Hash
|
38
|
+
": #{first['message'].chomp}"
|
39
|
+
else
|
40
|
+
": #{first.chomp}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Response::RaiseHttp5xx < Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status].to_i
|
9
|
+
when 500
|
10
|
+
raise SalesforceChatter::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
|
11
|
+
when 502
|
12
|
+
raise SalesforceChatter::BadGateway.new(error_message(env, "Something is technically wrong."), env[:response_headers])
|
13
|
+
when 503
|
14
|
+
raise SalesforceChatter::ServiceUnavailable.new(error_message(env, "Something is technically wrong."), env[:response_headers])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def error_message(env, body=nil)
|
21
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check https://trust.salesforce.com/trust/status/ for updates on the status of the Salesforce API services."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'hashie'
|
3
|
+
require 'simple_oauth'
|
4
|
+
require 'salesforce-chatter/configuration'
|
5
|
+
require 'salesforce-chatter/api'
|
6
|
+
require 'salesforce-chatter/client'
|
7
|
+
|
8
|
+
module SalesforceChatter
|
9
|
+
extend Configuration
|
10
|
+
|
11
|
+
# Alias for SalesforceChatter::Client.new
|
12
|
+
#
|
13
|
+
# @return [SalesforceChatter::Client]
|
14
|
+
def self.new(options={})
|
15
|
+
SalesforceChatter::Client.new(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Delegate to SalesforceChatter::Client
|
19
|
+
def self.method_missing(method, *args, &block)
|
20
|
+
return super unless new.respond_to?(method)
|
21
|
+
new.send(method, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.respond_to?(method, include_private = false)
|
25
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'salesforce-chatter/connection'
|
2
|
+
require 'salesforce-chatter/request'
|
3
|
+
require 'salesforce-chatter/authentication'
|
4
|
+
|
5
|
+
module SalesforceChatter
|
6
|
+
class API
|
7
|
+
|
8
|
+
# @private
|
9
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
10
|
+
|
11
|
+
# Creates a new API
|
12
|
+
def initialize(options={})
|
13
|
+
self.oauth_token = options.delete :oauth_token
|
14
|
+
options = SalesforceChatter.options.merge(options)
|
15
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
16
|
+
send("#{key}=", options[key])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
include Connection
|
21
|
+
include Request
|
22
|
+
include Authentication
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SalesforceChatter
|
2
|
+
|
3
|
+
module Authentication
|
4
|
+
|
5
|
+
def authenticate(options={})
|
6
|
+
options[:client_id] = SalesforceChatter.consumer_key
|
7
|
+
options[:client_secret] = SalesforceChatter.consumer_secret
|
8
|
+
options[:username] = SalesforceChatter.username
|
9
|
+
options[:password] = SalesforceChatter.password + SalesforceChatter.security_token
|
10
|
+
options[:grant_type] = 'password'
|
11
|
+
|
12
|
+
response = post('services/oauth2/token', options)
|
13
|
+
SalesforceChatter.oauth_token = response.access_token
|
14
|
+
response
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def authentication
|
19
|
+
{
|
20
|
+
:consumer_key => consumer_key,
|
21
|
+
:consumer_secret => consumer_secret,
|
22
|
+
:token => oauth_token,
|
23
|
+
:token_secret => oauth_token_secret
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def authenticated?
|
28
|
+
!SalesforceChatter.oauth_token.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SalesforceChatter
|
2
|
+
class Client
|
3
|
+
# Defines methods related to feed items
|
4
|
+
module FeedItems
|
5
|
+
def feed_items(*args)
|
6
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
7
|
+
user = args.first
|
8
|
+
response = get('/chatter/feeds/news/me/feed-items', options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def feed_item_create(text, options={})
|
12
|
+
options[:text] = text
|
13
|
+
response = post("/chatter/feeds/news/me/feed-items", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def feed_item_destroy(id, options={})
|
17
|
+
response = delete("/chatter/feed-items/#{id}", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def feed_item(id, options={})
|
21
|
+
response = get("/chatter/feed-items/#{id}", options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'salesforce-chatter/version'
|
3
|
+
|
4
|
+
module SalesforceChatter
|
5
|
+
# Defines constants and methods related to configuration
|
6
|
+
module Configuration
|
7
|
+
# An array of valid keys in the options hash when configuring a {SalesforceChatter::API}
|
8
|
+
VALID_OPTIONS_KEYS = [
|
9
|
+
:adapter,
|
10
|
+
:consumer_key,
|
11
|
+
:consumer_secret,
|
12
|
+
:endpoint,
|
13
|
+
:format,
|
14
|
+
:gateway,
|
15
|
+
:oauth_token,
|
16
|
+
:oauth_token_secret,
|
17
|
+
:proxy,
|
18
|
+
:username,
|
19
|
+
:password,
|
20
|
+
:security_token,
|
21
|
+
:oauth_token,
|
22
|
+
:user_agent].freeze
|
23
|
+
|
24
|
+
# An array of valid request/response formats
|
25
|
+
#
|
26
|
+
# @note Not all methods support the XML format.
|
27
|
+
VALID_FORMATS = [
|
28
|
+
:json,
|
29
|
+
:xml].freeze
|
30
|
+
|
31
|
+
# The adapter that will be used to connect if none is set
|
32
|
+
#
|
33
|
+
# @note The default faraday adapter is Net::HTTP.
|
34
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
35
|
+
|
36
|
+
# By default, don't set an application key
|
37
|
+
DEFAULT_CONSUMER_KEY = nil
|
38
|
+
|
39
|
+
# By default, don't set an application secret
|
40
|
+
DEFAULT_CONSUMER_SECRET = nil
|
41
|
+
|
42
|
+
# The endpoint that will be used to connect if none is set
|
43
|
+
DEFAULT_ENDPOINT = 'https://login.salesforce.com/'.freeze
|
44
|
+
|
45
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
46
|
+
#
|
47
|
+
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
48
|
+
DEFAULT_FORMAT = :json
|
49
|
+
|
50
|
+
# By default, don't set a user oauth token
|
51
|
+
DEFAULT_OAUTH_TOKEN = nil
|
52
|
+
|
53
|
+
# By default, don't set a user oauth secret
|
54
|
+
DEFAULT_OAUTH_TOKEN_SECRET = nil
|
55
|
+
|
56
|
+
# By default, don't use a proxy server
|
57
|
+
DEFAULT_PROXY = nil
|
58
|
+
|
59
|
+
# The user agent that will be sent to the API endpoint if none is set
|
60
|
+
DEFAULT_USER_AGENT = "SalesforceChatter Ruby Gem #{SalesforceChatter::VERSION}".freeze
|
61
|
+
|
62
|
+
DEFAULT_GATEWAY = nil
|
63
|
+
|
64
|
+
# @private
|
65
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
66
|
+
|
67
|
+
# When this module is extended, set all configuration options to their default values
|
68
|
+
def self.extended(base)
|
69
|
+
base.reset
|
70
|
+
end
|
71
|
+
|
72
|
+
# Convenience method to allow configuration options to be set in a block
|
73
|
+
def configure
|
74
|
+
yield self
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create a hash of options and their values
|
78
|
+
def options
|
79
|
+
options = {}
|
80
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
|
81
|
+
options
|
82
|
+
end
|
83
|
+
|
84
|
+
# Reset all configuration options to defaults
|
85
|
+
def reset
|
86
|
+
self.adapter = DEFAULT_ADAPTER
|
87
|
+
self.consumer_key = DEFAULT_CONSUMER_KEY
|
88
|
+
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
89
|
+
self.endpoint = DEFAULT_ENDPOINT
|
90
|
+
self.format = DEFAULT_FORMAT
|
91
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
92
|
+
self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
|
93
|
+
self.proxy = DEFAULT_PROXY
|
94
|
+
self.user_agent = DEFAULT_USER_AGENT
|
95
|
+
self.gateway = DEFAULT_GATEWAY
|
96
|
+
self
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/request/multipart_with_file'
|
3
|
+
# require 'faraday/request/gateway'
|
4
|
+
require 'faraday/request/salesforce_oauth'
|
5
|
+
require 'faraday/response/raise_http_4xx'
|
6
|
+
require 'faraday/response/raise_http_5xx'
|
7
|
+
|
8
|
+
module SalesforceChatter
|
9
|
+
# @private
|
10
|
+
module Connection
|
11
|
+
private
|
12
|
+
|
13
|
+
def connection(raw=false)
|
14
|
+
options = {
|
15
|
+
:headers => {'Accept' => "application/#{format}", 'User-Agent' => user_agent},
|
16
|
+
:proxy => proxy,
|
17
|
+
:ssl => {:verify => false},
|
18
|
+
:url => api_endpoint,
|
19
|
+
}
|
20
|
+
|
21
|
+
Faraday.new(options) do |builder|
|
22
|
+
builder.use Faraday::Request::MultipartWithFile
|
23
|
+
builder.use Faraday::Request::SalesforceOAuth, authentication if authenticated?
|
24
|
+
builder.use Faraday::Request::Multipart
|
25
|
+
builder.use Faraday::Request::UrlEncoded
|
26
|
+
builder.use Faraday::Request::Gateway, gateway if gateway
|
27
|
+
builder.use Faraday::Response::RaiseHttp4xx
|
28
|
+
builder.use Faraday::Response::Logger
|
29
|
+
builder.use Faraday::Response::Mashify unless raw
|
30
|
+
unless raw
|
31
|
+
case format.to_s.downcase
|
32
|
+
when 'json'
|
33
|
+
builder.use Faraday::Response::ParseJson
|
34
|
+
when 'xml'
|
35
|
+
builder.use Faraday::Response::ParseXml
|
36
|
+
end
|
37
|
+
end
|
38
|
+
builder.use Faraday::Response::RaiseHttp5xx
|
39
|
+
builder.adapter(adapter)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SalesforceChatter
|
2
|
+
|
3
|
+
module Request
|
4
|
+
def get(path, options={}, raw=false)
|
5
|
+
request(:get, path, options, raw)
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(path, options={}, raw=false)
|
9
|
+
request(:post, path, options, raw)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# Perform an HTTP request
|
15
|
+
def request(method, path, options, raw=false)
|
16
|
+
response = connection(raw).send(method) do |request|
|
17
|
+
case method
|
18
|
+
when :get, :delete
|
19
|
+
request.url(formatted_path(path), options)
|
20
|
+
when :post, :put
|
21
|
+
request.path = formatted_path(path)
|
22
|
+
request.body = options unless options.empty?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
raw ? response : response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def formatted_path(path)
|
29
|
+
SalesforceChatter.authenticated? ? File.join("/services/data/v22.0/", path) : path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SalesforceChatter" do
|
4
|
+
|
5
|
+
after do
|
6
|
+
SalesforceChatter.reset
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".configure" do
|
10
|
+
|
11
|
+
SalesforceChatter::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
12
|
+
it "should set the #{key}" do
|
13
|
+
SalesforceChatter.configure do |config|
|
14
|
+
config.send("#{key}=", key)
|
15
|
+
SalesforceChatter.send(key).should == key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get an oauth token for the user" do
|
21
|
+
SalesforceChatter.configure do |config|
|
22
|
+
config.consumer_key = ""
|
23
|
+
config.consumer_secret = ""
|
24
|
+
config.username = ""
|
25
|
+
config.password = ""
|
26
|
+
config.endpoint = ""
|
27
|
+
config.security_token = ""
|
28
|
+
end
|
29
|
+
SalesforceChatter.authenticate
|
30
|
+
SalesforceChatter.oauth_token.should_not be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should reset auth token" do
|
34
|
+
SalesforceChatter.configure do |config|
|
35
|
+
config.consumer_key = ""
|
36
|
+
config.consumer_secret = ""
|
37
|
+
config.username = ""
|
38
|
+
config.password = ""
|
39
|
+
config.endpoint = ""
|
40
|
+
config.security_token = ""
|
41
|
+
end
|
42
|
+
SalesforceChatter.authenticate
|
43
|
+
SalesforceChatter.reset
|
44
|
+
SalesforceChatter.oauth_token.should == nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be able to use an existing auth token" do
|
48
|
+
SalesforceChatter.configure do |config|
|
49
|
+
config.consumer_key = ""
|
50
|
+
config.consumer_secret = ""
|
51
|
+
config.username = ""
|
52
|
+
config.password = ""
|
53
|
+
config.endpoint = ""
|
54
|
+
config.security_token = ""
|
55
|
+
end
|
56
|
+
SalesforceChatter.authenticate
|
57
|
+
oauth_token = SalesforceChatter.oauth_token
|
58
|
+
SalesforceChatter.reset
|
59
|
+
|
60
|
+
|
61
|
+
SalesforceChatter.configure do |config|
|
62
|
+
config.consumer_key = ""
|
63
|
+
config.consumer_secret = ""
|
64
|
+
config.username = ""
|
65
|
+
config.password = ""
|
66
|
+
config.endpoint = ""
|
67
|
+
config.security_token = ""
|
68
|
+
config.oauth_token = oauth_token
|
69
|
+
end
|
70
|
+
|
71
|
+
SalesforceChatter.feed_items.class.should == Hashie::Mash
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'salesforce-chatter'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: salesforce-chatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dylan Vaughn
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-14 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &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
|
+
requirement: *id001
|
32
|
+
prerelease: false
|
33
|
+
name: yajl-ruby
|
34
|
+
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &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
|
+
requirement: *id002
|
46
|
+
prerelease: false
|
47
|
+
name: simple_oauth
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirement: *id003
|
60
|
+
prerelease: false
|
61
|
+
name: hashie
|
62
|
+
type: :runtime
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirement: *id004
|
74
|
+
prerelease: false
|
75
|
+
name: omniauth
|
76
|
+
type: :runtime
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirement: *id005
|
88
|
+
prerelease: false
|
89
|
+
name: faraday
|
90
|
+
type: :runtime
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirement: *id006
|
102
|
+
prerelease: false
|
103
|
+
name: faraday_middleware
|
104
|
+
type: :runtime
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 2
|
114
|
+
- 3
|
115
|
+
- 0
|
116
|
+
version: 2.3.0
|
117
|
+
requirement: *id007
|
118
|
+
prerelease: false
|
119
|
+
name: rspec
|
120
|
+
type: :development
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ~>
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
hash: 23
|
128
|
+
segments:
|
129
|
+
- 1
|
130
|
+
- 0
|
131
|
+
- 0
|
132
|
+
version: 1.0.0
|
133
|
+
requirement: *id008
|
134
|
+
prerelease: false
|
135
|
+
name: bundler
|
136
|
+
type: :development
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ~>
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 7
|
144
|
+
segments:
|
145
|
+
- 1
|
146
|
+
- 5
|
147
|
+
- 2
|
148
|
+
version: 1.5.2
|
149
|
+
requirement: *id009
|
150
|
+
prerelease: false
|
151
|
+
name: jeweler
|
152
|
+
type: :development
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
hash: 3
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
version: "0"
|
163
|
+
requirement: *id010
|
164
|
+
prerelease: false
|
165
|
+
name: rcov
|
166
|
+
type: :development
|
167
|
+
description: Ruby Client for Salesforce Chatter REST API
|
168
|
+
email: dylancvaughn@gmail.com
|
169
|
+
executables: []
|
170
|
+
|
171
|
+
extensions: []
|
172
|
+
|
173
|
+
extra_rdoc_files:
|
174
|
+
- LICENSE.txt
|
175
|
+
- README.md
|
176
|
+
files:
|
177
|
+
- .document
|
178
|
+
- .rspec
|
179
|
+
- Gemfile
|
180
|
+
- Gemfile.lock
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- VERSION
|
185
|
+
- lib/faraday/request/multipart_with_file.rb
|
186
|
+
- lib/faraday/request/salesforce_oauth.rb
|
187
|
+
- lib/faraday/response/raise_http_4xx.rb
|
188
|
+
- lib/faraday/response/raise_http_5xx.rb
|
189
|
+
- lib/salesforce-chatter.rb
|
190
|
+
- lib/salesforce-chatter/api.rb
|
191
|
+
- lib/salesforce-chatter/authentication.rb
|
192
|
+
- lib/salesforce-chatter/client.rb
|
193
|
+
- lib/salesforce-chatter/client/feed_items.rb
|
194
|
+
- lib/salesforce-chatter/configuration.rb
|
195
|
+
- lib/salesforce-chatter/connection.rb
|
196
|
+
- lib/salesforce-chatter/request.rb
|
197
|
+
- lib/salesforce-chatter/version.rb
|
198
|
+
- spec/salesforce-chatter_spec.rb
|
199
|
+
- spec/spec_helper.rb
|
200
|
+
has_rdoc: true
|
201
|
+
homepage: http://github.com/dylanvaughn/salesforce-chatter
|
202
|
+
licenses:
|
203
|
+
- MIT
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
|
207
|
+
require_paths:
|
208
|
+
- lib
|
209
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
hash: 3
|
215
|
+
segments:
|
216
|
+
- 0
|
217
|
+
version: "0"
|
218
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
|
+
none: false
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
hash: 3
|
224
|
+
segments:
|
225
|
+
- 0
|
226
|
+
version: "0"
|
227
|
+
requirements: []
|
228
|
+
|
229
|
+
rubyforge_project:
|
230
|
+
rubygems_version: 1.3.9.2
|
231
|
+
signing_key:
|
232
|
+
specification_version: 3
|
233
|
+
summary: Ruby Client for Salesforce Chatter REST API
|
234
|
+
test_files:
|
235
|
+
- spec/salesforce-chatter_spec.rb
|
236
|
+
- spec/spec_helper.rb
|