from devicehive.handler import Handler
from devicehive.device_hive import DeviceHive


class ApiCallHandler(Handler):
    """Api call handler class."""

    def __init__(self, api, call, *call_args, **call_kwargs):
        super(ApiCallHandler, self).__init__(api)
        self._call = call
        self._call_args = call_args
        self._call_kwargs = call_kwargs
        self._call_result = None

    @property
    def call_result(self):
        return self._call_result

    def handle_connect(self):
        self._call_result = getattr(self.api, self._call)(*self._call_args,
                                                          **self._call_kwargs)
        self.api.disconnect()


class DeviceHiveApi(object):
    """Device hive api class."""

    def __init__(self, transport_url, **options):
        self._transport_url = transport_url
        self._options = options

    def _call(self, call, *call_args, **call_kwargs):
        device_hive = DeviceHive(ApiCallHandler, call, *call_args,
                                 **call_kwargs)
        device_hive.connect(self._transport_url, **self._options)
        return device_hive.transport.handler.handler.call_result

    def get_info(self):
        return self._call('get_info')

    def get_cluster_info(self):
        return self._call('get_cluster_info')

from devicehive.handler import Handler
from devicehive.device_hive import DeviceHive


class ApiCallHandler(Handler):
    """Api call handler class."""

    def __init__(self, api, call, *call_args, **call_kwargs):
        super(ApiCallHandler, self).__init__(api)
        self._call = call
        self._call_args = call_args
        self._call_kwargs = call_kwargs
        self._call_result = None

    @property
    def call_result(self):
        return self._call_result

    def handle_connect(self):
        self._call_result = getattr(self.api, self._call)(*self._call_args,
                                                          **self._call_kwargs)
        self.api.disconnect()


class DeviceHiveApi(object):
    """Device hive api class."""

    def __init__(self, transport_url, **options):
        self._transport_url = transport_url
        self._options = options

    def _call(self, call, *call_args, **call_kwargs):
        device_hive = DeviceHive(ApiCallHandler, call, *call_args,
                                 **call_kwargs)
        device_hive.connect(self._transport_url, **self._options)
        return device_hive.transport.handler.handler.call_result

    def get_info(self):
        return self._call('get_info')

    def get_cluster_info(self):
        return self._call('get_cluster_info')

    def get_property(self, name):
        return self._call('get_property', name)

    def set_property(self, name, value):
        return self._call('set_property', name, value)

    def delete_property(self, name):
        return self._call('delete_property', name)

Add get_property, set_property and delete_property functions
Add get_property, set_property and delete_property functions

  from devicehive.handler import Handler
  from devicehive.device_hive import DeviceHive
  
  
  class ApiCallHandler(Handler):
      """Api call handler class."""
  
      def __init__(self, api, call, *call_args, **call_kwargs):
          super(ApiCallHandler, self).__init__(api)
          self._call = call
          self._call_args = call_args
          self._call_kwargs = call_kwargs
          self._call_result = None
  
      @property
      def call_result(self):
          return self._call_result
  
      def handle_connect(self):
          self._call_result = getattr(self.api, self._call)(*self._call_args,
                                                            **self._call_kwargs)
          self.api.disconnect()
  
  
  class DeviceHiveApi(object):
      """Device hive api class."""
  
      def __init__(self, transport_url, **options):
          self._transport_url = transport_url
          self._options = options
  
      def _call(self, call, *call_args, **call_kwargs):
          device_hive = DeviceHive(ApiCallHandler, call, *call_args,
                                   **call_kwargs)
          device_hive.connect(self._transport_url, **self._options)
          return device_hive.transport.handler.handler.call_result
  
      def get_info(self):
          return self._call('get_info')
  
      def get_cluster_info(self):
          return self._call('get_cluster_info')
  
+     def get_property(self, name):
+         return self._call('get_property', name)
+ 
+     def set_property(self, name, value):
+         return self._call('set_property', name, value)
+ 
+     def delete_property(self, name):
+         return self._call('delete_property', name)
+ 
Add get_property, set_property and delete_property functions
## Code Before:
from devicehive.handler import Handler
from devicehive.device_hive import DeviceHive


class ApiCallHandler(Handler):
    """Api call handler class."""

    def __init__(self, api, call, *call_args, **call_kwargs):
        super(ApiCallHandler, self).__init__(api)
        self._call = call
        self._call_args = call_args
        self._call_kwargs = call_kwargs
        self._call_result = None

    @property
    def call_result(self):
        return self._call_result

    def handle_connect(self):
        self._call_result = getattr(self.api, self._call)(*self._call_args,
                                                          **self._call_kwargs)
        self.api.disconnect()


class DeviceHiveApi(object):
    """Device hive api class."""

    def __init__(self, transport_url, **options):
        self._transport_url = transport_url
        self._options = options

    def _call(self, call, *call_args, **call_kwargs):
        device_hive = DeviceHive(ApiCallHandler, call, *call_args,
                                 **call_kwargs)
        device_hive.connect(self._transport_url, **self._options)
        return device_hive.transport.handler.handler.call_result

    def get_info(self):
        return self._call('get_info')

    def get_cluster_info(self):
        return self._call('get_cluster_info')

## Instruction:
Add get_property, set_property and delete_property functions
## Code After:
from devicehive.handler import Handler
from devicehive.device_hive import DeviceHive


class ApiCallHandler(Handler):
    """Api call handler class."""

    def __init__(self, api, call, *call_args, **call_kwargs):
        super(ApiCallHandler, self).__init__(api)
        self._call = call
        self._call_args = call_args
        self._call_kwargs = call_kwargs
        self._call_result = None

    @property
    def call_result(self):
        return self._call_result

    def handle_connect(self):
        self._call_result = getattr(self.api, self._call)(*self._call_args,
                                                          **self._call_kwargs)
        self.api.disconnect()


class DeviceHiveApi(object):
    """Device hive api class."""

    def __init__(self, transport_url, **options):
        self._transport_url = transport_url
        self._options = options

    def _call(self, call, *call_args, **call_kwargs):
        device_hive = DeviceHive(ApiCallHandler, call, *call_args,
                                 **call_kwargs)
        device_hive.connect(self._transport_url, **self._options)
        return device_hive.transport.handler.handler.call_result

    def get_info(self):
        return self._call('get_info')

    def get_cluster_info(self):
        return self._call('get_cluster_info')

    def get_property(self, name):
        return self._call('get_property', name)

    def set_property(self, name, value):
        return self._call('set_property', name, value)

    def delete_property(self, name):
        return self._call('delete_property', name)
