Skip to content

Commit

Permalink
adding missing options methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bigoulours committed May 20, 2023
1 parent ce7bd23 commit 77fe341
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ __pycache__
.vscode

build
dist
dist

slskd.yml
test.py
62 changes: 53 additions & 9 deletions slskd_api/apis/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,56 @@ def get_startup(self) -> dict:
return response.json()


# Getting error 'Unauthorized'(API-Key) or 'Forbidden' (token):
# def get_debug(self) -> dict:
# """
# Gets the debug view of the current application options.
# """
# url = self.api_url + '/options/debug'
# response = requests.get(url, headers=self.header)
# return response.json()

def debug(self) -> str:
"""
Gets the debug view of the current application options.
debug and remote_configuration must be set to true.
Only works with token (usr/pwd login). 'Unauthorized' with API-Key.
"""
url = self.api_url + '/options/debug'
response = requests.get(url, headers=self.header)
return response.json()


def yaml_location(self) -> str:
"""
Gets the path of the yaml config file. remote_configuration must be set to true.
Only works with token (usr/pwd login). 'Unauthorized' with API-Key.
"""
url = self.api_url + '/options/yaml/location'
response = requests.get(url, headers=self.header)
return response.json()


def download_yaml(self) -> str:
"""
Gets the content of the yaml config file as text. remote_configuration must be set to true.
Only works with token (usr/pwd login). 'Unauthorized' with API-Key.
"""
url = self.api_url + '/options/yaml'
response = requests.get(url, headers=self.header)
return response.json()


def upload_yaml(self, yaml_content: str) -> bool:
"""
Sets the content of the yaml config file. remote_configuration must be set to true.
Only works with token (usr/pwd login). 'Unauthorized' with API-Key.
:return: True if successful.
"""
url = self.api_url + '/options/yaml'
response = requests.post(url, headers=self.header, json=yaml_content)
return response.ok


def validate_yaml(self, yaml_content: str) -> str:
"""
Validates the provided yaml string. remote_configuration must be set to true.
Only works with token (usr/pwd login). 'Unauthorized' with API-Key.
:return: Empty string if validation successful. Error message otherwise.
"""
url = self.api_url + '/options/yaml/validate'
response = requests.post(url, headers=self.header, json=yaml_content)
return response.text

0 comments on commit 77fe341

Please sign in to comment.