N4S4 / synology-api

A Python wrapper around Synology API
MIT License
399 stars 145 forks source link

Use a decorator method to make api calls. #11

Closed amack-zing closed 5 years ago

amack-zing commented 5 years ago

See this issue first: https://github.com/N4S4/synology-api/issues/7

Each api call in each class currently repeats a lot of the same code over and over. Using a decorator function could easily reduce the number of instances of the repeating code to one. This will be especially easy to do if https://github.com/N4S4/synology-api/issues/9 is implemented.

The decorator function would be defined as a method in the "Authentication" class:

def api_call(self, function):
        ...

and then can be used in each other class as so:

class DownloadStation(Authentication):
        @self.api_call
        def get_info(self):
                ...

Writing new methods and changing existing ones becomes much easier.

amack-zing commented 5 years ago

As noted in the comments of #7 , Synology.api_call is the correct syntax instead of self.api_call.