Skip to main content

Simple rewards for your app or website

Project description

Scrimmage Rewards

The low-code loyalty program maker.

This library is a part of the Scrimmage Rewards Program that is providing a solution for loyalty programs and rewards.

Tutorial can be found at Scrimmage Rewards Tutorial.

Getting started

Install

pip install scrimmage-sdk

(This PyPi package is not currently available, but will be available soon)

Configuration

from scrimmage_sdk import Scrimmage

Scrimmage.init_rewarder(
    api_server_endpoint="YOUR_SCRIMMAGE_API_SERVER_ENDPOINT",
    private_key="YOUR_SCRIMMAGE_PRIVATE_KEY",
    namespace="YOUR_SCRIMMAGE_NAMESPACE",
)

Usage

Get user token

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

token = Scrimmage.get_user_token("unique-user-id")

Track rewardable for a user

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

user_id = 'nanachi'
data_type = 'helloWorld'
rewards = [{
    'amount': 10,
    'currency': 'USD'
}]
response = Scrimmage.reward.track_rewardable(user_id, data_type, rewards=rewards)

Track rewardable for a user only once (with idempotency key)

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

user_id = 'nanachi'
data_type = 'helloWorld'
idempotency_key = 'idempotency_key_12345'
reward = {
    'amount': 10,
    'currency': 'USD'
}
response = Scrimmage.reward.track_rewardable_once(user_id, data_type, idempotency_key, reward=reward)

Using multiple Scrimmage instances at once

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

# Using multiple Scrimmage instances at once
scrimmage1 = Scrimmage.create_rewarder(
    api_server_endpoint=os.getenv('SCRIMMAGE_API_SERVER_ENDPOINT_1'),
    private_key=os.getenv('SCRIMMAGE_PRIVATE_KEY_1'),
    namespace=os.getenv('SCRIMMAGE_NAMESPACE_1'),
)
scrimmage1.user.get_user_token(...)
scrimmage1.reward.track_rewardable(...)

scrimmage2 = Scrimmage.create_rewarder(
    api_server_endpoint=os.getenv('SCRIMMAGE_API_SERVER_ENDPOINT_2'),
    private_key=os.getenv('SCRIMMAGE_PRIVATE_KEY_2'),
    namespace=os.getenv('SCRIMMAGE_NAMESPACE_2'),
)
scrimmage2.user.get_user_token(...)
scrimmage2.reward.track_rewardable(...)

Async Usage

To use the SDK in an async environment, you can append _async to the functions to use the async version of the function.

import asyncio

from scrimmage_sdk import Scrimmage

# Configure Scrimmage
Scrimmage.init_rewarder(
    api_server_endpoint="YOUR_SCRIMMAGE_API_SERVER_ENDPOINT",
    private_key="YOUR_SCRIMMAGE_PRIVATE_KEY",
    namespace="YOUR_SCRIMMAGE_NAMESPACE",
)

# Async usage
async def main():
    token = await Scrimmage.get_user_token_async("unique-user-id")
    print(token)

    user_id = 'nanachi'
    data_type = 'helloWorld'
    rewards = [{
        'amount': 10,
        'currency': 'USD'
    }]
    response = await Scrimmage.reward.track_rewardable_async(user_id, data_type, rewards=rewards)
    print(response)

    user_id = 'nanachi'
    data_type = 'helloWorld'
    idempotency_key = 'idempotency_key_12345'
    reward = {
        'amount': 10,
        'currency': 'USD'
    }
    response = await Scrimmage.reward.track_rewardable_once_async(user_id, data_type, idempotency_key, reward=reward)
    print(response)

asyncio.run(main())

Examples

See the examples folder for different use cases.

Usage on other platforms

Development

  1. Add .env.test to your environment with the following variables
SCRIMMAGE_API_SERVER_ENDPOINT=SCRIMMAGE_API_SERVER_ENDPOINT
SCRIMMAGE_PRIVATE_KEY=YOUR_SCRIMMAGE_PRIVATE_KEY
SCRIMMAGE_NAMESPACE=YOUR_SCRIMMAGE_NAMESPACE
  1. Install dependencies
pip install -r requirements.txt
  1. Start your development - you can add tests in the tests folder

  2. Run tests using pytest from the root directory

pytest

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/scrimmage-rewards.

License

The SDK is available as open source under the terms of the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrimmage-sdk-0.1.0.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

scrimmage_sdk-0.1.0-py3-none-any.whl (13.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page