diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d79573c..27470e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +## [0.4.3](https://github.com/MLSDev/TRON/releases/tag/0.4.3) + +### Fixed + +* Allow `MultipartAPIRequest` to use any StringLiteralConvertible value in parameters (for example Int, or Bool e.t.c). + ## [0.4.2](https://github.com/MLSDev/TRON/releases/tag/0.4.2) ### Fixed diff --git a/Source/Core/MultipartAPIRequest.swift b/Source/Core/MultipartAPIRequest.swift index ba580018..6640a067 100644 --- a/Source/Core/MultipartAPIRequest.swift +++ b/Source/Core/MultipartAPIRequest.swift @@ -94,7 +94,7 @@ public class MultipartAPIRequest Void = { formData in self.parameters.forEach { (key,value) in - formData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding) ?? NSData(), name: key) + formData.appendBodyPart(data: String(value).dataUsingEncoding(NSUTF8StringEncoding) ?? NSData(), name: key) } self.multipartParameters.forEach { $0(formData) } } diff --git a/TRON.podspec b/TRON.podspec index f7705e98..72abca26 100644 --- a/TRON.podspec +++ b/TRON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TRON' - s.version = '0.4.2' + s.version = '0.4.3' s.license = 'MIT' s.summary = 'Lightweight network abstraction layer, written on top of Alamofire' s.homepage = 'https://github.com/MLSDev/TRON' diff --git a/Tests/MultipartAPIRequestTestCase.swift b/Tests/MultipartAPIRequestTestCase.swift index 79d92e75..963760f1 100644 --- a/Tests/MultipartAPIRequestTestCase.swift +++ b/Tests/MultipartAPIRequestTestCase.swift @@ -73,4 +73,36 @@ class MultipartAPIRequestTestCase: XCTestCase { waitForExpectationsWithTimeout(10, handler: nil) } + + func testIntParametersAreAcceptedAsMultipartParameters() { + let request: MultipartAPIRequest = tron.multipartRequest(path: "post") + request.method = .POST + request.parameters = ["foo":1] + + let expectation = expectationWithDescription("Int expectation") + _ = request.rxUpload().result.subscribeNext { result in + if let dictionary = result.response["form"] as? [String:String] { + if dictionary["foo"] == "1" { + expectation.fulfill() + } + } + } + waitForExpectationsWithTimeout(10, handler: nil) + } + + func testBoolParametersAreAcceptedAsMultipartParameters() { + let request: MultipartAPIRequest = tron.multipartRequest(path: "post") + request.method = .POST + request.parameters = ["foo":true] + + let expectation = expectationWithDescription("Int expectation") + _ = request.rxUpload().result.subscribeNext { result in + if let dictionary = result.response["form"] as? [String:String] { + if dictionary["foo"] == "1" { + expectation.fulfill() + } + } + } + waitForExpectationsWithTimeout(10, handler: nil) + } }