Skip to content

Instantly share code, notes, and snippets.

@valeriomazzeo
Created September 5, 2018 17:45
Show Gist options
  • Save valeriomazzeo/8b4f3836cfcc40c73200c849700f9709 to your computer and use it in GitHub Desktop.
Save valeriomazzeo/8b4f3836cfcc40c73200c849700f9709 to your computer and use it in GitHub Desktop.
import Foundation
import HTTP
extension HTTPMethod: RawRepresentable {
// swiftlint:disable:next cyclomatic_complexity function_body_length
public init?(rawValue: String) {
switch rawValue.uppercased() {
case "GET":
self = .GET
case "PUT":
self = .PUT
case "ACL":
self = .ACL
case "HEAD":
self = .HEAD
case "POST":
self = .POST
case "COPY":
self = .COPY
case "LOCK":
self = .LOCK
case "MOVE":
self = .MOVE
case "BIND":
self = .BIND
case "LINK":
self = .LINK
case "PATCH":
self = .PATCH
case "TRACE":
self = .TRACE
case "MKCOL":
self = .MKCOL
case "MERGE":
self = .MERGE
case "PURGE":
self = .PURGE
case "NOTIFY":
self = .NOTIFY
case "SEARCH":
self = .SEARCH
case "UNLOCK":
self = .UNLOCK
case "REBIND":
self = .REBIND
case "UNBIND":
self = .UNBIND
case "REPORT":
self = .REPORT
case "DELETE":
self = .DELETE
case "UNLINK":
self = .UNLINK
case "CONNECT":
self = .CONNECT
case "MSEARCH":
self = .MSEARCH
case "OPTIONS":
self = .OPTIONS
case "PROPFIND":
self = .PROPFIND
case "CHECKOUT":
self = .CHECKOUT
case "PROPPATCH":
self = .PROPPATCH
case "SUBSCRIBE":
self = .SUBSCRIBE
case "MKCALENDAR":
self = .MKCALENDAR
case "MKACTIVITY":
self = .MKACTIVITY
case "UNSUBSCRIBE":
self = .UNSUBSCRIBE
default:
self = .RAW(value: rawValue)
}
}
public var rawValue: String {
switch self {
case .GET:
return "GET"
case .PUT:
return "PUT"
case .ACL:
return "ACL"
case .HEAD:
return "HEAD"
case .POST:
return "POST"
case .COPY:
return "COPY"
case .LOCK:
return "LOCK"
case .MOVE:
return "MOVE"
case .BIND:
return "BIND"
case .LINK:
return "LINK"
case .PATCH:
return "PATCH"
case .TRACE:
return "TRACE"
case .MKCOL:
return "MKCOL"
case .MERGE:
return "MERGE"
case .PURGE:
return "PURGE"
case .NOTIFY:
return "NOTIFY"
case .SEARCH:
return "SEARCH"
case .UNLOCK:
return "UNLOCK"
case .REBIND:
return "REBIND"
case .UNBIND:
return "UNBIND"
case .REPORT:
return "REPORT"
case .DELETE:
return "DELETE"
case .UNLINK:
return "UNLINK"
case .CONNECT:
return "CONNECT"
case .MSEARCH:
return "MSEARCH"
case .OPTIONS:
return "OPTIONS"
case .PROPFIND:
return "PROPFIND"
case .CHECKOUT:
return "CHECKOUT"
case .PROPPATCH:
return "PROPPATCH"
case .SUBSCRIBE:
return "SUBSCRIBE"
case .MKCALENDAR:
return "MKCALENDAR"
case .MKACTIVITY:
return "MKACTIVITY"
case .UNSUBSCRIBE:
return "UNSUBSCRIBE"
case .RAW(let value):
return value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment