Skip to content

Commit

Permalink
Revert unnecessary change
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Sep 16, 2016
1 parent 6ce6b39 commit 0712334
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/Client/FHIROpenServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ open class FHIROpenServer: FHIRServer {
- returns: An appropriate `FHIRServerRequestHandler`, for example a _FHIRServerJSONRequestHandler_ if sending and receiving JSON
*/
open func handlerForRequest(_ ofType: FHIRRequestType, resource: Resource?, headers: FHIRRequestHeaders? = nil) -> FHIRServerRequestHandler? {
let handler = FHIRServerJSONRequestHandler(type: ofType, resource: resource)
let handler = FHIRServerJSONRequestHandler(ofType, resource: resource)
if let headers = headers {
handler.add(headers: headers)
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/Client/FHIRServerRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class FHIRServerRequestHandler {
}

/// The HTTP type of the request.
open let type: FHIRRequestType
open let method: FHIRRequestType

/// Headers to be used on the request.
open var headers: FHIRRequestHeaders
Expand All @@ -35,8 +35,8 @@ open class FHIRServerRequestHandler {
/// The receiver may hold on to a resource that supplies the request's body data.
open var resource: Resource?

public init(type: FHIRRequestType, resource: Resource? = nil) {
self.type = type
public init(_ method: FHIRRequestType, resource: Resource? = nil) {
self.method = method
self.headers = type(of: self).defaultHeaders
self.resource = resource
}
Expand Down Expand Up @@ -73,7 +73,7 @@ open class FHIRServerRequestHandler {
*/
open func prepare(request: inout URLRequest) throws {
try prepareData()
type.prepare(request: &request, body: data)
method.prepare(request: &request, body: data)
headers.prepare(request: &request)
}

Expand Down Expand Up @@ -143,7 +143,7 @@ open class FHIRServerJSONRequestHandler: FHIRServerRequestHandler {
}

open override func prepare(request: inout URLRequest) throws {
switch type {
switch method {
case .PUT:
headers[.contentType] = "application/json+fhir; charset=utf-8"
case .POST:
Expand Down Expand Up @@ -172,14 +172,14 @@ open class FHIRServerDataRequestHandler: FHIRServerRequestHandler {

init(_ type: FHIRRequestType, contentType: String) {
self.contentType = contentType
super.init(type: type, resource: nil)
super.init(type, resource: nil)
}

override open func prepareData() throws {
}

open override func prepare(request: inout URLRequest) throws {
switch type {
switch method {
case .GET:
headers[.accept] = contentType
case .PUT:
Expand Down
6 changes: 3 additions & 3 deletions Tests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Test request generation.
class RequestTests: XCTestCase {

func testJSONGETRequest() {
let handler = FHIRServerJSONRequestHandler(type: .GET)
let handler = FHIRServerJSONRequestHandler(.GET)
XCTAssertEqual("application/json+fhir", handler.headers[.accept])
}

func testJSONPUTRequest() {
let handler = FHIRServerJSONRequestHandler(type: .PUT)
let handler = FHIRServerJSONRequestHandler(.PUT)
var req = URLRequest(url: URL(string: "https://fhir.smarthealthit.org")!)
try! handler.prepare(request: &req)
XCTAssertEqual("application/json+fhir", handler.headers[.accept])
Expand All @@ -41,7 +41,7 @@ class RequestTests: XCTestCase {
}

func testJSONPOSTRequest() {
let handler = FHIRServerJSONRequestHandler(type: .POST)
let handler = FHIRServerJSONRequestHandler(.POST)
var req = URLRequest(url: URL(string: "https://fhir.smarthealthit.org")!)
try! handler.prepare(request: &req)
XCTAssertEqual("application/json+fhir", handler.headers[.accept])
Expand Down
2 changes: 1 addition & 1 deletion Tests/ResourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class LocalPatientServer: FHIROpenServer {
pat.meta?.versionId = "\(version+1)"
pat.name = [HumanName(json: ["family": ["POST"]])]

let req = FHIRServerJSONRequestHandler(type: .POST)
let req = FHIRServerJSONRequestHandler(.POST)
req.resource = pat
try! req.prepareData()

Expand Down

0 comments on commit 0712334

Please sign in to comment.