Client

open class Client

Client object for performing requests against the Contentful API.

  • Initializes a new Contentful client instance

    Declaration

    Swift

    public init(spaceId: String,
                    accessToken: String,
                    clientConfiguration: ClientConfiguration = .default,
                    sessionConfiguration: URLSessionConfiguration = .default)

    Parameters

    spaceId

    The space you want to perform requests against.

    accessToken

    The access token used for authorization.

    clientConfiguration

    Custom Configuration of the Client.

    sessionConfiguration

    The configuration for the URLSession. Note that HTTP headers will be overwritten interally by the SDK so that requests can be authorized correctly.

    Return Value

    An initialized client instance.

  • Fetch a collection of Entries from Contentful matching the specified query. This method does not specify the content_type in the query parameters, so the entries returned in the results can be of any type.

    Declaration

    Swift

    @discardableResult public func fetchEntries(with query: Query,
                                                    then completion: @escaping ResultsHandler<ArrayResponse<Entry>>) -> URLSessionDataTask?

    Parameters

    query

    The Query object to match results againts.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a collection of Entries from Contentful matching the specified query. This method does not specify the content_type in the query parameters, so the entries returned in the results can be of any type.

    Declaration

    Swift

    @discardableResult public func fetchEntries(with query: Query) -> Observable<Result<ArrayResponse<Entry>>>

    Parameters

    query

    The Query object to match results againts.

    Return Value

    A tuple of data task and an observable for the resulting array of Entry’s.

  • Fetch a collection of Entries of a specified content type matching the query. The content_type parameter is specified by passing in a generic parameter: a model class conforming to EntryModellable.

    Declaration

    Swift

    @discardableResult public func fetchMappedEntries<EntryType: EntryModellable>(with query: QueryOn<EntryType>,
                                                    then completion: @escaping ResultsHandler<MappedArrayResponse<EntryType>>) -> URLSessionDataTask?

    Parameters

    query

    A QueryOn object to match results of the specified EntryModellable against.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a collection of Entries of a specified content type matching the query. The content_type parameter is specified by passing in a generic parameter: a model class conforming to EntryModellable.

    Declaration

    Swift

    @discardableResult public func fetchMappedEntries<EntryType: EntryModellable>(with query: QueryOn<EntryType>)
            -> Observable<Result<MappedArrayResponse<EntryType>>>

    Parameters

    query

    A QueryOn object to match results of the specified EntryModellable against.

    Return Value

    A tuple of data task and an observable for the resulting array of EntryModellable types.

  • Fetch a collection of Assets from Contentful matching the specified query.

    Declaration

    Swift

    @discardableResult public func fetchAssets(with query: AssetQuery,
                                                   then completion: @escaping ResultsHandler<ArrayResponse<Asset>>) -> URLSessionDataTask?

    Parameters

    query

    The Query object to match results againts.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a collection of Assets from Contentful matching the specified query.

    Declaration

    Swift

    @discardableResult public func fetchAssets(query: AssetQuery) -> Observable<Result<ArrayResponse<Asset>>>

    Parameters

    query

    The Query object to match results againts.

    Return Value

    A tuple of data task and an observable for the resulting array of Assets.

  • Fetch a single Asset from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchAsset(id: String, completion: @escaping ResultsHandler<Asset>) -> URLSessionDataTask?

    Parameters

    id

    The identifier of the Asset to be fetched.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a single Asset from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchAsset(id: String) -> Observable<Result<Asset>>

    Parameters

    id

    The identifier of the Asset to be fetched.

    Return Value

    A tuple of data task and a signal for the resulting Asset.

  • Fetch a collection of Assets from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchAssets(matching: [String: Any] = [:],
                                                   completion: @escaping ResultsHandler<ArrayResponse<Asset>>) -> URLSessionDataTask?

    Parameters

    matching

    An optional list of search parameters the Assets must match.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a collection of Assets from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchAssets(matching: [String: Any] = [:]) -> Observable<Result<ArrayResponse<Asset>>>

    Parameters

    matching

    Optional list of search parameters the Assets must match.

    Return Value

    A tuple of data task and a signal for the resulting array of Assets.

  • Fetch the underlying media file as Data.

    Declaration

    Swift

    public func fetchData(for asset: Asset) -> Observable<Result<Data>>

    Return Value

    Tuple of the data task and a signal for the Data result.

  • Fetch the underlying media file as UIImage.

    Declaration

    Swift

    public func fetchImage(for asset: Asset) -> Observable<Result<UIImage>>

    Return Value

    The signal for the UIImage result

  • Fetch a single Content Type from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchContentType(id: String, completion: @escaping ResultsHandler<ContentType>) -> URLSessionDataTask?

    Parameters

    id

    The identifier of the Content Type to be fetched.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a single Content Type from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchContentType(id: String) -> Observable<Result<ContentType>>

    Parameters

    id

    The identifier of the Content Type to be fetched.

    Return Value

    A tuple of data task and a signal for the resulting Content Type.

  • Fetch a collection of Content Types from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchContentTypes(matching: [String: Any] = [:],
                                                         completion: @escaping ResultsHandler<ArrayResponse<ContentType>>) -> URLSessionDataTask?

    Parameters

    matching

    Optional list of search parameters the Content Types must match.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a collection of Content Types from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchContentTypes(matching: [String: Any] = [:]) ->  Observable<Result<ArrayResponse<ContentType>>>

    Parameters

    matching

    Optional list of search parameters the Content Types must match.

    Return Value

    A tuple of data task and a signal for the resulting array of Content Types.

  • Fetch a collection of Entries from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchEntries(matching: [String: Any] = [:],
                                                    completion: @escaping ResultsHandler<ArrayResponse<Entry>>) -> URLSessionDataTask?

    Parameters

    matching

    Optional list of search parameters the Entries must match.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests

  • Fetch a collection of Entries from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchEntries(matching: [String: Any] = [:]) ->  Observable<Result<ArrayResponse<Entry>>>

    Parameters

    matching

    Optional list of search parameters the Entries must match.

    Return Value

    A tuple of data task and a signal for the resulting array of Entries.

  • Fetch a single Entry from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchEntry(id: String, completion: @escaping ResultsHandler<Entry>) -> URLSessionDataTask?

    Parameters

    id

    The identifier of the Entry to be fetched.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Fetch a single Entry from Contentful.

    Declaration

    Swift

    @discardableResult public func fetchEntry(id: String) ->  Observable<Result<Entry>>

    Parameters

    id

    The identifier of the Entry to be fetched.

    Return Value

    A tuple of data task and a signal for the resulting Entry.

  • Fetch the space this client is constrained to.

    Declaration

    Swift

    @discardableResult public func fetchSpace(then completion: @escaping ResultsHandler<Space>) -> URLSessionDataTask?

    Parameters

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, which enables cancellation of requests, or nil if the. Space was already cached locally

  • Fetch the space this client is constrained to.

    Declaration

    Swift

    @discardableResult public func fetchSpace() -> Observable<Result<Space>>

    Return Value

    A tuple of data task and a signal for the resulting Space.

  • Perform an initial synchronization of the Space this client is constrained to.

    Declaration

    Swift

    @discardableResult public func initialSync(matching: [String: Any] = [:],
                                                   completion: @escaping ResultsHandler<SyncSpace>) -> URLSessionDataTask?

    Parameters

    matching

    Additional options for the synchronization.

    completion

    A handler being called on completion of the request.

    Return Value

    The data task being used, enables cancellation of requests.

  • Perform an initial synchronization of the Space this client is constrained to.

    Declaration

    Swift

    @discardableResult public func initialSync(matching: [String: Any] = [:]) -> Observable<Result<SyncSpace>>

    Parameters

    matching

    Additional options for the synchronization.

    Return Value

    A tuple of data task and a signal for the resulting SyncSpace.