Skip to content

Commit d13beed

Browse files
committed
convert parameters to String before encoding them into multipart request.
1 parent 25f26c5 commit d13beed

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [0.4.3](https://github.com/MLSDev/TRON/releases/tag/0.4.3)
5+
6+
### Fixed
7+
8+
* Allow `MultipartAPIRequest` to use any StringLiteralConvertible value in parameters (for example Int, or Bool e.t.c).
9+
410
## [0.4.2](https://github.com/MLSDev/TRON/releases/tag/0.4.2)
511

612
### Fixed

Source/Core/MultipartAPIRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class MultipartAPIRequest<Model: ResponseParseable, ErrorModel: ResponseP
9494

9595
let multipartConstructionBlock: MultipartFormData -> Void = { formData in
9696
self.parameters.forEach { (key,value) in
97-
formData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding) ?? NSData(), name: key)
97+
formData.appendBodyPart(data: String(value).dataUsingEncoding(NSUTF8StringEncoding) ?? NSData(), name: key)
9898
}
9999
self.multipartParameters.forEach { $0(formData) }
100100
}

TRON.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TRON'
3-
s.version = '0.4.2'
3+
s.version = '0.4.3'
44
s.license = 'MIT'
55
s.summary = 'Lightweight network abstraction layer, written on top of Alamofire'
66
s.homepage = 'https://github.com/MLSDev/TRON'

Tests/MultipartAPIRequestTestCase.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,36 @@ class MultipartAPIRequestTestCase: XCTestCase {
7373

7474
waitForExpectationsWithTimeout(10, handler: nil)
7575
}
76+
77+
func testIntParametersAreAcceptedAsMultipartParameters() {
78+
let request: MultipartAPIRequest<TestResponse,TronError> = tron.multipartRequest(path: "post")
79+
request.method = .POST
80+
request.parameters = ["foo":1]
81+
82+
let expectation = expectationWithDescription("Int expectation")
83+
_ = request.rxUpload().result.subscribeNext { result in
84+
if let dictionary = result.response["form"] as? [String:String] {
85+
if dictionary["foo"] == "1" {
86+
expectation.fulfill()
87+
}
88+
}
89+
}
90+
waitForExpectationsWithTimeout(10, handler: nil)
91+
}
92+
93+
func testBoolParametersAreAcceptedAsMultipartParameters() {
94+
let request: MultipartAPIRequest<TestResponse,TronError> = tron.multipartRequest(path: "post")
95+
request.method = .POST
96+
request.parameters = ["foo":true]
97+
98+
let expectation = expectationWithDescription("Int expectation")
99+
_ = request.rxUpload().result.subscribeNext { result in
100+
if let dictionary = result.response["form"] as? [String:String] {
101+
if dictionary["foo"] == "1" {
102+
expectation.fulfill()
103+
}
104+
}
105+
}
106+
waitForExpectationsWithTimeout(10, handler: nil)
107+
}
76108
}

0 commit comments

Comments
 (0)