diff --git a/Pod/Classes/Traverson.swift b/Pod/Classes/Traverson.swift index 653b6b3..6a184f4 100644 --- a/Pod/Classes/Traverson.swift +++ b/Pod/Classes/Traverson.swift @@ -448,6 +448,13 @@ open class Traverson { return self } + + @discardableResult + open func modifiedJsonHal() -> Traversing { + self.linkResolver = TraversonModifiedJsonHalLinkResolver() + + return self + } @discardableResult open func withHeaders(_ headers: [String: String]) -> Traversing { diff --git a/Pod/Classes/TraversonModifiedJsonHalLinkResolver.swift b/Pod/Classes/TraversonModifiedJsonHalLinkResolver.swift new file mode 100644 index 0000000..53e888a --- /dev/null +++ b/Pod/Classes/TraversonModifiedJsonHalLinkResolver.swift @@ -0,0 +1,32 @@ +/* +* Copyright 2016 smoope GmbH +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import Foundation +import SwiftyJSON + +/** + HATEOAS media type response link resolver + */ +open class TraversonModifiedJsonHalLinkResolver: TraversonLinkResolver { + + public init() { } + + open func findNext(_ rel: String, data: JSON) throws -> String { + guard let next = data["links"][rel]["href"].string else { throw TraversonError.relationNotFound(relation: rel) } + + return next + } +}