Python API - nextgis/lib_ngstd GitHub Wiki

Python API

This is example of using access python API:

from ngstd._framework import *

# Check if user authorised
NGAccess.instance().isUserAuthorized()

# Check if user is supported
NGAccess.instance().isUserSupported()

# Check if function available for current user 
NGAccess.instance().isFunctionAvailable("NextGIS QGIS", "some function name")

# Get icon for plugin
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
icon = NGAccess.lockIcon(originalIcon, QSize(24, 24), QIcon())

# Get user name
NGAccess.instance().firstName()
NGAccess.instance().lastName()
NGAccess.instance().userId()
NGAccess.instance().email()
NGAccess.instance().endPoint()

Listen update user status events

There are two signals to listen for updates:

  1. userInfoUpdated()
  2. supportInfoUpdated()

Example of listening such events:

self.connect(NGAccess.instance(), QtCore.SIGNAL('supportInfoUpdated()'),
            self, QtCore.SLOT('updatePluginIcon()') )

Protected plugins

To get protected plugin decryptor execute following method:

NGAccess.instance().getPluginSign("plugin_name", "plugin_version")

For unauthorised and unsupported users the method will return empty string.

Get authorization header

To get authorization header execute following code:

from ngstd._core import *
NGRequest.getAuthHeader('https://my.nextgis.com/api/v1')
u'Authorization: Bearer RVU4zNRH4pnTatbn43GAgKAfd8YtqD'