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.

@@ -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 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
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 Restforce::Middleware::Caching, cache, @options if cache
365
- builder.use FaradayMiddleware::FollowRedirects
366
- builder.use Restforce::Middleware::Logger, Restforce.configuration.logger, @options if Restforce.log?
367
- builder.adapter Faraday.default_adapter
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(env)
7
+ raise Faraday::Error::ResourceNotFound, message
7
8
  when 401
8
- raise Restforce::UnauthorizedError, message(env)
9
+ raise Restforce::UnauthorizedError, message
9
10
  when 400...600
10
- raise Faraday::Error::ClientError, message(env)
11
+ raise Faraday::Error::ClientError, message
11
12
  end
12
13
  end
13
14
 
14
- def message(env)
15
- "#{env[:body].first['errorCode']}: #{env[:body].first['message']}"
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
@@ -1,3 +1,3 @@
1
1
  module Restforce
2
- VERSION = "0.1.2"
2
+ VERSION = '0.1.3'
3
3
  end
@@ -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
- @requests = [].tap do |requests|
435
- requests << stub_request(:get, /query\?q=SELECT%20some,%20fields%20FROM%20object/)
436
- .with(headers: { 'Authorization' => "OAuth #{oauth_token}" })
437
- .to_return(status: 401, body: fixture('expired_session_response'))
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
- requests << stub_request(:post, "https://login.salesforce.com/services/oauth2/token")
440
- .with(:body => "grant_type=password&client_id=client_id&client_secret=" \
441
- "client_secret&username=foo&password=barsecurity_token")
442
- .to_return(status: 200, body: fixture(:auth_success_response))
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
- @requests.each { |request| request.should have_been_requested }
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) { JSON.parse(fixture('sobject/query_error_response')) }
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: