๐Ÿ“ฑ Cordova

Access

Request access by emailing [email protected].

๐Ÿšง

Be sure to enable the Native SDK toggle under Settings->Account in the SharpSports dashboard to enable SDK Required books in the Linking UI.

Integrating with Angular

Generate a Mobile Authentication Token

In order to initialize the SharpSportsPlugin object in your application you need to generate a mobileAuthToken in your backend and retrieve it client-side.

First create an API endpoint in your backend to retrieve the mobileAuthToken from the SharpSports /v1/mobile/auth endpoint. Your API endpoint should:

  1. Require that the bettor is authenticated in your application
  2. Pass the internalId of the authenticated bettor as data to the /v1/mobile/auth endpoint
  3. Return the value of {"token":<mobileAuthToken>} you receive from the /v1/mobile/auth endpoint

The mobileAuthToken is unique by internalId but does not have a time to live, so you can use the same token repeatedly per bettor.

Example usage of /v1/mobile/auth is shown below in node:

const privateKey = 'my-private-api-key'
const internalId = 'internal-id-of-authenticated-bettor'
const HEADERS = {
	"Authorization" : `Token ${privateKey}`,
	"Content-Type": "application/json"
}

const  DATA = {
	"internalId": internalId
}

const  OPTS = {
	method: 'POST',
	headers: HEADERS,
	body: JSON.stringify(DATA)
};

let response = await fetch('https://api.sharpsports.io/v1/mobile/auth',OPTS)
let data = await response.json() //data takes the form {"token": <mobileAuthToken>}

Your application should fetch the mobileAuthToken once a bettor has logged in to your app and you can use it to initialize the SharpSportsPlugin .

Adding the Cordova Plugin

  • Add the SharpSports plugin to the cordova app:

<ionic> cordova plugin add https://github.com/sharpsports/cordova-plugin.git

  • Declare Plugin variable in the file where you will be initializing the plugin

declare var SharpSportsPlugin: any;

  • Initialize the Plugin
    • internalId : Your internal identifier for the authenticated bettor
    • publicKey: Your SharpSports public API key
    • mobileAuthToken: This bettor's unique mobile authentication token

sharpsports = new SharpSportsPlugin(internalId, publicKey, mobileAuthToken)

Android specific setup

Contact us to get your github account added as an outside collaborator to the sharpsports-android library. Please generate a Personal Access Token (PAT) to use when installing the library into your project. This should be a classic token with permission scope read:packages.

For details on how to create a classic PAT see: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

Set GITHUB_USER_NAME to your github username ID, and GITHUB_TOKEN to a token scoped to read the SharpSports repository, as environment variables. This is necessary for the build_extras.gradle repositories block.

Plugin Methods

Context

The Context method corresponds to the API call POST https://api.sharpsports.io/v1/context. It returns a Promise that when resolved contains a context ID - {"cid": <cid>}.

Use this cid to render a webview that navigates to https://ui.sharpsports.io/link/<cid> (or a specific book/region if you prefer - see https://docs.sharpsports.io/#create-your-own-button-for-each-book). Make sure to generate a new cid each time the webview is opened; don't create a cid on app load and use for multiple sessions.

All of the arguments for the Context method are optional.

Setting Light/Dark Mode

You can set the SharpSports UI background color by using the uiMode parameter

dark: dark mode background

light: light mode background

system: use device's default setting

sharpsports.Context({uiMode: <light|dark|system>})
Generate a Context for Best Price Widget

If you need to generate a context for the SharpSports Best Price Widget you use the bestPrice parameter. Then navigate to the url https://ui.sharpsports.io/best-price/<cid>.

sharpsports.Context({bestPrice: true})

WebView

The WebView method allows you to display the SharpSports UI within a mobile web view. It is required to use this method in order for all sportsbooks to be accessible via the linking process.

  • url : The url that the web view will initially display
  • cid: The context ID generated by the Context method
sharpsports.WebView(url, cid)

Refresh

The Refresh method allows you to make refresh requests to the SharpSports API.

By default the Refresh method will run a refresh on all accounts associated with the internalId that you provided when initializing the SharpSportsPlugin object. Optionally you can pass a bettorId to refresh all accounts associated with that ID or a bettorAccountId to refresh just a specific account.

You can also optionally pass reverify: true as an argument to attach the reverify query parameter to the refresh request.

bettorId?: string;
bettorAccountId?: string;
reverify?: boolean;
Refresh by InternalID
sharpsports.Refresh()

corresponds to the API call

POST https://api.sharpsports.io/v1/bettors/<internalID>/refresh
Refresh by BettorID
sharpsports.Refresh({bettorId: <BTTR_ID>})

corresponds to the API call

POST https://api.sharpsports.io/v1/bettors/<BTTR_ID>/refresh
Refresh by BettorAccountID
sharpsports.Refresh({bettorAccountId: <BACT_ID>})

corresponds to the API call

POST https://api.sharpsports.io/v1/bettorAccounts/<BACT_ID>/refresh
Reverify
sharpsports.Refresh({bettorAccountId: <BACT_ID>, reverify: true})

corresponds to the API call

POST https://api.sharpsports.io/v1/bettorAccounts/<BACT_ID>/refresh?reverify=true

Example Usage

The following example angular component demonstrates proper usage of the SharpSports Cordova plugin to successfully sync sportsbooks using native code.

import { Component, Inject } from '@angular/core';
declare var SharpSportsPlugin: any;

@Component({
	selector: 'app-home',
	templateUrl: 'home.page.html',
	styleUrls: ['home.page.scss'],
})

export class HomePage {
	internalId: string;
	publicKey: string;
	mobileAuthToken: string;
	sharpsports: any;

	constructor() {
		this.internalId = '<bettor-internal-id>';
		this.publicKey = '<sharpsports-public-api-key>';
		this.mobileAuthToken = '<token>'; //This needs to be generated server-side
	}

	async link() {

		this.sharpsports = new SharpSportsPlugin(this.internalId, this.publicKey, this.mobileAuthToken)

		let response = await this.sharpsports.Context()
		let data = await response.json()
		console.log("Context Data: ", JSON.stringify(data))

		let url = `https://ui.sharpsports.io/link/${data.cid}`
		let inAppBrowserRef = this.sharpsports.WebView(url, data.cid)
	}
	
	async refresh() {

		this.sharpsports = new SharpSportsPlugin(this.internalId, this.publicKey, this.mobileAuthToken)
		
		let response = await this.sharpsports.Refresh()
		let data = await response.json()
		console.log("Refresh Data: ", JSON.stringify(data))
	}
}