Fixer

struct Fixer

Adds support for requesting data from the Fixer.io Latest Rates API and being provided with an Exchange instance configured with this data.

Example

Exchange.Fixer.exchange(accessKey: "YourFixerAccessKey") { result in
    switch result {
        case let .success(exchange):
            // We have an Exchange value

        case let .failure(error):
            // Something went wrong. Dig into the error.
     }
}
  • Provides an Exchange value based upon the Fixer.io Latest Rates API.

    Declaration

    Swift

    @discardableResult
    static public func exchange(
        session: URLSession = .shared,
        host: String = defaultHost,
        path: String = detaultAPIPath,
        secure: Bool = true,
        accessKey: String?,
        completion: @escaping FixerCompletion
    ) -> URLSessionTask?

    Parameters

    session

    A URLSession used to create the URLSessionTask. Defaults to URLSession.shared

    host

    The host name (domain) of a Fixer.io compatible API. Defaults to the standard Fixer.io data host

    path

    The path (domain) to a Fixer.io Latest Rates compatible API. Defaults to the standard Fixer.io Latest Rates API

    secure

    Whether the request should be made over HTTP or HTTPS. The basic Fixer.io plan only supports HTTP. Defaults to true (HTTPS).

    accessKey

    The API access key issued by Fixer.io. Optional if you are using a compatible API that does not require an access key.

    completion

    Completes with a Swift Result<Exchange, FixerError> type. If the URLSessionTask is cancelled before completion, then this closure will not get called.

    Return Value

    An optional URLSessionTask handling the network request for the Fixer.io API call. If no call was made, due to error, then nil will be returned.

  • Declaration

    Swift

    public typealias FixerCompletion = (_ result: Result<Exchange, FixerError>) -> Void

    Parameters

    result

    A Swift Result<Exchange, FixerError> type.

  • Errors that can occur when requesting an Exchange value using the Fixer.io API

    See more

    Declaration

    Swift

    public enum FixerError : Error
  • The standard Fixer.io host for API calls: data.fixer.io

    Declaration

    Swift

    public static let defaultHost: String
  • The standard path for the Latest Rates API: api/latest

    Declaration

    Swift

    public static let detaultAPIPath: String
  • The URL query item key used to supply the API access key: access_key

    Declaration

    Swift

    public static let accessKeyQueryKey: String