lib/afmotion/session_client.rb in afmotion-2.0.0.rc1 vs lib/afmotion/session_client.rb in afmotion-2.0.0.rc2

- old
+ new

@@ -123,6 +123,28 @@ # EX client.get('my/resource.json') define_method "#{method}", -> (path, parameters = {}, &callback) do create_task(method, path, parameters, &callback) end end + + # options = {parameters: , constructingBodyWithBlock: , success:, failure:} + def PUT(url_string, options = {}) + parameters = options[:parameters] + block = options[:constructingBodyWithBlock] + success = options[:success] + failure = options[:failure] + + request = self.requestSerializer.multipartFormRequestWithMethod("PUT", URLString: NSURL.URLWithString(url_string, relativeToURL: self.baseURL).absoluteString, parameters:parameters, constructingBodyWithBlock:block) + + task = self.dataTaskWithRequest(request, completionHandler: ->(response, responseObject, error) { + if error && failure + failure.call(task, error) + elsif success + success.call(task, responseObject) + end + }) + + task.resume + + task + end end \ No newline at end of file