lib/faraday/request.rb in faraday-1.0.1 vs lib/faraday/request.rb in faraday-1.1.0

- old
+ new

@@ -10,11 +10,11 @@ # req.params['c'] = '3' # GET Param # req['b'] = '2' # also Header # req.body = 'abc' # end # - # @!attribute method + # @!attribute http_method # @return [Symbol] the HTTP method of the Request # @!attribute path # @return [URI, String] the path # @!attribute params # @return [Hash] query parameters @@ -24,11 +24,13 @@ # @return [Hash] body # @!attribute options # @return [RequestOptions] options # # rubocop:disable Style/StructInheritance - class Request < Struct.new(:method, :path, :params, :headers, :body, :options) + class Request < Struct.new( + :http_method, :path, :params, :headers, :body, :options + ) # rubocop:enable Style/StructInheritance extend MiddlewareRegistry register_middleware File.expand_path('request', __dir__), @@ -54,10 +56,18 @@ new(request_method).tap do |request| yield(request) if block_given? end end + def method + warn <<~TEXT + WARNING: `Faraday::Request##{__method__}` is deprecated; use `#http_method` instead. It will be removed in or after version 2.0. + `Faraday::Request##{__method__}` called from #{caller_locations(1..1).first} + TEXT + http_method + end + # Replace params, preserving the existing hash type. # # @param hash [Hash] new params def params=(hash) if params @@ -114,11 +124,11 @@ # Marshal serialization support. # # @return [Hash] the hash ready to be serialized in Marshal. def marshal_dump { - method: method, + http_method: http_method, body: body, headers: headers, path: path, params: params, options: options @@ -127,20 +137,20 @@ # Marshal serialization support. # Restores the instance variables according to the +serialised+. # @param serialised [Hash] the serialised object. def marshal_load(serialised) - self.method = serialised[:method] - self.body = serialised[:body] - self.headers = serialised[:headers] - self.path = serialised[:path] - self.params = serialised[:params] - self.options = serialised[:options] + self.http_method = serialised[:http_method] + self.body = serialised[:body] + self.headers = serialised[:headers] + self.path = serialised[:path] + self.params = serialised[:params] + self.options = serialised[:options] end # @return [Env] the Env for this Request def to_env(connection) - Env.new(method, body, connection.build_exclusive_url(path, params), + Env.new(http_method, body, connection.build_exclusive_url(path, params), options, headers, connection.ssl, connection.parallel_manager) end end end