diff --git a/faraday.gemspec b/faraday.gemspec index 66e45ed84..429cf445b 100644 --- a/faraday.gemspec +++ b/faraday.gemspec @@ -1,13 +1,10 @@ # frozen_string_literal: true -lib = 'faraday' -lib_file = File.expand_path("../lib/#{lib}.rb", __FILE__) -File.read(lib_file) =~ /\bVERSION\s*=\s*["'](.+?)["']/ -version = Regexp.last_match(1) +require_relative 'lib/faraday/version' Gem::Specification.new do |spec| - spec.name = lib - spec.version = version + spec.name = 'faraday' + spec.version = Faraday::VERSION spec.summary = 'HTTP/REST API client library.' diff --git a/lib/faraday.rb b/lib/faraday.rb index 378194797..d7b4b1bc1 100644 --- a/lib/faraday.rb +++ b/lib/faraday.rb @@ -7,6 +7,26 @@ require 'faraday/middleware_registry' require 'faraday/dependency_loader' +unless defined?(::Faraday::Timer) + require 'timeout' + Timer = Timeout +end + +require 'faraday/version' +require 'faraday/methods' +require 'faraday/utils' +require 'faraday/options' +require 'faraday/connection' +require 'faraday/rack_builder' +require 'faraday/parameters' +require 'faraday/middleware' +require 'faraday/adapter' +require 'faraday/request' +require 'faraday/response' +require 'faraday/error' +require 'faraday/file_part' +require 'faraday/param_part' + # This is the main namespace for Faraday. # # It provides methods to create {Connection} objects, and HTTP-related @@ -20,10 +40,6 @@ # conn.get '/' # module Faraday - VERSION = '1.1.0' - METHODS_WITH_QUERY = %w[get head delete trace].freeze - METHODS_WITH_BODY = %w[post put patch].freeze - class << self # The root path that Faraday is being loaded from. # @@ -108,6 +124,34 @@ def respond_to_missing?(symbol, include_private = false) default_connection.respond_to?(symbol, include_private) || super end + # @overload default_connection + # Gets the default connection used for simple scripts. + # @return [Faraday::Connection] a connection configured with + # the default_adapter. + # @overload default_connection=(connection) + # @param connection [Faraday::Connection] + # Sets the default {Faraday::Connection} for simple scripts that + # access the Faraday constant directly, such as + # Faraday.get "https://faraday.com". + def default_connection + @default_connection ||= Connection.new(default_connection_options) + end + + # Gets the default connection options used when calling {Faraday#new}. + # + # @return [Faraday::ConnectionOptions] + def default_connection_options + @default_connection_options ||= ConnectionOptions.new + end + + # Sets the default options used when calling {Faraday#new}. + # + # @param options [Hash, Faraday::ConnectionOptions] + def default_connection_options=(options) + @default_connection = nil + @default_connection_options = ConnectionOptions.from(options) + end + private # Internal: Proxies method calls on the Faraday constant to @@ -126,42 +170,5 @@ def method_missing(name, *args, &block) self.lib_path = File.expand_path 'faraday', __dir__ self.default_adapter = :net_http - # @overload default_connection - # Gets the default connection used for simple scripts. - # @return [Faraday::Connection] a connection configured with - # the default_adapter. - # @overload default_connection=(connection) - # @param connection [Faraday::Connection] - # Sets the default {Faraday::Connection} for simple scripts that - # access the Faraday constant directly, such as - # Faraday.get "https://faraday.com". - def self.default_connection - @default_connection ||= Connection.new(default_connection_options) - end - - # Gets the default connection options used when calling {Faraday#new}. - # - # @return [Faraday::ConnectionOptions] - def self.default_connection_options - @default_connection_options ||= ConnectionOptions.new - end - - # Sets the default options used when calling {Faraday#new}. - # - # @param options [Hash, Faraday::ConnectionOptions] - def self.default_connection_options=(options) - @default_connection = nil - @default_connection_options = ConnectionOptions.from(options) - end - - unless defined?(::Faraday::Timer) - require 'timeout' - Timer = Timeout - end - - require_libs 'utils', 'options', 'connection', 'rack_builder', 'parameters', - 'middleware', 'adapter', 'request', 'response', 'error', - 'file_part', 'param_part' - require_lib 'autoload' unless ENV['FARADAY_NO_AUTOLOAD'] end diff --git a/lib/faraday/methods.rb b/lib/faraday/methods.rb new file mode 100644 index 000000000..53e390379 --- /dev/null +++ b/lib/faraday/methods.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Faraday + METHODS_WITH_QUERY = %w[get head delete trace].freeze + METHODS_WITH_BODY = %w[post put patch].freeze +end diff --git a/lib/faraday/version.rb b/lib/faraday/version.rb new file mode 100644 index 000000000..074cff54f --- /dev/null +++ b/lib/faraday/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Faraday + VERSION = '1.1.0' +end