Method: ApiResource::Mocks::MockRequest#initialize
- Defined in:
- lib/api_resource/mocks.rb
#initialize(method, path, opts = {}) ⇒ MockRequest
Returns a new instance of MockRequest.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/api_resource/mocks.rb', line 164 def initialize(method, path, opts = {}) @method = method.to_sym # set the normalized path, format and query string @path, @query = path.split("?") @path, @format = @path.split(".") # if we have params, it is a MockRequest definition if opts[:params] @params = sorted_params(URI.decode(opts[:params].to_query)) # otherwise, we need to check either the query string or the body # depending on the http verb else case @method when :post, :put @params = sorted_params(JSON.parse((opts[:body] || "")).to_query) when :get, :delete, :head @params = sorted_params(@query || "") end end @body = opts[:body] @headers = opts[:headers] || {} @headers["Content-Length"] = @body.blank? ? "0" : @body.size.to_s end |