Giter Club home page Giter Club logo

business-loyalty-ios-sdk-poc's Introduction

This NimbleLoyalty SDK library allows developers to easily integrate loyalty programs into their iOS applications.

Features

  • Authenticate
  • Get reward list
  • Redeem reward
  • Get reward history

Component Libraries

  • Moya
  • KeychainAccess

Requirements

  • iOS 14.0+
  • Xcode 14.0+

Installation

The iOS Loyalty SDK can be installed using CocoaPods or Swift Package Manager.

CocoaPods

To install using CocoaPods, add the following line to your Podfile:

pod 'NimbleLoyalty', '~> 0.1.0'

Swift Package Manager

To install using Swift Package Manager, add the following line to your dependencies:

.package(url: "https://github.com/nimblehq/business-loyalty-ios-sdk-poc.git", from: "0.1.0")

Usage

Authentication

Before authenticating the user, remember to set the clientId and clientSecret.

NimbleLoyalty.shared.setClientId("CLIENT_ID")
NimbleLoyalty.shared.setClientSecret("CLIENT_SECRET")
isAuthenticated()

Checks if the user is authenticated.

if NimbleLoyalty.shared.isAuthenticated() {
    // The user is authenticated, do something
} else {
    // The user is not authenticated, show a login button
}
authenticate(completion:)

Initiates the authentication flow.

NimbleLoyalty.shared.authenticate { result in
    switch result {
    case .success:
        // The user is authenticated, do something
    case .failure(let error):
    	print("Error authenticating: \(error.localizedDescription)")
    }
}
clearSession()

Remove the session, effectively logging the user out.

// Clear the user's session
NimbleLoyalty.shared.clearSession()

Get Reward List

Retrieves the list of available rewards for the authenticated user.

NimbleLoyalty.shared.getRewardList { result in
   switch result {
   case .success(let rewardList):
       // Display the list of rewards to the user
       for reward in rewardList.rewards {
           print("Reward name: \(reward.name)")
       }
   case .failure(let error):
       print("Error retrieving rewards: \(error.localizedDescription)")
   }
}

Redeem a Reward

Redeems a reward with the given reward's code for the authenticated user.

NimbleLoyalty.shared.redeemReward(code: "ABC123") { result in
   switch result {
   case .success(let rewardList):
       print("Reward redeemed with ID: \(redeemReward.id)")
   case .failure(let error):
       print("Error redeeming reward: \(error.localizedDescription)")
   }
}

Get Reward History

Retrieves the reward history for the authenticated user.

NimbleLoyalty.shared.getRewardHistory { result in
   switch result {
   case .success(let rewardHistory):
       // Display the reward history to the user
       for reward in rewardHistory {
           print("Reward name: \(reward.name)")
       }
   case .failure(let error):
       print("Error retrieving reward history: \(error.localizedDescription)")
   }
}

Credits

Nimble logo

This project is maintained and funded by Nimble.

License

This project is Copyright (c) 2023 and onwards Nimble. It is free software and may be redistributed under the terms specified in the LICENSE file.

business-loyalty-ios-sdk-poc's People

Contributors

ducbm051291 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.