new_contents: # -*- coding: utf-8 -*-
  """
  @author: Stuart Longland
  Based on NiagaraAX client code.
  """
  import pyhaystack.client.HaystackClient as hc
  import pyhaystack.info as info
  import requests
  import json
  import time
  from hszinc import zoneinfo
  
  class Connect(hc.Connect):
      """
      This class connects to Widesky and fetch haystack servlet
      A session is open and authentication will persist
      """
      def __init__(self,url,username,password,**kwargs):
          """
          Define Niagara AX specific local variables : url
          Calls the authenticate function
          """
          hc.Connect.__init__(self,url,username,password,**kwargs)
          self.loginURL = self.baseURL + "login/"
          self.queryURL = self.baseURL + "api/"
          self.requestAbout = "about"
          self._login_expiry = 0
          self.isConnected = property(lambda self : \
                  self._login_expiry > time.time())
          self.authenticate()
  
      def authenticate(self):
          """
          Login to the server
          Get the cookie from the server, configure headers, make a POST request with credential informations.
          When connected, ask the haystack for "about" information and print connection information
          """
          print('pyhaystack %s | Authentication to %s' % (info.__version__,self.loginURL))
          print('Initiating connection')
  
          # Source: https://vrtsystems.atlassian.net/wiki/display/WSDOC/WideSky+API+Reference
          # Authentication
          #
          # WideSky uses token-based authentication with a bcrypt key hashing.
          # Before accessing the API, the client must first request a token, by
          # supplying a valid username & password with a POST request to the
          # /login URI. For example:
          #
          # POST /login
          # Content-Type: application/json
          #
          # {
          #
          #  "username": "myuser",
          #  "password": "mypassword"
          # }
          #
          # Response:
          #
          # {
          #   "token": "eyJ0…h1-Q",
          #   "expires": 1448250270588,
          #   "user": {
          #     "name": "myuser",
          #     "role": "admin",
          #     …
          #   }
          # }
  
          # Request body
          rq_body = json.dumps({
              'username': self.USERNAME,
              'password': self.PASSWORD,
          })
  
          # Attempt to post to login URL, this may throw back an exception.
          response = self.s.post(self.loginURL, headers={
                  'Content-Type': 'application/json',
              }, data=rq_body)
          # See if something failed, this will raise a HTTPError if something
          # failed at the server end.
          response.raise_for_status()
  
          # All good, keep moving along.
          res_body = response.json()
          self._rq_headers['X-Access-Token'] = res_body.get('token')
          self._login_expiry = res_body.get('expiry',0)
  
          #Continue with haystack login
          if self.isConnected:
              print('User logged in...')
              self.about = self.read(self.requestAbout)
              self.serverName = self.about['rows'][0]['serverName']
              self.haystackVersion = self.about['rows'][0]['haystackVersion']
              axVersion = self.about['rows'][0]['productVersion']
              haystack_tz = zoneinfo.get_tz_map()
              self.timezone = haystack_tz[\
                      self.read('read?filter=site')['rows'][0]['tz']]
              print('Time Zone used : %s' % self.timezone)
              print('Connection succeed with haystack on %s (%s) running haystack version %s' %(self.serverName,axVersion,self.haystackVersion))
              self.refreshHisList()
          else:
              # TODO: better exception
              raise Exception('Log-in failed.')
  
subject: Add initial support for VRT WideSky.