Skip to content

[Swift 4] Add createURLRequest method #1727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-date what about adding a 1-liner explaining what this function does?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 Thanks! Added

let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4-SNAPSHOT
4.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import Foundation
public struct ApiResponse: Codable {

public var code: Int?
public var codeNum: NSNumber? {
get {
return code.map({ return NSNumber(value: $0) })
}
}
public var type: String?
public var message: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import Foundation
public struct Category: Codable {

public var _id: Int64?
public var _idNum: NSNumber? {
get {
return _id.map({ return NSNumber(value: $0) })
}
}
public var name: String = "default-name"

public init(_id: Int64?, name: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,11 @@ import Foundation
public struct FormatTest: Codable {

public var integer: Int?
public var integerNum: NSNumber? {
get {
return integer.map({ return NSNumber(value: $0) })
}
}
public var int32: Int?
public var int32Num: NSNumber? {
get {
return int32.map({ return NSNumber(value: $0) })
}
}
public var int64: Int64?
public var int64Num: NSNumber? {
get {
return int64.map({ return NSNumber(value: $0) })
}
}
public var number: Double
public var numberNum: NSNumber? {
get {
return number.map({ return NSNumber(value: $0) })
}
}
public var float: Float?
public var floatNum: NSNumber? {
get {
return float.map({ return NSNumber(value: $0) })
}
}
public var double: Double?
public var doubleNum: NSNumber? {
get {
return double.map({ return NSNumber(value: $0) })
}
}
public var string: String?
public var byte: Data
public var binary: URL?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import Foundation
public struct Model200Response: Codable {

public var name: Int?
public var nameNum: NSNumber? {
get {
return name.map({ return NSNumber(value: $0) })
}
}
public var _class: String?

public init(name: Int?, _class: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ import Foundation
public struct Name: Codable {

public var name: Int
public var nameNum: NSNumber? {
get {
return name.map({ return NSNumber(value: $0) })
}
}
public var snakeCase: Int?
public var snakeCaseNum: NSNumber? {
get {
return snakeCase.map({ return NSNumber(value: $0) })
}
}
public var property: String?
public var _123number: Int?
public var _123numberNum: NSNumber? {
get {
return _123number.map({ return NSNumber(value: $0) })
}
}

public init(name: Int, snakeCase: Int?, property: String?, _123number: Int?) {
self.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import Foundation
public struct NumberOnly: Codable {

public var justNumber: Double?
public var justNumberNum: NSNumber? {
get {
return justNumber.map({ return NSNumber(value: $0) })
}
}

public init(justNumber: Double?) {
self.justNumber = justNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,12 @@ public struct Order: Codable {
case delivered = "delivered"
}
public var _id: Int64?
public var _idNum: NSNumber? {
get {
return _id.map({ return NSNumber(value: $0) })
}
}
public var petId: Int64?
public var petIdNum: NSNumber? {
get {
return petId.map({ return NSNumber(value: $0) })
}
}
public var quantity: Int?
public var quantityNum: NSNumber? {
get {
return quantity.map({ return NSNumber(value: $0) })
}
}
public var shipDate: Date?
/** Order Status */
public var status: Status?
public var complete: Bool? = false
public var completeNum: NSNumber? {
get {
return complete.map({ return NSNumber(value: $0) })
}
}

public init(_id: Int64?, petId: Int64?, quantity: Int?, shipDate: Date?, status: Status?, complete: Bool?) {
self._id = _id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,8 @@ import Foundation
public struct OuterComposite: Codable {

public var myNumber: Double?
public var myNumberNum: NSNumber? {
get {
return myNumber.map({ return NSNumber(value: $0) })
}
}
public var myString: String?
public var myBoolean: Bool?
public var myBooleanNum: NSNumber? {
get {
return myBoolean.map({ return NSNumber(value: $0) })
}
}

public init(myNumber: Double?, myString: String?, myBoolean: Bool?) {
self.myNumber = myNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public struct Pet: Codable {
case sold = "sold"
}
public var _id: Int64?
public var _idNum: NSNumber? {
get {
return _id.map({ return NSNumber(value: $0) })
}
}
public var category: Category?
public var name: String
public var photoUrls: [String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import Foundation
public struct Return: Codable {

public var _return: Int?
public var _returnNum: NSNumber? {
get {
return _return.map({ return NSNumber(value: $0) })
}
}

public init(_return: Int?) {
self._return = _return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import Foundation
public struct SpecialModelName: Codable {

public var specialPropertyName: Int64?
public var specialPropertyNameNum: NSNumber? {
get {
return specialPropertyName.map({ return NSNumber(value: $0) })
}
}

public init(specialPropertyName: Int64?) {
self.specialPropertyName = specialPropertyName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import Foundation
public struct Tag: Codable {

public var _id: Int64?
public var _idNum: NSNumber? {
get {
return _id.map({ return NSNumber(value: $0) })
}
}
public var name: String?

public init(_id: Int64?, name: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import Foundation
public struct User: Codable {

public var _id: Int64?
public var _idNum: NSNumber? {
get {
return _id.map({ return NSNumber(value: $0) })
}
}
public var username: String?
public var firstName: String?
public var lastName: String?
Expand All @@ -25,11 +20,6 @@ public struct User: Codable {
public var phone: String?
/** User Status */
public var userStatus: Int?
public var userStatusNum: NSNumber? {
get {
return userStatus.map({ return NSNumber(value: $0) })
}
}

public init(_id: Int64?, username: String?, firstName: String?, lastName: String?, email: String?, password: String?, phone: String?, userStatus: Int?) {
self._id = _id
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4-SNAPSHOT
4.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4-SNAPSHOT
4.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4-SNAPSHOT
4.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4-SNAPSHOT
4.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return Alamofire.SessionManager(configuration: configuration)
}

/**
May be overridden by a subclass if you want to custom request constructor.
*/
open func createURLRequest() -> URLRequest? {
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
guard let originalRequest = try? URLRequest(url: URLString, method: HTTPMethod(rawValue: method)!, headers: buildHeaders()) else { return nil }
return try? encoding.encode(originalRequest, with: parameters)
}

/**
May be overridden by a subclass if you want to control the Content-Type
that is given to an uploaded form part.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ import Foundation

public struct SampleSubClass: Codable {

public var baseClassStringProp: String?
public var baseClassIntegerProp: Int?
public var subClassStringProp: String?
public var subClassIntegerProp: Int?

public init(baseClassStringProp: String?, baseClassIntegerProp: Int?, subClassStringProp: String?, subClassIntegerProp: Int?) {
self.baseClassStringProp = baseClassStringProp
self.baseClassIntegerProp = baseClassIntegerProp
public init(subClassStringProp: String?, subClassIntegerProp: Int?) {
self.subClassStringProp = subClassStringProp
self.subClassIntegerProp = subClassIntegerProp
}
Expand Down