Skip to content

Commit

Permalink
Add User
Browse files Browse the repository at this point in the history
  • Loading branch information
devcadotio committed Feb 6, 2024
1 parent bb6fc1c commit 30c0be6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
1 change: 0 additions & 1 deletion Njalla/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ def __init__(self, api_key):
"paypal": "paypal"
}

# API functions will be added later
55 changes: 54 additions & 1 deletion Njalla/User.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
import requests
from .API import NjallaAPI


class NjallaUser:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://njal.la/api/1/"

# will be added later on
def login(self, email, password):
"""
Login into an existing account (cookie-based session).
Consider using API tokens instead
:param email: Email address
:param password: Password
"""
data = {
"method": "login",
"params": {
"email": email,
"password": password
}
}
r = requests.post(self.base_url, json=data, headers=self.headers)
result = r.json()["result"]
if "error" in r.json():
raise ValueError(r.json()["error"]["message"])
return result

def logout(self):
"""
Logout and end your current session
"""
data = {
"method": "logout",
"params": {
}
}
r = requests.post(self.base_url, json=data, headers=self.headers)
result = r.json()["result"]
if "error" in r.json():
raise ValueError(r.json()["error"]["message"])
return result

def delete_account(self):
"""
Delete your account.
You can only delete the account if all domains and servers
have been removed and your wallet is empty.
"""
data = {
"method": "delete-account",
"params": {
}
}
r = requests.post(self.base_url, json=data, headers=self.headers)
result = r.json()["result"]
if "error" in r.json():
raise ValueError(r.json()["error"]["message"])
return result
1 change: 0 additions & 1 deletion Njalla/Wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def get_balance(self):
:return: Balance (int) in EUR.
"""
data = {
"jsonrpc": "2.0",
"method": "get-balance"
}
r = requests.post(self.base_url, json=data, headers=self.headers)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = Njalla
version = 0.2.1
version = 0.3
author = Luca from DevCa
author_email= [email protected]
description = A python library built to integrate the njal.la API
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='Njalla',
version='0.2.1',
version='0.3',
packages=find_packages(),
install_requires=[
'requests'
Expand Down

0 comments on commit 30c0be6

Please sign in to comment.