API Reference

API Reference for the OkHi JavaScript browser library

OkHi(configuration)

Creates a new OkHi class instance.

Arguments

  • configuration (object) -- A configuration object that the new class instance will be initiated with.

Returns

A new OkHi class instance with methods and values publicly accessible.

Usage

var okhi = new OkHi({ apiKey: 'my_api_key'});

LocationCard(options)

Creates and renders an OkHi location card on the DOM. Upon success the onSuccess callback function will be called with a SuccessObject and upon failure the onError will be called with a ErrorObject.

Arguments

  • options (object) -- A configuration object that the LocationCard class will use to render the card on the DOM.

Returns

A location card class instance with the properties below.

user

This property allows you to change the user by supplying a new user object to the card. Only phone number is required to change the user. If you provide only a new phone number without changing firstName and lastName properties the previous values will be used.

Usage

var okhi = new OkHi({ apiKey: 'my_api_key' });
var element = document.getElementById('lets-okhi');
var user = {
    firstName: "John" // optional
    lastName: "Doe", // optional
    phone: "0722xxxxxx", // required
};
var style = { //add your style configuration here };
var copy = { // add your copy configuration here };

var handleOnSuccess = funcation(data) {
// handle your success here with the data you get back
};

var handleOnError = function (error) {
// handle errors here e.g fallback to your own way of collecting a location information 
};

var locationCard = new okhi.LocationCard({
    element: element, // required
    user: user, // required
    onSuccess: handleOnSuccess, // optional
    onError: handleOnError,// optional
    style: style, // optional
    copy: copy // optional
});

// changing the user
locationCard.user = {
  firstName: 'Evans', // optional
  lastName: 'Mutai', // optional
  phone: '0721xxxxxx', // required
}

LocationManager(options)

Enables launching and closing of the OkHi location manager.

Arguments

  • options (object) -- A configuration object that the LocationManager class will use to to launch.

Returns

A location manager class instance with the methods below

launch(launchConfiguration)

Arguments

  • launchConfiguration (object) -- A configuration object that will enable the location manager to launch in different modes.

  • mode - string values

    • select_location: This launches the location manager prompting the user to select one of their existing locations if available

  • location - object

    • id - An OkHi location id.

Launch Possibilities

Usage

var okhi = new OkHi({ apiKey: 'my_api_key' });

var button = document.getElementById('lets-okhi');

var handleOnSuccess = function (data) {
  // handle your success here with the data you get back
};

var handleOnError = function (error) {
  // handle errors here e.g fallback to your own way of collecting a location information 
};

var style = { //add your style configuration here };

var copy = { // add your copy configuration here };

var launchConfiguration = {
  mode: // mode you want to launch in
  location: {
    id: 'xxx' // the OkHi location id you want manipulated in the selected mode
  }
};

var handleButtonClick = function () {
  var user = {
    phone: '0722xxxxxx',
    firstName: 'John',
    lastName: 'Doe',
  };
  var locationManager = new okhi.LocationManager({
    user: user,
    onSuccess: handleOnSuccess,
    onError: handleOnError,
    style: style,
    copy: copy
  });
  locationManager.launch(launchConfiguration);
};

button.addEventListener('click', handleButtonClick);

UserObject

The UserObject consists of information about a single user.

LocationObject

A LocationObject consists of information about a single OkHi location.

*IMPORTANT* When a user is creating / selecting a location you can always expect to receive a latitude and a longitude all other information listed below are optional.

SuccessObject

The SuccessObject is the UserObject and LocationObject nested into one object.

Example

{
    "location": {
        "streetName": "Yellow brick road",
        "lat": -1.2343261,
        "lng": 36.6642569,
        "placeId": "1A8sxd6V9W",
        "propertyName": "Mitte lane court",
        "directions": "turn is gud",
        "id": "dEwmYjtpqc",
        "url": "https://receive2.okhi.co/dEwmYjtpqc",
        "otherInformation": "Please pet the dog when you arrive"
    },
    "user": {
        "phone": "0721856492",
        "firstName": "Evans",
        "lastName": "Mutai"
    }
}

ErrorObject

An ErrorObject contains information of any error that occurred during the launch of the LocationManager.

Error Codes

StyleObject

The StyleObject provides you with a way to customise both the LocationCard and LocationManager to better match your brand requirements.

StyleBaseObject

StyleClassObject

Example

style: {
  base: {
    color: '#0277BD',
    logo: 'https://cdn.okhi.co/icon.png',
    name: 'OkHi',
  },
  classes: {
    'lc-container': 'border 1px solid red;',
    'lc-title': 'font-size: 22px;',
    'lc-button': 'border-radius: 0;',
    'lc-top': 'background-color: pink;',
    'lc-bottom': 'background-color: orange;',
    'block-button': 'border-radius: 8px;',
    'up-container': 'background: blue;',
    'up-message': 'color: purple;',
    'lc-information': 'opacity: 0.4;',
  },
},

CopyObject

This object allows you to change different pieces of copy in the LocatinCard

Example

copy: {
  createOtherInformation: 'Create your delivery location',
  updateOtherInformation: 'Change your delivery notes',
  createLocation: 'Create a new delivery location',
  selectLocation: 'Select a delivery location',
  upsellMessage: 'Create your first delivery location with OkHi!',
},

ConfigurationObject

AppBarConfigurationObject

Example

config: {
    appBar: {
      color: '#f0f0f0',
      visible: true,
    },
    streetView: true
},

Last updated