Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-sinina committed Dec 29, 2023
1 parent 3a4b103 commit 521f85c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
39 changes: 28 additions & 11 deletions examples/simple_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

from yeti_switch_api.orm import OrmClient
from yeti_switch_api.orm import Contractor
from yeti_switch_api.orm.billing import Invoice
from yeti_switch_api.orm.billing import InvoiceOriginatedDestination
from yeti_switch_api.orm.billing import InvoiceOriginatedNetwork
from yeti_switch_api.orm.billing import InvoiceTerminatedDestination
from yeti_switch_api.orm.billing import InvoiceTerminatedNetwork
from yeti_switch_api.orm.system import SmtpConnection
from yeti_switch_api.orm.system import Country
from yeti_switch_api.orm.system import Network
from yeti_switch_api.orm.system import NetworkType

# For demonstration purpose only: below lines logs all HTTP requests to stdout
#
Expand All @@ -19,10 +27,10 @@
# here library usage starts
OrmClient(
{
"API_ROOT": "http://127.0.0.1:4321/api/rest/admin",
"API_ROOT": "https://demo.yeti-switch.org/api/rest/admin",
"AUTH_CREDS": {
"login": "admin",
"password": "qweasd",
"password": "111111",
},
"VALIDATE_SSL": True,
"TIMEOUT": 1,
Expand Down Expand Up @@ -50,15 +58,15 @@
"name": "test_python",
"enabled": True,
"customer": True,
},
relationships={
"smtp-connection": {
"data": {
"type": SmtpConnection.Meta.type,
"id": found_smtp_connections[0].id,
}
}
},
}
# relationships={
# "smtp-connection": {
# "data": {
# "type": SmtpConnection.Meta.type,
# "id": found_smtp_connections[0].id,
# }
# }
# },
)
print("new_contractor before create", new_contractor.raw_object)
new_contractor.create()
Expand All @@ -74,3 +82,12 @@
print("contractor found", contractor.raw_object)

print(contractor.creatable_fields())


# get invoices
invs = Invoice.get_list()
if len(invs) == 0:
print("No invoices found")
else:
for inv in invs:
print("Invoices found:", inv.raw_object)
16 changes: 16 additions & 0 deletions yeti_switch_api/orm/orm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
from ..common import build_client_config
from .routing import Rateplan, RoutingTag
from .billing import Contact
from .billing import Invoice
from .billing import InvoiceOriginatedDestination
from .billing import InvoiceOriginatedNetwork
from .billing import InvoiceTerminatedDestination
from .billing import InvoiceTerminatedNetwork
from .contractor import Contractor
from .system import SmtpConnection
from .system import Country
from .system import Network
from .system import NetworkType


class OrmClient:
Expand All @@ -23,6 +31,14 @@ def __new__(cls, config, **kwargs):
def __register_models(cls):
cls.__register_model(Contractor)
cls.__register_model(Contact)
cls.__register_model(Invoice)
cls.__register_model(InvoiceOriginatedDestination)
cls.__register_model(InvoiceOriginatedNetwork)
cls.__register_model(InvoiceTerminatedDestination)
cls.__register_model(InvoiceTerminatedNetwork)
cls.__register_model(Country)
cls.__register_model(Network)
cls.__register_model(NetworkType)
cls.__register_model(Rateplan)
cls.__register_model(RoutingTag)
cls.__register_model(SmtpConnection)
Expand Down

0 comments on commit 521f85c

Please sign in to comment.