Fantasy Match Points via Firebase

Fantasy Match Points via Firebase

Fantasy player points information available through the Fantasy Match Points API, automatically updated and delivered to your Firebase backend.

Configuring your Console

Follow the instructions below to receive automated Fantasy match points updates in your Firebase Realtime Database:
  1. To receive automatic match updates from Roanuz Cricket API, you are required to share a service account with us.
  2. From your Firebase Console, go to Project Settings and open the Service Accounts tab. In the Service accounts settings, click on the "Manage service account permissions" option.
  3. Now, click on the "Create Service Account" button. Enter a suitable Service account name & Service Account ID and click Create. Provide an optional description in the Description field if needed.
  4. In the second step, under the "Select a Role" dropdown, type and select "Firebase Admin". Once done, skip the third step and click on Done.
  5. Now, in the Filter table, in the Service account you have just created, click on the options button under the Actions column and click on Create Key. Select JSON as the Key type and click on Create. A JSON file will now be downloaded in your system.
  6. Now, head back to your Firebase Console and create a new Realtime Database under test mode. After creating the database, create a node called "rs-cricket" with a value 1 for us to push data.
  7. Now, open a new Tab in your browser and head to your Roanuz Console. Click on Push Configuration and select the Firebase option.
  8. Click on the Generate option near the Push Auth Code field. In the DB URL text box, paste your Firebase Realtime Database URL, and in the Service Data text box, paste the contents of the JSON file which was previously downloaded.
  9. Copy the value of the generated Push Auth Code and head back to your Firebase Console.
  10. Replace the snippet in the Rules tab of your Realtime Database with the following snippet:

DB rules

{ "rules": { ".read": "auth.uid === 'rs-cricket-user-<your generated push auth code'", ".write": "auth.uid === 'rs-cricket-user-<your generated push auth code'", } }
{
  "rules": {
    ".read": "auth.uid === 'rs-cricket-user-<your generated push auth code'",
    ".write": "auth.uid === 'rs-cricket-user-<your generated push auth code'", 
  }
}
icon copy
  1. Now, click on Publish. You are now all set to subscribe and receive automatic match updates.

Sending a Subscription Request

You have to subscribe to the matches individually for receiving automatic updates. The Sample snippet below demonstrates how to send a subscription request. Please note that subscribing twice to the same match does not mean that you will be charged twice, or you will receive the same update twice.

Fantasy Match Points Subscribe - Firebase

terminal
pip install requests
pip install requests
icon copy
Python
import requests project_key = 'YOUR_PROJ_KEY' token = 'YOUR_ACCESS_TOKEN' match_key = 'ausind_2020_odi01' url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/subscribe/".format(project_key,match_key) headers = { 'rs-token': token } payload = { 'method': "google:firebase" } response = requests.post(url, headers=headers, json=payload) print(response.json())
import requests

project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/subscribe/".format(project_key,match_key)
headers = {
    'rs-token': token
}
payload = {
    'method': "google:firebase"
}
response = requests.post(url, headers=headers, json=payload)

print(response.json())
icon copy

Handling the data received

Once successfully set up, Roanuz Cricket API servers will automatically start pushing data to your Firebase Realtime Database as the match progresses. You can easily include the data in your application by using the Firebase APIs.

Unsubscribing from a Match

For any reasons, if you wish to opt-out of receiving automatic updates for a match, you can do so by placing an unsubscribe request from the Fantasy Match Points Unsubscribe API.

Fantasy Match Points Unsubscribe - Firebase

terminal
pip install requests
pip install requests
icon copy
Python
import requests project_key = 'YOUR_PROJ_KEY' token = 'YOUR_ACCESS_TOKEN' match_key = 'ausind_2020_odi01' url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/unsubscribe/".format(project_key,match_key) headers = { 'rs-token': token } payload = { 'method': "google:firebase" } response = requests.post(url, headers=headers, json=payload) print(response.json())
import requests

project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/unsubscribe/".format(project_key,match_key)
headers = {
    'rs-token': token
}
payload = {
    'method': "google:firebase"
}
response = requests.post(url, headers=headers, json=payload)

print(response.json())
icon copy