Skip to content

Commit

Permalink
convert parameters to String before encoding them into multipart requ…
Browse files Browse the repository at this point in the history
…est.
  • Loading branch information
DenTelezhkin committed Apr 23, 2016
1 parent 25f26c5 commit d13beed
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/MultipartAPIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class MultipartAPIRequest<Model: ResponseParseable, ErrorModel: ResponseP

let multipartConstructionBlock: MultipartFormData -> 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) }
}
Expand Down
2 changes: 1 addition & 1 deletion TRON.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
32 changes: 32 additions & 0 deletions Tests/MultipartAPIRequestTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,36 @@ class MultipartAPIRequestTestCase: XCTestCase {

waitForExpectationsWithTimeout(10, handler: nil)
}

func testIntParametersAreAcceptedAsMultipartParameters() {
let request: MultipartAPIRequest<TestResponse,TronError> = 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<TestResponse,TronError> = 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)
}
}

0 comments on commit d13beed

Please sign in to comment.