databasedotcom 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/databasedotcom/client.rb +30 -27
- data/lib/databasedotcom/version.rb +1 -1
- metadata +2 -2
@@ -310,51 +310,53 @@ module Databasedotcom
|
|
310
310
|
|
311
311
|
private
|
312
312
|
|
313
|
-
def with_encoded_path_and_checked_response(path, parameters,
|
314
|
-
ensure_expected_response(
|
315
|
-
with_logging(encode_path_with_params(path, parameters),
|
313
|
+
def with_encoded_path_and_checked_response(path, parameters, options = {})
|
314
|
+
ensure_expected_response(options[:expected_result_class]) do
|
315
|
+
with_logging(encode_path_with_params(path, parameters), options) do |encoded_path|
|
316
316
|
yield(encoded_path)
|
317
317
|
end
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
321
|
-
def with_logging(encoded_path,
|
322
|
-
log_request(encoded_path,
|
321
|
+
def with_logging(encoded_path, options)
|
322
|
+
log_request(encoded_path, options)
|
323
323
|
response = yield encoded_path
|
324
324
|
log_response(response)
|
325
325
|
response
|
326
326
|
end
|
327
327
|
|
328
328
|
def ensure_expected_response(expected_result_class)
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
response
|
329
|
+
response = yield
|
330
|
+
|
331
|
+
unless response.is_a?(expected_result_class || Net::HTTPSuccess)
|
332
|
+
if response.is_a?(Net::HTTPUnauthorized)
|
333
|
+
if self.refresh_token
|
334
|
+
response = with_encoded_path_and_checked_response("/services/oauth2/token", { :grant_type => "refresh_token", :refresh_token => self.refresh_token, :client_id => self.client_id, :client_secret => self.client_secret}, :host => self.host) do |encoded_path|
|
335
|
+
response = https_request(self.host).post(encoded_path, nil)
|
336
|
+
if response.is_a?(Net::HTTPOK)
|
337
|
+
parse_auth_response(response.body)
|
339
338
|
end
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
response
|
339
|
+
response
|
340
|
+
end
|
341
|
+
elsif self.username && self.password
|
342
|
+
response = with_encoded_path_and_checked_response("/services/oauth2/token", { :grant_type => "password", :username => self.username, :password => self.password, :client_id => self.client_id, :client_secret => self.client_secret}, :host => self.host) do |encoded_path|
|
343
|
+
response = https_request(self.host).post(encoded_path, nil)
|
344
|
+
if response.is_a?(Net::HTTPOK)
|
345
|
+
parse_auth_response(response.body)
|
347
346
|
end
|
347
|
+
response
|
348
348
|
end
|
349
|
+
end
|
349
350
|
|
350
|
-
|
351
|
-
|
352
|
-
end
|
351
|
+
if response.is_a?(Net::HTTPSuccess)
|
352
|
+
response = yield
|
353
353
|
end
|
354
354
|
end
|
355
355
|
|
356
356
|
raise SalesForceError.new(response) unless response.is_a?(expected_result_class || Net::HTTPSuccess)
|
357
357
|
end
|
358
|
+
|
359
|
+
response
|
358
360
|
end
|
359
361
|
|
360
362
|
def https_request(host=nil)
|
@@ -369,8 +371,9 @@ module Databasedotcom
|
|
369
371
|
(parameters || {}).collect { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join('&')
|
370
372
|
end
|
371
373
|
|
372
|
-
def log_request(path,
|
373
|
-
|
374
|
+
def log_request(path, options={})
|
375
|
+
base_url = options[:host] ? "https://#{options[:host]}" : self.instance_url
|
376
|
+
puts "***** REQUEST: #{path.include?(':') ? path : URI.join(base_url, path)}#{options[:data] ? " => #{options[:data]}" : ''}" if self.debugging
|
374
377
|
end
|
375
378
|
|
376
379
|
def log_response(result)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: databasedotcom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Glenn Gillen, Danny Burkes & Richard Zhao
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-23 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multipart-post
|