Initialization
This document outlines the steps to initialize the ZumoKit SDK on Android, iOS and React Native. You'll need the following credentials to get started:
myRoot
- This is the base URL of your API on which ZumoKit Bundle library is configured.apiRoot
- This is the root URL of ZumoKit API.apiKey
- A unique key used to interact with the API.appId
- A unique identifier for your application.txServiceUrl
- This is the URL provided to you of the transaction WebSocket service.
SDK assumes that ZumoKit Bundle authentication endpoint is accessible at myRoot/wallet/preauth
. For example if your base URL is https://www.example.com/
and ZumoKit Bundle is accessible at https://www.example.com/wallet/preauth
then myRoot
is https://www.example.com/
.
Android
On Android, the main class you'll interact with is ZumoKit
. You'll need to create a new instance of the class and save a reference to it for use later.
import com.zumo.zumokit.ZumoKit;
public class MainActivity extends AppCompatActivity {
private ZumoKit zumoKit;
@Override
protected void onCreate(Bundle savedInstanceState) {
String myRoot = "https://www.example.com/";
String apiRoot = "https://kit.sandbox.zumo.money/";
String txServiceUrl = "wss://tx.sandbox.zumo.money/";
String apiKey = "a123456780bcdef12345";
String appId = "12dd1sr4-22ss-11aa-22ff-b14d1356ex";
String dbPath = this.getFilesDir().getAbsolutePath();
this.zumoKit = new ZumoKit(dbPath, txServiceUrl, apiKey, appId, apiRoot, myRoot);
}
}
You'll notice that in the above example we've passed dbPath
as the first argument for the ZumoKit
constructor. This is the absolute path to the directory the database for ZumoKit will be stored.
As we've initialized ZumoKit
in a class that extends Context
, we can get the path to the files directory with the getFilesDir()
method.
iOS
On iOS, the main class you'll interact with is ZumoKitImpl
. You'll need to create a new instance of the class and save a reference to it for use later.
#import "ViewController.h"
#import <ZumoKit/ZumoKit.h>
@interface ViewController ()
@property (strong, nonatomic) ZumoKitImpl *zumoKit;
@end
@implementation ViewController
- (void)viewDidLoad {
NSString *myRoot = @"https://www.example.com/";
NSString *apiRoot = @"https://kit.sandbox.zumo.money/";
NSString *txServiceUrl = @"wss://tx.sandbox.zumo.money/";
NSString *apiKey = @"a123456780bcdef12345";
NSString *appId = @"12dd1sr4-22ss-11aa-22ff-b14d1356ex";
NSArray *appFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *dbPath = [appFolderPath objectAtIndex:0];
_zumoKit = [[ZumoKitImpl alloc] initWithDbPath:dbPath
txServiceUrl:txServiceUrl
apiKey:apiKey
appId:appId
apiRoot:apiRoot];
}
@end
In the above example we've passed dbPath
as the first argument for the ZumoKitImpl
initializer. This is the absolute path to the directory the database for ZumoKit will be stored. In our example we use the cache directory provided by the OS for our applications
You may need to use Obj-C++ implementation files if you encounter errors importing any of the relevant classes. Rename your file to use the
.mm
extension if so.
React Native
When using ZumoKit with React Native, you'll interact with the ZumoKit
singleton. To get started, you'll need to provide your credentials to the class' init
method.
import React, { Component } from 'react';
import ZumoKit from 'react-native-zumo-kit';
class HelloZumoKit extends Component {
componentDidMount() {
ZumoKit.init({
myRoot: 'https://www.example.com/',
apiRoot: 'https://kit.sandbox.zumo.money',
txServiceUrl: 'wss://tx.sandbox.zumo.money/',
apiKey: 'a123456780bcdef12345',
appId: '12dd1sr4-22ss-11aa-22ff-b14d1356ex'
});
}
}
In the above example, we've provided the config object to the ZumoKit
singleton within a React component's componentDidMount
method. Unlike Android an iOS implementations, a dbPath
doesn't need to be provided and a reference doesn't need to be stored.