databasedotcom_additions 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/databasedotcom_additions/client.rb +95 -0
- data/lib/databasedotcom_additions/persistent_hash.rb +35 -0
- data/lib/databasedotcom_additions/proxy_patch.rb +29 -0
- data/lib/databasedotcom_additions/rforce_proxy_patch.rb +33 -0
- data/lib/databasedotcom_additions/set_proxy_if_needed.rb +14 -0
- data/lib/databasedotcom_additions.rb +1 -0
- metadata +82 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rforce'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'rforce_proxy_patch'
|
4
|
+
require 'proxy_patch'
|
5
|
+
require 'persistent_hash'
|
6
|
+
|
7
|
+
module Databasedotcom
|
8
|
+
class Client
|
9
|
+
|
10
|
+
attr_accessor :query_result_cache_enabled
|
11
|
+
attr_accessor :login_failed_user_message
|
12
|
+
|
13
|
+
alias_method :query_orig, :query
|
14
|
+
|
15
|
+
# opt username, password, sandbox
|
16
|
+
def self.username_password_login(opt)
|
17
|
+
client = Databasedotcom::Client.new :verify_mode => OpenSSL::SSL::VERIFY_NONE
|
18
|
+
client.host = opt[:sandbox] ? "test.salesforce.com" : "login.salesforce.com"
|
19
|
+
begin
|
20
|
+
binding = RForce::Binding.new("https://#{client.host}/services/Soap/u/20.0", nil)
|
21
|
+
response = binding.login(opt[:username], opt[:password])
|
22
|
+
token = response.loginResponse.result.sessionId
|
23
|
+
serverUrl = response.loginResponse.result.serverUrl
|
24
|
+
uri = URI(serverUrl)
|
25
|
+
client.username = opt[:username]
|
26
|
+
client.password = opt[:password]
|
27
|
+
client.version = '22.0'
|
28
|
+
client.oauth_token = token
|
29
|
+
client.instance_url = "#{uri.scheme}://#{uri.host}"
|
30
|
+
rescue => e
|
31
|
+
client.login_failed_user_message = e.message
|
32
|
+
end
|
33
|
+
client
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache
|
37
|
+
|
38
|
+
if ! defined?(@global_cache)
|
39
|
+
cache_file_name = 'cache/global-cache.json'
|
40
|
+
@global_cache ||= UtilityPack::PersistentHash.new cache_file_name
|
41
|
+
end
|
42
|
+
|
43
|
+
@global_cache
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# support for count query - SELECT COUNT() FROM Account_vod__c
|
48
|
+
def count(soql_expr)
|
49
|
+
result = http_get("/services/data/v#{self.version}/query", :q => soql_expr)
|
50
|
+
JSON.parse(result.body)['totalSize']
|
51
|
+
end
|
52
|
+
|
53
|
+
def query(soql)
|
54
|
+
resp = query_orig(soql)
|
55
|
+
resp
|
56
|
+
end
|
57
|
+
|
58
|
+
def query_raw(soql)
|
59
|
+
|
60
|
+
if query_result_cache_enabled
|
61
|
+
cache_key = "#{self.username}:#{soql}"
|
62
|
+
if cache[cache_key]
|
63
|
+
puts "cache get - #{cache_key}"
|
64
|
+
return cache[cache_key]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
result = http_get("/services/data/v#{self.version}/query", :q => soql)
|
70
|
+
resp = JSON.parse(result.body)
|
71
|
+
|
72
|
+
if query_result_cache_enabled
|
73
|
+
puts "cache put - #{cache_key}"
|
74
|
+
cache[cache_key] = resp
|
75
|
+
end
|
76
|
+
resp
|
77
|
+
end
|
78
|
+
|
79
|
+
def next_page_raw(path)
|
80
|
+
result = http_get(path)
|
81
|
+
JSON.parse(result.body)
|
82
|
+
end
|
83
|
+
|
84
|
+
def query_all(soql_expr)
|
85
|
+
all_records = []
|
86
|
+
records = query(soql_expr)
|
87
|
+
while records.total_size > 0
|
88
|
+
all_records.concat(records)
|
89
|
+
records = records.next_page
|
90
|
+
end
|
91
|
+
all_records
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module UtilityPack
|
5
|
+
|
6
|
+
class PersistentHash
|
7
|
+
def initialize path
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def json_parse_file(path)
|
12
|
+
JSON.parse(File.open(path).read)
|
13
|
+
end
|
14
|
+
|
15
|
+
def load
|
16
|
+
File.exists?(@path) ? json_parse_file(@path) : {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def save h
|
20
|
+
File.open(@path, 'w') {|f| f.write(h.to_json)}
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](key)
|
24
|
+
load[key]
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(key, value)
|
28
|
+
h = load
|
29
|
+
h[key] = value
|
30
|
+
save(h)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'databasedotcom'
|
2
|
+
require 'set_proxy_if_needed'
|
3
|
+
|
4
|
+
# patch for using a proxy
|
5
|
+
module Databasedotcom
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def proxy
|
9
|
+
http_proxy = ENV["http_proxy"]
|
10
|
+
URI.parse(http_proxy) rescue nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def https_request(host=nil)
|
14
|
+
|
15
|
+
if proxy
|
16
|
+
http = Net::HTTP::Proxy(proxy.host, proxy.port).new(host || URI.parse(self.instance_url).host, 443)
|
17
|
+
else
|
18
|
+
http = Net::HTTP.new(host || URI.parse(self.instance_url).host, 443)
|
19
|
+
end
|
20
|
+
|
21
|
+
http.tap do |http|
|
22
|
+
http.use_ssl = true
|
23
|
+
http.ca_file = self.ca_file if self.ca_file
|
24
|
+
http.verify_mode = self.verify_mode if self.verify_mode
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rforce'
|
3
|
+
require 'set_proxy_if_needed'
|
4
|
+
|
5
|
+
module RForce
|
6
|
+
|
7
|
+
class Binding
|
8
|
+
|
9
|
+
def init_server(url)
|
10
|
+
@url = URI.parse(url)
|
11
|
+
|
12
|
+
if proxy
|
13
|
+
@server = Net::HTTP::Proxy(proxy.host, proxy.port).new(@url.host, 443)
|
14
|
+
else
|
15
|
+
@server = Net::HTTP.new(@url.host, 443)
|
16
|
+
end
|
17
|
+
|
18
|
+
#@server = Net::HTTP.new(@url.host, @url.port)
|
19
|
+
@server.use_ssl = @url.scheme == 'https'
|
20
|
+
@server.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
+
|
22
|
+
# run ruby with -d or env variable SHOWSOAP=true to see SOAP wiredumps.
|
23
|
+
@server.set_debug_output $stderr if show_debug
|
24
|
+
end
|
25
|
+
|
26
|
+
def proxy
|
27
|
+
http_proxy = ENV['http_proxy']
|
28
|
+
URI.parse(http_proxy) rescue nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
def on_work_network
|
2
|
+
if RUBY_PLATFORM =~ /32/ # windows
|
3
|
+
%x{ipconfig /all}.split.grep(/54\./).count > 0
|
4
|
+
else
|
5
|
+
%x{ifconfig | grep -i "inet 54." > /dev/null}
|
6
|
+
$? == 0
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if on_work_network
|
11
|
+
ENV["http_proxy"] = "http://webproxy.merck.com:8080"
|
12
|
+
else
|
13
|
+
ENV.delete("http_proxy")
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'databasedotcom_additions/client.rb'
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: databasedotcom_additions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Pfeil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: databasedotcom
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rforce
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: databasedotcom additions
|
47
|
+
email: brian.pfeil@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/databasedotcom_additions/client.rb
|
53
|
+
- lib/databasedotcom_additions/persistent_hash.rb
|
54
|
+
- lib/databasedotcom_additions/proxy_patch.rb
|
55
|
+
- lib/databasedotcom_additions/rforce_proxy_patch.rb
|
56
|
+
- lib/databasedotcom_additions/set_proxy_if_needed.rb
|
57
|
+
- lib/databasedotcom_additions.rb
|
58
|
+
homepage: http://rubygems.org/gems/databasedotcom_additions
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.24
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: databasedotcom additions
|
82
|
+
test_files: []
|