lib/her/api.rb in her-1.0.1 vs lib/her/api.rb in her-1.0.2
- old
+ new
@@ -1,17 +1,18 @@
module Her
# This class is where all HTTP requests are made. Before using Her, you must configure it
# so it knows where to make those requests. In Rails, this is usually done in `config/initializers/her.rb`:
class API
+
# @private
attr_reader :connection, :options
# Constants
FARADAY_OPTIONS = [:request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class].freeze
# Setup a default API connection. Accepted arguments and options are the same as {API#setup}.
- def self.setup(opts={}, &block)
+ def self.setup(opts = {}, &block)
@default_api = new(opts, &block)
end
# Create a new API object. This is useful to create multiple APIs and use them with the `uses_api` method.
# If your application uses only one API, you should use Her::API.setup to configure the default API
@@ -66,15 +67,15 @@
# Her::API.setup :url => "https://api.example.com" do |connection|
# connection.use Faraday::Request::UrlEncoded
# connection.use MyCustomParser
# connection.use Faraday::Adapter::NetHttp
# end
- def setup(opts={}, &blk)
+ def setup(opts = {}, &blk)
opts[:url] = opts.delete(:base_uri) if opts.include?(:base_uri) # Support legacy :base_uri option
@options = opts
- faraday_options = @options.reject { |key, value| !FARADAY_OPTIONS.include?(key.to_sym) }
+ faraday_options = @options.select { |key, _| FARADAY_OPTIONS.include?(key.to_sym) }
@connection = Faraday.new(faraday_options) do |connection|
yield connection if block_given?
end
self
end
@@ -82,15 +83,15 @@
# Define a custom parsing procedure. The procedure is passed the response object and is
# expected to return a hash with three keys: a main data Hash, an errors Hash
# and a metadata Hash.
#
# @private
- def request(opts={})
+ def request(opts = {})
method = opts.delete(:_method)
path = opts.delete(:_path)
headers = opts.delete(:_headers)
- opts.delete_if { |key, value| key.to_s =~ /^_/ } # Remove all internal parameters
+ opts.delete_if { |key, _| key.to_s =~ /^_/ } # Remove all internal parameters
if method == :options
# Faraday doesn't support the OPTIONS verb because of a name collision with an internal options method
# so we need to call run_request directly.
request.headers.merge!(headers) if headers
response = @connection.run_request method, path, opts, headers
@@ -106,15 +107,15 @@
request.body = opts
end
end
end
{ :parsed_data => response.env[:body], :response => response }
-
end
private
+
# @private
- def self.default_api(opts={})
+ def self.default_api(opts = {})
defined?(@default_api) ? @default_api : nil
end
end
end