NeoDay iOS SDK - Campaigns

    //// Makes the Campaigns Overview screen that shows all the Campaigns available for a user.
    ///
    /// - parameter filter: Filter to use for which Campaign types to show.
    /// - parameter completion: Contains the screen with all Campaigns.
    public func makeCampaignsOverview(
        filter: CampaignTypeFilter = .showAll,
        _ completion: @escaping (Result<UIViewController, Error>) -> Void
    )
    
    /// Makes the Campaign detail screen based on the campaignID and/or campaignInstanceID.
    ///
    /// - parameter campaignID: The id of the Campaign
    /// - parameter campaignInstanceID: Optional, a Campaign will have a unique campaignInstanceID when a user can participate in the Campaign.
    /// - parameter completion: Optionally returns the Campaign Detail screen. When a user is logged out a Campaign Detail screen will always be returned. When a user is logged in, a Campaign Detail screen will only be returned when there is Campaign available with the same campaignInstanceID passed in.
    public func makeCampaignDetail(
        campaignID: String,
        campaignInstanceID: String? = nil,
        _ completion: @escaping (Result<UIViewController, Error>) -> Void
    )
    
    /// Reloads the Campaign data that is shown on the Campaigns Overview screen
    ///
    /// - parameter filter: Filter to use for which Campaign types to show.
    /// - parameter completion: Contains the the result of reloading Campaigns data for the given filter.
    public func reloadCampaigns(
        filter: CampaignTypeFilter = .showAll,
        completion: @escaping (Result<Bool, Error>) -> Void
    )
        
    /// Participate with a Campaign without having to be on the Campaign detail screen.
    ///
    /// - parameter participationMethod: The participation method to use for a Campaign
    /// - parameter completion: Returns the result of participating
    public func partipate(
        with participationMethod: ParticipationMethod,
        completion: @escaping (Result<Bool, Error>) -> Void
    )
    
    /// Determines how many items are shown on the Campaign transaction history screen
    ///
    enum CampaignTransactionHistoryLimit {
        case showAll
        case last(UInt)
    }
    
    /// Makes the Campaign transaction history screen based on the campaignID and blockID.
    ///
    /// - parameter campaignID: The id of the Campaign
    /// - parameter blockID: The id of the block inside a Campaign, on which transactions have been made
    /// - parameter limit: The number of transactions to show
    public func makeCampaignTransactionsHistory(
        campaignID: String,
        blockID: String,
        limit: CampaignTransactionHistoryLimit = .last(20),
        _ completion: @escaping (Result<UIViewController, Error>) -> Void
    )

Directly requesting a Campaign Overview screen

The NeoDaySDK factory methods are executed asynchronously in order to fetch the data and return a UIViewController.

sdk.makeCampaignsOverview(filter: .showOnly([.challenge, .gamification])) { [weak self] result in
    guard let self = self else {
        return
    }
    
    switch result {
        case let .success(viewController):
            // Display the viewController
            
        case let .failure(error):
            // Handle the error
    }
}

Directly requesting a Campaign detail screen

sdk.makeCampaignDetail(campaignID: "campaign-id", campaignInstanceID: "campaign-instance-id") { [weak self] result in
    guard let self = self else {
        return
    }
    
    switch result {
        case let .success(viewController):
            // Display the viewController
            
        case let .failure(error):
            // Handle the error
    }
}

Participating with a Campaign

It is possible to participate with a Campaign without being on the Campaign Detail screen. This is currently only supported for the "Scratch Card" Campaign in combination with a "code submission" participation.

let campaignID = "some campaign id"
let code = "some code or URL String"

sdk.partipate(with: .codeSubmission(campaignID: campaignID, code: code)) { [weak self] result in
    guard let self = self else {
        return
    }
    
    switch result {
        case .success:
           // When the NeoDayDeepLinkDelegate is implemented the gamification screen (gamificationCampaign) will be returned there, right after the success is returned.
            
        case let .failure(error):
            // Handle the error
            if let readableError = (error as? NetworkingError)?.endpointResult?.dataDictionary, let errorMessage = (readableError["errors"] as? [String])?.first {
                print(errorMessage)
            }
    }
}

// NeoDayDeepLinkDelegate
func handleDeepLink(_ deepLink: DeepLink, factoryMethod: ((@escaping (Result<UIViewController, Error>) -> Void) -> Void)?) {
        
    switch deepLink.identifier {
       case .gamificationCampaign:
            factoryMethod? { [weak self] result in
                guard
                    let self = self,
                    let viewController = try? result.get()
                else {
                    return
                }

                // Present the viewController
            }
    }
}