Skip to content

Commit

Permalink
Add more API objects. Switch to new API format (#8)
Browse files Browse the repository at this point in the history
* add more API objects
* switch to new API format
  • Loading branch information
dmitry-sinina authored Dec 4, 2024
1 parent 23ef0c0 commit fdb7d2b
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 44 deletions.
23 changes: 23 additions & 0 deletions yeti_switch_api/orm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
from .orm_client import OrmClient # noqa: F401
from .contractor import Contractor # noqa: F401
from .contact import Contact # noqa: F401
from .account import Account # noqa: F401
from .invoice import Invoice # noqa: F401
from .invoice_originated_destination import InvoiceOriginatedDestination # noqa: F401
from .invoice_originated_network import InvoiceOriginatedNetwork # noqa: F401
from .invoice_terminated_destination import InvoiceTerminatedDestination # noqa: F401
from .invoice_terminated_network import InvoiceTerminatedNetwork # noqa: F401

from .customers_auth import CustomersAuth # noqa: F401
from .dialpeer import Dialpeer # noqa: F401
from .numberlist import Numberlist # noqa: F401
from .numberlist_item import NumberlistItem # noqa: F401
from .rateplan import Rateplan # noqa: F401
from .routing_tag import RoutingTag # noqa: F401

from .gateway import Gateway # noqa: F401
from .gateway_group import GatewayGroup # noqa: F401

from .pop import Pop # noqa: F401
from .smtp_connection import SmtpConnection # noqa: F401
from .country import Country # noqa: F401
from .network import Network # noqa: F401
from .network_type import NetworkType # noqa: F401
17 changes: 17 additions & 0 deletions yeti_switch_api/orm/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from ..base_model import BaseModel, AttributeField, RelationField


class Account(BaseModel):
class Meta:
path = "accounts"
type = "account"

contractor = RelationField("contractor")

name = AttributeField("name")
balance = AttributeField("balance")
min_balance = AttributeField("min-balance")
max_balance = AttributeField("max-balance")

def creatable_fields(self):
return ["contractor", "min_balace", "max_balance"]
6 changes: 0 additions & 6 deletions yeti_switch_api/orm/billing/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Contact(BaseModel):
class Meta:
path = "billing/contacts"
path = "contacts"
type = "contacts"

name = AttributeField("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Country(BaseModel):
class Meta:
path = "system/countries"
path = "countries"
type = "countries"

name = AttributeField("name")
Expand Down
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions yeti_switch_api/orm/gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from ..base_model import BaseModel, AttributeField, RelationField


class Gateway(BaseModel):
class Meta:
path = "gateways"
type = "gateways"

contractor = RelationField("contractor")
gateway_group = RelationField("gateway-group")
pop = RelationField("pop")

name = AttributeField("name")
enabled = AttributeField("enabled")
priority = AttributeField("priority")
weight = AttributeField("weight")
allow_origination = AttributeField("allow-origination")
allow_termination = AttributeField("allow-termination")
host = AttributeField("host")
port = AttributeField("port")
registered_aor_mode = AttributeField("registered-aor-mode-id")

REGISTERED_AOR_MODE_DISABLE = 1
REGISTERED_AOR_MODE_AS_IS = 2
REGISTERED_AOR_MODE_REPLACE_USEPART = 3

def creatable_fields(self):
return [
"contractor",
"gateway-group",
"pop",
"name",
"enabled",
"priority",
"weight",
"allow-origination",
"allow-termination",
"host",
"port",
"registered-aor-mode-id",
]
11 changes: 11 additions & 0 deletions yeti_switch_api/orm/gateway_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ..base_model import BaseModel, AttributeField, RelationField


class GatewayGroup(BaseModel):
class Meta:
path = "gateway-groups"
type = "gateway-groups"

vendor = RelationField("vendor")

name = AttributeField("name")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Invoice(BaseModel):
class Meta:
path = "billing/invoices"
path = "invoices"
type = "invoices"

account = RelationField("account")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class InvoiceOriginatedDestination(BaseModel):
class Meta:
path = "billing/invoice-originated-destinations"
path = "invoice-originated-destinations"
type = "invoice-originated-destinations"

invoice = RelationField("invoice")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class InvoiceOriginatedNetwork(BaseModel):
class Meta:
path = "billing/invoice-originated-networks"
path = "invoice-originated-networks"
type = "invoice-originated-networks"

invoice = RelationField("invoice")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class InvoiceTerminatedDestination(BaseModel):
class Meta:
path = "billing/invoice-terminated-destinations"
path = "invoice-terminated-destinations"
type = "invoice-terminated-destinations"

invoice = RelationField("invoice")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class InvoiceTerminatedNetwork(BaseModel):
class Meta:
path = "billing/invoice-terminated-networks"
path = "invoice-terminated-networks"
type = "invoice-terminated-networks"

invoice = RelationField("invoice")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Network(BaseModel):
class Meta:
path = "system/networks"
path = "networks"
type = "networks"

name = AttributeField("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class NetworkType(BaseModel):
class Meta:
path = "system/network-types"
path = "network-types"
type = "network-types"

name = AttributeField("name")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Numberlist(BaseModel):
class Meta:
path = "routing/numberlists"
path = "numberlists"
type = "numberlists"

name = AttributeField("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class NumberlistItem(BaseModel):
class Meta:
path = "routing/numberlist-items"
path = "numberlist-items"
type = "numberlist-items"

key = AttributeField("key")
Expand Down
49 changes: 35 additions & 14 deletions yeti_switch_api/orm/orm_client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
from jsonapi_requests.orm import OrmApi

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
from .contact import Contact
from .account import Account
from .invoice import Invoice
from .invoice_originated_destination import InvoiceOriginatedDestination
from .invoice_originated_network import InvoiceOriginatedNetwork
from .invoice_terminated_destination import InvoiceTerminatedDestination
from .invoice_terminated_network import InvoiceTerminatedNetwork

from .customers_auth import CustomersAuth
from .dialpeer import Dialpeer
from .numberlist import Numberlist
from .numberlist_item import NumberlistItem
from .rateplan import Rateplan
from .routing_tag import RoutingTag

from .gateway import Gateway
from .gateway_group import GatewayGroup

from .pop import Pop
from .smtp_connection import SmtpConnection
from .country import Country
from .network import Network
from .network_type import NetworkType


class OrmClient:
Expand All @@ -31,17 +44,25 @@ def __new__(cls, config, **kwargs):
def __register_models(cls):
cls.__register_model(Contractor)
cls.__register_model(Contact)
cls.__register_model(Account)
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(CustomersAuth)
cls.__register_model(Dialpeer)
cls.__register_model(Numberlist)
cls.__register_model(NumberlistItem)
cls.__register_model(Rateplan)
cls.__register_model(RoutingTag)
cls.__register_model(Gateway)
cls.__register_model(GatewayGroup)
cls.__register_model(Pop)
cls.__register_model(SmtpConnection)
cls.__register_model(Country)
cls.__register_model(Network)
cls.__register_model(NetworkType)

@classmethod
def __register_model(cls, model_class):
Expand Down
9 changes: 9 additions & 0 deletions yeti_switch_api/orm/pop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ..base_model import BaseModel, AttributeField, RelationField # noqa: F401


class Pop(BaseModel):
class Meta:
path = "pops"
type = "pops"

name = AttributeField("name")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Rateplan(BaseModel):
class Meta:
path = "routing/rateplans"
path = "rateplans"
type = "rateplans"

name = AttributeField("name")
Expand Down
6 changes: 0 additions & 6 deletions yeti_switch_api/orm/routing/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class RoutingTag(BaseModel):
class Meta:
path = "routing/routing-tags"
path = "routing-tags"
type = "routing-tags"

name = AttributeField("name")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class SmtpConnection(BaseModel):
class Meta:
path = "system/smtp-connections"
path = "smtp-connections"
type = "smtp-connections"

name = AttributeField("name")
Expand Down
4 changes: 0 additions & 4 deletions yeti_switch_api/orm/system/__init__.py

This file was deleted.

0 comments on commit fdb7d2b

Please sign in to comment.