Class: Restforce::Middleware::InstanceURL
- Inherits:
-
Restforce::Middleware
- Object
- Faraday::Middleware
- Restforce::Middleware
- Restforce::Middleware::InstanceURL
- Defined in:
- lib/restforce/middleware/instance_url.rb
Overview
Middleware which asserts that the instance_url is always set
Instance Method Summary collapse
Methods inherited from Restforce::Middleware
#client, #connection, #initialize
Constructor Details
This class inherits a constructor from Restforce::Middleware
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/restforce/middleware/instance_url.rb', line 6 def call(env) # If the instance url isn't set in options, raise a # Restforce::UnauthorizedError to trigger reauthentication. raise Restforce::UnauthorizedError, 'instance url not set' unless @options[:instance_url] # If the url_prefix for the connection doesn't match the instance_url # set in the options, we raise an error which gets caught outside of # middleware, where the url_prefix is then set before retrying the # request. It would be ideal if this could all be handled in # middleware... raise Restforce::InstanceURLError unless connection.url_prefix == instance_url @app.call(env) end |
#instance_url ⇒ Object
21 22 23 |
# File 'lib/restforce/middleware/instance_url.rb', line 21 def instance_url URI.parse(@options[:instance_url]) end |