restforce 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of restforce might be problematic. Click here for more details.
- data/lib/restforce/client.rb +11 -11
- data/lib/restforce/middleware/raise_error.rb +10 -5
- data/lib/restforce/version.rb +1 -1
- data/spec/lib/client_spec.rb +10 -15
- data/spec/lib/middleware/raise_error_spec.rb +1 -1
- metadata +1 -1
data/lib/restforce/client.rb
CHANGED
@@ -353,18 +353,18 @@ module Restforce
|
|
353
353
|
# Internal: Internal faraday connection where all requests go through
|
354
354
|
def connection
|
355
355
|
@connection ||= Faraday.new(@options[:instance_url]) do |builder|
|
356
|
-
builder.use
|
357
|
-
builder.use
|
358
|
-
builder.request
|
359
|
-
builder.use
|
360
|
-
builder.use
|
361
|
-
builder.use
|
362
|
-
builder.use Restforce::Middleware::RaiseError
|
356
|
+
builder.use Restforce::Middleware::Mashify, self, @options
|
357
|
+
builder.use Restforce::Middleware::Multipart
|
358
|
+
builder.request :json
|
359
|
+
builder.use authentication_middleware, self, @options if authentication_middleware
|
360
|
+
builder.use Restforce::Middleware::Authorization, self, @options
|
361
|
+
builder.use Restforce::Middleware::InstanceURL, self, @options
|
363
362
|
builder.response :json
|
364
|
-
builder.use
|
365
|
-
builder.use
|
366
|
-
builder.use
|
367
|
-
builder.
|
363
|
+
builder.use Restforce::Middleware::Caching, cache, @options if cache
|
364
|
+
builder.use FaradayMiddleware::FollowRedirects
|
365
|
+
builder.use Restforce::Middleware::RaiseError
|
366
|
+
builder.use Restforce::Middleware::Logger, Restforce.configuration.logger, @options if Restforce.log?
|
367
|
+
builder.adapter Faraday.default_adapter
|
368
368
|
end
|
369
369
|
@connection
|
370
370
|
end
|
@@ -1,18 +1,23 @@
|
|
1
1
|
module Restforce
|
2
2
|
class Middleware::RaiseError < Faraday::Response::Middleware
|
3
3
|
def on_complete(env)
|
4
|
+
@env = env
|
4
5
|
case env[:status]
|
5
6
|
when 404
|
6
|
-
raise Faraday::Error::ResourceNotFound, message
|
7
|
+
raise Faraday::Error::ResourceNotFound, message
|
7
8
|
when 401
|
8
|
-
raise Restforce::UnauthorizedError, message
|
9
|
+
raise Restforce::UnauthorizedError, message
|
9
10
|
when 400...600
|
10
|
-
raise Faraday::Error::ClientError, message
|
11
|
+
raise Faraday::Error::ClientError, message
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
def message
|
15
|
-
"#{
|
15
|
+
def message
|
16
|
+
"#{body.first['errorCode']}: #{body.first['message']}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
@body ||= JSON.parse(@env[:body])
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/restforce/version.rb
CHANGED
data/spec/lib/client_spec.rb
CHANGED
@@ -428,27 +428,22 @@ shared_examples_for 'methods' do
|
|
428
428
|
end
|
429
429
|
|
430
430
|
let(:cache) { MockCache.new }
|
431
|
-
let(:oauth_token) { 'foobar' }
|
432
431
|
|
433
432
|
before do
|
434
|
-
@
|
435
|
-
|
436
|
-
|
437
|
-
|
433
|
+
@query = stub_request(:get, /query\?q=SELECT%20some,%20fields%20FROM%20object/)
|
434
|
+
.with(headers: { 'Authorization' => "OAuth #{oauth_token}" })
|
435
|
+
.to_return(status: 401, body: fixture('expired_session_response')).then
|
436
|
+
.to_return(status: 200, body: fixture('sobject/query_success_response'))
|
438
437
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
requests << stub_request(:get, /query\?q=SELECT%20some,%20fields%20FROM%20object/)
|
445
|
-
.with(headers: { 'Authorization' => "OAuth 00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW19ye6PE3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs" })
|
446
|
-
.to_return(status: 200, body: fixture('sobject/query_success_response'))
|
447
|
-
end
|
438
|
+
@login = stub_request(:post, "https://login.salesforce.com/services/oauth2/token")
|
439
|
+
.with(:body => "grant_type=password&client_id=client_id&client_secret=" \
|
440
|
+
"client_secret&username=foo&password=barsecurity_token")
|
441
|
+
.to_return(status: 200, body: fixture(:auth_success_response))
|
448
442
|
end
|
449
443
|
|
450
444
|
after do
|
451
|
-
@
|
445
|
+
@query.should have_been_made.times(2)
|
446
|
+
@login.should have_been_made
|
452
447
|
end
|
453
448
|
|
454
449
|
subject { client.query('SELECT some, fields FROM object') }
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Restforce::Middleware::RaiseError do
|
4
4
|
let(:app) { double('app') }
|
5
|
-
let(:body) {
|
5
|
+
let(:body) { fixture('sobject/query_error_response') }
|
6
6
|
let(:env) { { status: status, body: body } }
|
7
7
|
let(:middleware) { described_class.new app }
|
8
8
|
|