HubID SDK


HubID SDK provides basic techniques that make it easier to work with HubID API. It implements method OAUTH authorization and execution of queries to the api.

Demo example


Install

To use HubID SDK enough to add the following code to your web page. The script is loaded asynchronously without blocking the loading of the other elements of the page.

<script>
    window.HubIDAsyncInit = function() {
      HubID.init({
        'clientID': 'your-application-id', // Required for all queries
        'publicKey': 'your-application-public-key',  // Required for queries using the public key
        'privateKey': 'your-application-private-key' // Required for queries using the private key
      });

    };
    (function(d, s, id){
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = "http://api.hubculture.local/hubid-sdk/dist/hubid-sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
      js.onload = HubIDAsyncInit;
    }(document, 'script', 'hubid-sdk'));
</script>
                    

Login

For use user data, the user needs to log in HubID and in your application.

<script>
    HubID.login(
        {
          holderID: 'my-hubid-holder' // Specify the id element in which the login button will be placed.
        },

        function(result) {
            // success callback
        },
        function(err) {
            // error callback
        }
    );
</script>
                    

Get user login status

For use user data, the user needs to log in HubID and in your application.

<script>
    HubID.getLoginStatus(
        function(result) {
            // success callback
        },
        function(err) {
            // error callback
        }
    );
</script>
                    

Api requests

These methods allow you to query HUBID api. List of all available methods can be found in the documentation

<script>
    HubID.apiGet(
        {
          uri: 'api-method-uri' // Api uri. Example: '/user'.
        },

        function(result) {
          // success callback
        },
        function(err) {
          // error callback
        }
    );
    HubID.apiPost(
        {
          uri: 'api-method-url', // Api uri. Example: '/user'.
          data: 'send-data-object' // Request body data (must be object)
        },

        function(result) {
          // success callback
        },
        function(err) {
          // error callback
        }
    );
    HubID.apiPut(
        {
          uri: 'api-method-url', // Api uri. Example: '/user'.
          data: 'send-data-object' // Request body data (must be object)
        },

        function(result) {
          // success callback
        },
        function(err) {
          // error callback
        }
    );
    HubID.apiDelete(
        {
          uri: 'api-method-url' // Api uri. Example: '/user'.
        },

        function(result) {
          // success callback
        },
        function(err) {
          // error callback
        }
    );
</script>