Skip to content

Commit

Permalink
Renames HttpBodyConvertable to HttpBodyConvertible
Browse files Browse the repository at this point in the history
  • Loading branch information
s4cha committed Jul 29, 2020
1 parent 99d8118 commit 05f89f6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// HttpBodyConvertable.swift
// HttpBodyConvertible.swift
//
//
// Created by Jeff Barg on 07/22/2020.
//

import Foundation

public protocol HttpBodyConvertable {
public protocol HttpBodyConvertible {
func buildHttpBodyPart(boundary: String) -> Data
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// MultipartData+HttpBody.swift
// MultipartData+HttpBodyConvertible.swift
//
//
// Created by Sacha on 13/03/2020.
//

import Foundation

extension MultipartData: HttpBodyConvertable {
extension MultipartData: HttpBodyConvertible {
public func buildHttpBodyPart(boundary: String) -> Data {
let httpBody = NSMutableData()
httpBody.appendString("--\(boundary)\r\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
//
// Params+HttpBodyConvertable.swift
// Params+HttpBodyConvertible.swift
//
//
// Created by Jeff Barg on 07/22/2020.
//

import Foundation

extension Params: HttpBodyConvertable {
extension Params: HttpBodyConvertible {
public func buildHttpBodyPart(boundary: String) -> Data {
let httpBody = NSMutableData()

self.forEach { (name, value) in
forEach { (name, value) in
httpBody.appendString("--\(boundary)\r\n")
httpBody.appendString("Content-Disposition: form-data; name=\"\(name)\"\r\n\r\n")
httpBody.appendString(value.description)
httpBody.appendString("\r\n")
}

return httpBody as Data
}
}
4 changes: 2 additions & 2 deletions Sources/Networking/NetworkingRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ public class NetworkingRequest: NSObject {

private func buildMultipartHttpBody(params: Params, multiparts: [MultipartData], boundary: String) -> Data {
// Combine all multiparts together
let allMultiparts: [HttpBodyConvertable] = [params] + multiparts;
let allMultiparts: [HttpBodyConvertible] = [params] + multiparts;
let boundaryEnding = "--\(boundary)--".data(using: .utf8)!

// Convert multiparts to boundary-seperated Data and combine them
return allMultiparts
.map { (multipart: HttpBodyConvertable) -> Data in
.map { (multipart: HttpBodyConvertible) -> Data in
return multipart.buildHttpBodyPart(boundary: boundary)
}
.reduce(Data.init(), +)
Expand Down

0 comments on commit 05f89f6

Please sign in to comment.