packet/Facility.py
class Facility:
    def __init__(self, data):
        self.id = data.get("id")
        self.code = data.get("code")
        self.name = data.get("name")
        self.features = data.get("features")
        self.address = data.get("address")

    def __str__(self):
        return "%s" % self.code

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/baseapi.py
class ResponseError(Error):
    def __init__(self, resp, data, exception=None):
        if not data:
            msg = "(empty response)"
        elif not isinstance(data, dict):
            msg = str(data)
        elif "error" in data:
            msg = data["error"]
        elif "errors" in data:
            msg = ", ".join(data["errors"])
        super(ResponseError, self).__init__(
            "Error {0}: {1}".format(resp.status_code, msg), exception
        )
        self._response = resp

    @property
    def response(self):
        """The Requests response which failed"""
        return self._response
packet/IPAddress.py
class IPAddress:
    def __init__(self, data, manager):
        self.manager = manager

        self.id = data.get("id")
        self.address_family = data.get("address_family")
        self.netmask = data.get("netmask")
        self.created_at = data.get("created_at")
        self.details = data.get("details")
        self.tags = data.get("tags")
        self.public = data.get("public")
        self.cidr = data.get("cidr")
        self.management = data.get("management")
        self.enabled = data.get("enabled")
        self.global_ip = data.get("global_ip")
        self.customdata = data.get("customdata")
        self.project = data.get("project")
        self.project_lite = data.get("project_lite")
        self.details = data.get("details")
        self.assigned_to = data.get("assigned_to")
        self.interface = data.get("interface")
        self.network = data.get("network")
        self.address = data.get("address")
        self.gateway = data.get("gateway")

        facility = data.get("facility")
        self.facility = Facility(facility) if facility else None
        metro = data.get("metro")
        self.metro = Metro(metro) if metro else None

    def delete(self):
        return self.manager.call_api("ips/%s" % self.id, type="DELETE")

    def __str__(self):
        return "%s" % self.code

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Provider.py
class Provider:
    def __init__(self, data):
        self.id = data.get("id")
        self.name = data.get("name")
        self.status = data.get("status")
        self.type = data.get("type")
        self.public = data.get("public")

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Snapshot.py
class Snapshot:
    def __init__(self, data):
        self.id = data.get("id")
        self.status = data.get("status")
        self.timestamp = data.get("timestamp")
        self.created_at = data.get("created_at")
        self.volume = data.get("volume")

    def __str__(self):
        return "%s" % self.name

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Organization.py
class Organization:
    def __init__(self, data):
        self.id = data.get("id")
        self.name = data.get("name")
        self.description = data.get("description")
        self.website = data.get("website")
        self.twitter = data.get("twitter")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")
        self.tax_id = data.get("tax_id")
        self.main_phone = data.get("main_phone")
        self.billing_phone = data.get("billing_phone")
        self.credit_amount = data.get("credit_amount")
        self.personal = data.get("personal")
        self.customdata = data.get("customdata")
        self.attn = data.get("attn")
        self.purchase_order = data.get("purchase_order")
        self.billing_name = data.get("billing_name")
        self.enforce_2fa = data.get("enforce_2fa")
        self.enforce_2fa_at = data.get("enforce_2fa_at")
        self.short_id = data.get("short_id")
        self.account_id = data.get("account_id")
        self.enabled_features = data.get("enabled_features")
        self.maintenance_email = data.get("maintenance_email")
        self.abuse_email = data.get("abuse_email")
        self.address = data.get("address")
        self.billing_address = data.get("billing_address")
        self.account_manager = data.get("account_manager")
        self.logo = data.get("logo")
        self.logo_thumb = data.get("logo_thumb")
        self.projects = data.get("projects")
        self.plan = data.get("plan")
        self.monthly_spend = data.get("monthly_spend")
        self.current_user_abilities = data.get("current_user_abilities")
        self.href = data.get("href")

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/HardwareReservation.py
class HardwareReservation:
    def __init__(self, data, manager):
        self.manager = manager

        self.id = data.get("id")
        self.created_at = data.get("created_at")
        self.billing_cycle = data.get("billing_cycle")
        self.created_at = data.get("created_at")
        self.short_id = data.get("short_id")
        self.intervals = data.get("intervals")
        self.current_period = data.get("current_period")
        self.started_at = data.get("started_at")
        self.custom_rate = data.get("custom_rate")
        self.remove_at = data.get("remove_at")
        self.project = data.get("project")
        # self.facility = data.get("facility")
        self.device = data.get("device")
        self.provisionable = data.get("provisionable")
        self.spare = data.get("spare")
        self.need_of_service = data.get("need_of_service")
        self.plan = Plan(data.get("plan"))
        self.switch_uuid = data.get("switch_uuid")

        try:
            project_data = self.manager.call_api(data["project"]["href"], type="GET")
            self.project = Project(project_data, self.manager)
        except (KeyError, IndexError):
            self.attached_to = None

        # endpoint is not working yet
        # try:
        #     facility_data = self.manager.call_api(
        #         data["facility"]["href"], type="GET"
        #     )
        #     self.project = Facility(facility_data, self.manager)
        # except (KeyError, IndexError):
        #     self.attached_to = None

        try:
            device_data = self.manager.call_api(data["device"]["href"], type="GET")
            self.device = Device(device_data, self.manager)
        except (KeyError, IndexError, TypeError):
            self.attached_to = None

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)

    def __getitem__(self, item):
        return getattr(self, item)
packet/OperatingSystem.py
class OperatingSystem(object):
    def __init__(self, data):
        self.slug = data.get("slug")
        self.name = data.get("name")
        self.distro = data.get("distro")
        self.version = data.get("version")
        self.provisionable_on = data.get("provisionable_on")

    def __str__(self):
        return "%s %s %s %s" % (self.slug, self.name, self.distro, self.version)

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.slug)
packet/BGPConfig.py
class BGPConfig:
    def __init__(self, data):
        self.id = data.get("id")
        self.status = data.get("status")
        self.deployment_type = data.get("deployment_type")
        self.asn = data.get("asn")
        self.md5 = data.get("md5")
        self.route_object = data.get("route_object")
        self.max_prefix = data.get("max_prefix")
        self.created_at = data.get("created_at")
        self.requested_at = data.get("requested_at")
        self.project = data.get("project")
        self.sessions = data.get("sessions")
        self.ranges = data.get("ranges")
        self.href = data.get("href")

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/baseapi.py
class Error(Exception):
    """Base exception class for this module"""

    def __init__(self, msg, cause=None):
        super(Error, self).__init__(msg)
        self._cause = cause

    @property
    def cause(self):
        """The underlying exception causing the error, if any."""
        return self._cause
packet/Vlan.py
class Vlan:
    def __init__(self, data, manager):
        self.manager = manager
        if data is None:
            return

        self.id = data.get("id")
        self.description = data.get("description")
        self.vxlan = data.get("vxlan")
        self.internet_gateway = data.get("internet_gateway")
        self.facility_code = data.get("facility_code")
        self.metro_code = data.get("metro_code")
        self.created_at = data.get("created_at")
        facility = data.get("facility")
        self.facility = Facility(facility) if facility else None
        metro = data.get("metro")
        self.metro = Metro(metro) if metro else None

        try:
            project_data = self.manager.call_api(
                data["assigned_to"]["href"], type="GET"
            )
            self.assigned_to = Project(project_data, self.manager)
        except (KeyError, IndexError):
            self.attached_to = None

    def get(self):
        return self.manager.call_api("virtual-networks/%s" % self.id, type="GET")

    def delete(self):
        return self.manager.call_api("virtual-networks/%s" % self.id, type="DELETE")

    def create_internet_gateway(self, ip_reservation_length):
        """:param ip_reservation_length:  (required) number of IP addresses possible 8 or 16"""
        params = {"length": ip_reservation_length}
        return self.manager.call_api(
            "/virtual-networks/%s/internet-gateways" % self.id,
            type="POST",
            params=params,
        )

    def assign_native_vlan(self, port_id):
        params = {"vnid": self.id}
        return self.manager.call_api(
            "/ports/%s/native-vlan" % port_id, type="POST", params=params
        )

    def remove_native_vlan(self, port_id):
        return self.manager.call_api("/ports/%s/native-vlan" % port_id, type="DELETE")

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/baseapi.py
class BaseAPI(object):
    """
        Basic api class for
    """

    def __init__(self, auth_token, consumer_token, user_agent=""):
        self.auth_token = auth_token
        self.consumer_token = consumer_token
        self.end_point = "api.packet.net"
        self._user_agent_prefix = user_agent
        self._log = logging.getLogger(__name__)

    @property
    def user_agent(self):
        return "{}packet-python/{} {}".format(
            self._user_agent_prefix, __version__, requests.utils.default_user_agent()
        ).strip()

    def call_api(self, method, type="GET", params=None):  # noqa
        if params is None:
            params = {}

        url = "https://" + self.end_point + "/" + method

        headers = {
            "X-Auth-Token": self.auth_token,
            "X-Consumer-Token": self.consumer_token,
            "Content-Type": "application/json",
            "User-Agent": self.user_agent,
        }

        # remove token from log
        headers_str = str(headers).replace(self.auth_token.strip(), "TOKEN")
        self._log.debug("%s %s %s %s" % (type, url, params, headers_str))
        try:
            if type == "GET":
                url = url + "%s" % self._parse_params(params)
                resp = requests.get(url, headers=headers)
            elif type == "POST":
                resp = requests.post(
                    url,
                    headers=headers,
                    data=json.dumps(
                        params, default=lambda o: o.__dict__, sort_keys=True, indent=4
                    ),
                )
            elif type == "DELETE":
                resp = requests.delete(url, headers=headers)
            elif type == "PATCH":
                resp = requests.patch(url, headers=headers, data=json.dumps(params))
            else:
                raise Error(
                    "method type not recognized as one of GET, POST, DELETE or PATCH: %s"
                    % type
                )
        except requests.exceptions.RequestException as e:  # pragma: no cover
            raise Error("Communcations error: %s" % str(e), e)

        if not resp.content:
            data = None
        elif resp.headers.get("content-type", "").startswith("application/json"):
            try:
                data = resp.json()
            except ValueError as e:  # pragma: no cover
                raise JSONReadError("Read failed: %s" % e.message, e)
        else:
            data = resp.content  # pragma: no cover

        if not resp.ok:  # pragma: no cover
            raise ResponseError(resp, data)

        try:
            resp.raise_for_status()
        except requests.HTTPError as e:  # pragma: no cover
            raise ResponseError(resp, data, e)

        self.meta = None
        try:
            if data and data["meta"]:
                self.meta = data["meta"]
        except (KeyError, IndexError):
            pass

        return data

    def _parse_params(self, params):
        vals = list()
        for k, v in params.items():
            vals.append(str("%s=%s" % (k, v)))
        return "?" + "&".join(vals)
packet/SSHKey.py
class SSHKey:
    def __init__(self, data, manager):
        self.manager = manager

        self.id = data.get("id")
        self.key = data.get("key")
        self.label = data.get("label")
        self.fingerprint = data.get("fingerprint")
        self.href = data.get("href")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")

        try:
            self.owner = data["owner"]["href"]
        except (KeyError, TypeError):
            self.owner = None

    def update(self):
        params = {"label": self.label, "key": self.key}

        return self.manager.call_api(
            "ssh-keys/%s" % self.id, type="PATCH", params=params
        )

    def delete(self):
        return self.manager.call_api("ssh-keys/%s" % self.id, type="DELETE")

    def __str__(self):
        return "%s %s" % (self.id, self.label)

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Event.py
class Event:
    def __init__(self, data):
        self.id = data.get("id")
        self.type = data.get("type")
        self.body = data.get("body")
        self.state = data.get("state")
        self.created_at = data.get("created_at")
        self.modified_by = data.get("modified_by")
        self.ip = data.get("ip")
        self.interpolated = data.get("interpolated")

    def __str__(self):
        return "%s" % self.interpolated

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Batch.py
class Batch:
    def __init__(self, data):
        self.id = data.get("id")
        self.error_messages = data.get("error_messages")
        self.quantity = data.get("quantity")
        self.state = data.get("state")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")
        self.devices = data.get("devices")
        self.project = data.get("project")
        self.state = data.get("state")
        self.error_messages = data.get("error_messages")

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Volume.py
class Volume:
    def __init__(self, data, manager):
        self.manager = manager
        if data is None:
            return

        self.id = data.get("id")
        self.name = data.get("name")
        self.description = data.get("description")
        self.size = data.get("size")
        self.state = data.get("state")
        self.locked = data.get("locked")
        self.billing_cycle = data.get("billing_cycle")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")
        self.attachments = data.get("attachments")

        self.plan = Plan(data.get("plan"))
        self.facility = Facility(data.get("facility"))
        try:
            self.attached_to = data["attachments"][0]["device"]["id"]
        except (KeyError, IndexError):
            self.attached_to = None

    def update(self):
        params = {
            "description": self.description,
            "size": self.size,
            "plan": self.plan.slug,
            "locked": self.locked,
        }

        return self.manager.call_api(
            "storage/%s" % self.id, type="PATCH", params=params
        )

    def delete(self):
        return self.manager.call_api("storage/%s" % self.id, type="DELETE")

    def attach(self, device_id):
        params = {"device_id": device_id}
        return self.manager.call_api(
            "storage/%s/attachments" % self.id, type="POST", params=params
        )

    def detach(self):
        for attachment in self.attachments:
            return self.manager.call_api(attachment["href"], type="DELETE")

    def list_snapshots(self, params={}):
        data = self.manager.call_api("storage/%s/snapshots" % (self.id))
        snapshots = list()
        for jsoned in data["snapshots"]:
            snapshot = VolumeSnapshot(jsoned, self)
            snapshots.append(snapshot)
        return snapshots

    def create_snapshot(self):
        self.manager.call_api("storage/%s/snapshots" % self.id, type="POST")

    def create_snapshot_policy(self, frequency, count):
        """Creates a new snapshot policy of your volume.

        :param frequency:  (required) Snapshot frequency

        Validation of `frequency` is left to the packet api to avoid going out
        of date if any new value is introduced.
        The currently known values are:
          - 1hour,
          - 1day
          - 1week
          - 1month
          - 1year
        """
        data = self.manager.call_api(
            "storage/{0}/snapshot-policies?snapshot_frequency={1}&snapshot_count={2}".format(
                self.id, frequency, count
            ),
            type="POST",
        )
        return SnapshotPolicy(data, self)

    def clone(self):
        return Volume(
            self.manager.call_api("storage/%s/clone" % self.id, type="POST"),
            manager=self.manager,
        )

    def restore(self, restore_point):
        self.manager.restore_volume(self.id, restore_point=restore_point)

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Metro.py
class Metro:
    def __init__(self, data):
        self.id = data.get("id")
        self.code = data.get("code")
        self.name = data.get("name")
        self.country = data.get("country")

    def __str__(self):
        return "%s" % self.code

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Project.py
class Project:
    def __init__(self, data, manager):
        self.manager = manager

        self.id = data.get("id")
        self.name = data.get("name")
        self.payment_method = data.get("payment_method", [])
        self.max_projects = data.get("max_devices")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")
        self.devices = data.get("devices")
        self.invitations = data.get("invitations")
        self.memberships = data.get("memberships")
        self.members = data.get("members")
        self.ssh_keys = data.get("ssh_keys")

    def update(self):
        params = {"name": self.name}

        return self.manager.call_api(
            "projects/%s" % self.id, type="PATCH", params=params
        )

    def delete(self):
        return self.manager.call_api("projects/%s" % self.id, type="DELETE")

    def __str__(self):
        return "%s" % self.name

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Plan.py
class Plan:
    def __init__(self, data):
        self.id = data.get("id")
        self.name = data.get("name")
        self.slug = data.get("slug")
        self.line = data.get("line")
        self.pricing = data.get("pricing")
        self.specs = data.get("specs")
        self.description = data.get("description")
        self.available_in = data.get("available_in")

    def __str__(self):
        return "%s" % self.slug

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/Device.py
class Device:
    def __init__(self, data, manager):
        self.manager = manager

        self.id = data.get("id")
        self.short_id = data.get("short_id")
        self.hostname = data.get("hostname")
        self.description = data.get("description")
        self.state = data.get("state")
        self.tags = data.get("tags")
        self.image_url = data.get("image_url")
        self.billing_cycle = data.get("billing_cycle")
        self.user = data.get("user")
        self.iqn = data.get("iqn")
        self.locked = data.get("locked")
        self.bonding_mode = data.get("bonding_mode")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")
        self.ipxe_script_url = data.get("ipxe_script_url")
        self.always_pxe = data.get("always_pxe", False)
        self.storage = data.get("storage")
        self.customdata = data.get("customdata")
        self.operating_system = OperatingSystem(data["operating_system"])
        self.facility = data.get("facility")
        self.metro = data.get("metro")
        self.project = data.get("project")
        self.ssh_keys = data.get("ssh_keys")
        self.project_lite = data.get("project_lite")
        self.volumes = data.get("volumes")
        self.ip_addresses = data.get("ip_addresses")
        self.plan = data.get("plan")
        self.userdata = data.get("userdata")
        self.switch_uuid = data.get("switch_uuid")
        self.network_ports = data.get("network_ports")
        self.href = data.get("href")
        self.spot_instance = data.get("spot_instance", False)
        self.hardware_reservation_id = data.get("hardware_reservation_id")
        self.spot_price_max = data.get("spot_price_max")
        self.termination_time = data.get("termination_time")
        self.root_password = data.get("root_password")
        self.provisioning_percentage = data.get("provisioning_percentage")

    def update(self):
        params = {
            "hostname": self.hostname,
            "locked": self.locked,
            "tags": self.tags,
            "description": self.description,
            "billing_cycle": self.billing_cycle,
            "userdata": self.userdata,
            "always_pxe": self.always_pxe,
            "ipxe_script_url": self.ipxe_script_url,
            "spot_instance": self.spot_instance,
            "customdata": self.customdata,
        }

        return self.manager.call_api(
            "devices/%s" % self.id, type="PATCH", params=params
        )

    def delete(self):
        return self.manager.call_api("devices/%s" % self.id, type="DELETE")

    def reinstall(self, operating_system=None, ipxe_script_url=None):
        params = {"type": "reinstall"}
        if operating_system is not None:
            params["operating_system"] = operating_system
        if ipxe_script_url is not None:
            params["operating_system"] = "custom_ipxe"
            params["ipxe_script_url"] = ipxe_script_url

        return self.manager.call_api(
            "devices/%s/actions" % self.id, type="POST", params=params
        )

    def power_off(self):
        params = {"type": "power_off"}
        return self.manager.call_api(
            "devices/%s/actions" % self.id, type="POST", params=params
        )

    def power_on(self):
        params = {"type": "power_on"}
        return self.manager.call_api(
            "devices/%s/actions" % self.id, type="POST", params=params
        )

    def reboot(self):
        params = {"type": "reboot"}
        return self.manager.call_api(
            "devices/%s/actions" % self.id, type="POST", params=params
        )

    def rescue(self):
        params = {"type": "rescue"}
        return self.manager.call_api(
            "devices/%s/actions" % self.id, type="POST", params=params
        )

    def ips(self):
        return self.manager.list_device_ips(self.id)

    def __str__(self):
        return "%s" % self.hostname

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)

    def __getitem__(self, item):
        return getattr(self, item)
packet/Email.py
class Email:
    def __init__(self, data, manager):
        self.manager = manager

        self.id = data.get("id")
        self.address = data.get("address")
        self.default = data.get("default")
        self.verified = data.get("verified")

    def update(self):
        params = {"address": self.address, "default": self.default}

        return self.manager.call_api("emails/%s" % self.id, type="PATCH", params=params)

    def delete(self):
        return self.manager.call_api("emails/%s" % self.id, type="DELETE")

    def __str__(self):
        return "%s" % self.address

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)
packet/BGPSession.py
class BGPSession:
    def __init__(self, data):
        self.id = data.get("id")
        self.status = data.get("status")
        self.learned_routes = data.get("learned_routes")
        self.switch_name = data.get("switch_name")
        self.default_route = data.get("default_route")
        self.created_at = data.get("created_at")
        self.updated_at = data.get("updated_at")
        self.device = data.get("device")
        self.address_family = data.get("address_family")
        self.href = data.get("href")

    def __str__(self):
        return "%s" % self.id

    def __repr__(self):
        return "{}: {}".format(self.__class__.__name__, self.id)


Question: from packet.Vlan import Vlan
from .baseapi import BaseAPI
from .baseapi import Error as PacketError
from .baseapi import ResponseError
from .Batch import Batch
from .Plan import Plan
from .Device import Device
from .SSHKey import SSHKey
from .Project import Project
from .Facility import Facility
from .Metro import Metro
from .OperatingSystem import OperatingSystem
from .Volume import Volume
from .BGPConfig import BGPConfig
from .BGPSession import BGPSession
from .IPAddress import IPAddress
from .HardwareReservation import HardwareReservation
from .Snapshot import Snapshot
from .Organization import Organization
from .Email import Email
from .Event import Event
from .Provider import Provider
            "quantity": quantity,
            "details": details,
            "comments": comments,
            "tags": tags,
        }

        if facility != "":
            request["facility"] = facility
        if metro != "":
            request["metro"] = metro
        data = self.call_api(
            "/projects/%s/ips" % project_id, params=request, type="POST"
        )
        return IPAddress(data, self)

    # Batches
    def create_batch(self, project_id, params):
        param = {"batches": params}
        data = self.call_api(
            "/projects/%s/devices/batch" % project_id, type="POST", params=param
        )
        batches = list()
        for b in data["batches"]:
            batch = Batch(b)
            batches.append(batch)
        return batches

    def list_batches(self, project_id, params=None):
        data = self.call_api(
            "/projects/%s/batches" % project_id, type="GET", params=params
        )
        batches = list()
        for b in data["batches"]:
            batch = Batch(b)
            batches.append(batch)
        return batches

    def delete_batch(self, batch_id, remove_associated_instances=False):
        self.call_api(
            "/batches/%s" % batch_id, type="DELETE", params=remove_associated_instances
        )

    # Snapshots
    def get_snapshots(self, volume_id, params=None):
        data = self.call_api(
            "storage/%s/snapshots" % volume_id, type="GET", params=params
        )
        snapshots = list()
        for ss in data["snapshots"]:
            snapshot = Snapshot(ss)
            snapshots.append(snapshot)

        return snapshots

    def restore_volume(self, volume_id, restore_point):
        params = {"restore_point": restore_point}
        self.call_api("storage/%s/restore" % volume_id, type="POST", params=params)

    # Organization
    def list_organizations(self, params=None):
        data = self.call_api("organizations", type="GET", params=params)
        orgs = list()
        for org in data["organizations"]:
            o = Organization(org)
            orgs.append(o)

        return orgs

    def get_organization(self, org_id, params=None):
        data = self.call_api("organizations/%s" % org_id, type="GET", params=params)
        return Organization(data)

    def list_organization_projects(self, org_id, params=None):
        data = self.call_api(
            "organizations/%s/projects" % org_id, type="GET", params=params
        )
        projects = list()
        for p in data["projects"]:
            projects.append(Project(p, self))

        return projects

    def list_organization_devices(self, org_id, params=None):
        data = self.call_api(
            "organizations/%s/devices" % org_id, type="GET", params=params
        )
        devices = list()
        for d in data["devices"]:
            devices.append(Device(d, self))

        return devices

    def create_organization_project(
        self, org_id, name, payment_method_id=None, customdata=None
    ):
        params = {
            "name": name,
            "payment_method_id": payment_method_id,
            "customdata": customdata,
        }
        data = self.call_api(
            "organizations/%s/projects" % org_id, type="POST", params=params
        )
        return Project(data, self)

    # Email
    def add_email(self, address, default=False):
        params = {"address": address, "default": default}
        data = self.call_api("emails", type="POST", params=params)
        return Email(data, self)

    def get_email(self, email_id):
        data = self.call_api("emails/%s" % email_id)
        return Email(data, self)

    # Event
    def list_events(self, params=None):
        data = self.call_api("events", type="GET", params=params)
        events = list()
        for e in data["events"]:

Answer:             events.append(Event(e))