def voicemail_messages(self, mailbox, **kwargs): """ Retrieves a list of Voicemail Messages if mailbox parameter is provided - Retrieves a list of Voicemail Messages in a Folder if a folder is provided - Retrieves a list of Voicemail Messages in a date range if a from and to are provided :param mailbox: [Required] ID for a specific Mailbox (Example: 1001) :type mailbox: :py:class:`int` :param folder: Name for specific Folder (Required if message id is passed, Example: 'INBOX', values from: voicemail.voicemail_folders) :type folder: :py:class:`str` :param date_from: Start Date for Filtering Voicemail Messages (Example: '2016-01-30') :type date_from: :py:class:`str` :param date_to: End Date for Filtering Voicemail Messages (Example: '2016-01-30') :type date_to: :py:class:`str` :returns: :py:class:`dict` """ method = "getVoicemailMessages" if not isinstance(mailbox, int): raise ValueError( "ID for a specific Mailbox needs to be an int (Example: 1001)") parameters = { "mailbox": mailbox, } if "folder" in kwargs: if not isinstance(kwargs["folder"], str): raise ValueError( "Name for specific Folder needs to be a str (Required if message id is passed, Example: 'INBOX', values from: voicemail.voicemail_folders)" ) parameters["folder"] = kwargs.pop("folder") if "date_from" in kwargs: if not isinstance(kwargs["date_from"], str): raise ValueError( "Start Date for Filtering Voicemail Messages needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["date_from"]) parameters["date_from"] = kwargs.pop("date_from") if "date_to" in kwargs: if not isinstance(kwargs["date_to"], str): raise ValueError( "End Date for Filtering Voicemail Messages needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["date_to"]) parameters["date_to"] = kwargs.pop("date_to") if len(kwargs) > 0: not_allowed_parameters = "" for key, value in kwargs.items(): not_allowed_parameters += key + " " raise ValueError( "Parameters not allowed: {}".format(not_allowed_parameters)) return self._voipms_client._get(method, parameters)
def fax_messages(self, **kwargs): """ Retrieves a list of Fax Messages :param from: Start Date for Filtering Fax Messages (Example: '2014-03-30') - Default value: Today :type from: :py:class:`str` :param to: End Date for Filtering Fax Messages (Example: '2014-03-30') - Default value: Today :type to: :py:class:`str` :param folder: Name of specific Fax Folder (Example: SENT) - Default value: ALL :type folder: :py:class:`str` :returns: :py:class:`dict` """ method = "getFaxMessages" parameters = {} if "from" in kwargs: if not isinstance(kwargs["from"], str): raise ValueError( "Start Date for Filtering Fax Messages needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["from"]) parameters["from"] = kwargs.pop("from") if "to" in kwargs: if not isinstance(kwargs["to"], str): raise ValueError( "End Date for Filtering Fax Messages needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["to"]) parameters["to"] = kwargs.pop("to") if "folder" in kwargs: if not isinstance(kwargs["folder"], str): raise ValueError( "Name of specific Fax Folder needs to be a str (Example: SENT)" ) parameters["folder"] = kwargs.pop("folder") if len(kwargs) > 0: not_allowed_parameters = "" for key, value in kwargs.items(): not_allowed_parameters += key + " " raise ValueError( "Parameters not allowed: {}".format(not_allowed_parameters)) return self._voipms_client._get(method, parameters)
def transaction_history(self, date_from, date_to): """ Retrieves the Transaction History records between two dates :param date_from: [Required] Start Date for Filtering Transactions (Example: '2016-06-03') :type date_from: :py:class:`str` :param date_to: [Required] End Date for Filtering Transactions (Example: '2016-06-04') :type date_to: :py:class:`str` :returns: :py:class:`dict` """ method = "getTransactionHistory" if not isinstance(date_from, str): raise ValueError( "Start Date for Filtering Transactions needs to be str (Example: '2016-06-03')" ) if not isinstance(date_to, str): raise ValueError( "End Date for Filtering Transactions needs to be str (Example: '2016-06-04')" ) date_from_object = validate_date(date_from) date_to_object = validate_date(date_to) if date_from_object > date_to_object: raise ValueError( "The start date needs to be ealier or the same as the end date." ) if date_to_object > datetime.now(): raise ValueError("The end date can't be in the future.") parameters = { "date_from": date_from, "date_to": date_to, } return self._voipms_client._get(method, parameters)
def connect_did(self, did, account, monthly, setup, minute, **kwargs): """ Connects a specific DID to a specific Reseller Client Sub Account :param did: [Required] DID to be canceled and deleted (Example: 5551234567) :type did: :py:class:`str` or `int` :param account: [Required] Reseller Sub Account (Example: '100001_VoIP') :type account: :py:class:`str` :param monthly: [Required] Montly Fee for Reseller Client (Example: 3.50) :type monthly: :py:class:`float` :param setup: [Required] Setup Fee for Reseller Client (Example: 1.99) :type setup: :py:class:`float` :param minute: [Required] Minute Rate for Reseller Client (Example: 0.03) :type minute: :py:class:`float` :param **kwargs: All optional parameters :type **kwargs: :py:class:`dict` :param next_billing: Next billing date (Example: '2014-03-30') :type next_billing: :py:class:`str` :param dont_charge_setup: If set to true, the setup value will not be charged after Connect :type dont_charge_setup: :py:class:`bool` :param dont_charge_monthly: If set to true, the monthly value will not be charged after Connect :type dont_charge_monthly: :py:class:`bool` :returns: :py:class:`dict` """ method = "connectDID" if isinstance(did, str): did = did.replace('.', '') try: did = int(did) except: raise ValueError( "DID to be canceled and deleted needs to be an int or str of numbers (Example: 555.123.4567 or 5551234567)" ) if not isinstance(did, int): raise ValueError( "DID to be canceled and deleted needs to be an int (Example: 5551234567)" ) if not isinstance(account, str): raise ValueError( "Reseller Sub Account needs to be a str (Example: '100001_VoIP')" ) if not isinstance(monthly, float): raise ValueError( "Montly Fee for Reseller Client needs to be a float (Example: 3.50)" ) if not isinstance(setup, float): raise ValueError( "Setup Fee for Reseller Client needs to be a float (Example: 1.99)" ) if not isinstance(minute, float): raise ValueError( "Minute Rate for Reseller Client needs to be a float (Example: 0.03)" ) parameters = { "did": did, "account": account, "monthly": monthly, "setup": setup, "minute": minute, } if "next_billing" in kwargs: if not isinstance(kwargs["next_billing"], str): raise ValueError( "Next billing date needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["next_billing"]) parameters["next_billing"] = kwargs.pop("next_billing") if "dont_charge_setup" in kwargs: if not isinstance(kwargs["dont_charge_setup"], bool): raise ValueError( "If set to True, the setup value will not be charged after Connect (needs to be bool)" ) parameters["dont_charge_setup"] = convert_bool( kwargs.pop("dont_charge_setup")) if "dont_charge_monthly" in kwargs: if not isinstance(kwargs["dont_charge_monthly"], bool): raise ValueError( "If set to True, the monthly value will not be charged after Connect (needs to be bool)" ) parameters["dont_charge_monthly"] = convert_bool( kwargs.pop("dont_charge_monthly")) if len(kwargs) > 0: not_allowed_parameters = "" for key, value in kwargs.items(): not_allowed_parameters += key + " " raise ValueError( "Parameters not allowed: {}".format(not_allowed_parameters)) return self._voipms_client._get(method, parameters)
def sms(self, **kwargs): """ Retrieves a list of SMS messages by: date range, sms type, DID number, and contact :param sms: ID for a specific SMS (Example: 5853) :type sms: :py:class:`int` :param from: Start Date for Filtering SMSs (Example: '2014-03-30') - Default value: Today :type from: :py:class:`str` :param to: End Date for Filtering SMSs (Example: '2014-03-30') - Default value: Today :type to: :py:class:`str` :param type: Filter SMSs by Type (Boolean: True = received / False = sent) :type type: :py:class:`bool` :param did: DID number for Filtering SMSs (Example: 5551234567) :type did: :py:class:`int` :param contact: Contact number for Filtering SMSs (Example: 5551234567) :type contact: :py:class:`int` :param limit: Number of records to be displayed (Example: 20) - Default value: 50 :type limit: :py:class:`int` :param timezone: Adjust time of SMSs according to Timezome (Numeric: -12 to 13) :type timezone: :py:class:`int` :returns: :py:class:`dict` """ method = "getSMS" parameters = {} if "sms" in kwargs: if not isinstance(kwargs["sms"], int): raise ValueError( "ID for a specific SMS needs to be an int (Example: 5853)") parameters["sms"] = kwargs.pop("sms") if "from" in kwargs: if not isinstance(kwargs["from"], str): raise ValueError( "Start Date for Filtering SMSs needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["from"]) parameters["from"] = kwargs.pop("from") if "to" in kwargs: if not isinstance(kwargs["to"], str): raise ValueError( "End Date for Filtering SMSs needs to be a str (Example: '2014-03-30')" ) validate_date(kwargs["to"]) parameters["to"] = kwargs.pop("to") if "type" in kwargs: if not isinstance(kwargs["type"], bool): raise ValueError( "Filter SMSs by Type needs to be a bool (Boolean: True = received / False = sent)" ) parameters["type"] = convert_bool(kwargs.pop("type")) if "did" in kwargs: if not isinstance(kwargs["did"], int): raise ValueError( "DID number for Filtering SMSs needs to be an int (Example: 5551234567)" ) parameters["did"] = kwargs.pop("did") if "contact" in kwargs: if not isinstance(kwargs["contact"], int): raise ValueError( "Contact number for Filtering SMSs needs to be an int (Example: 5551234567)" ) parameters["contact"] = kwargs.pop("contact") if "limit" in kwargs: if not isinstance(kwargs["limit"], int): raise ValueError( "Number of records to be displayed needs to be an int (Example: 20)" ) parameters["limit"] = kwargs.pop("limit") if "timezone" in kwargs: if not isinstance(kwargs["timezone"], int): raise ValueError( "Adjust time of SMSs according to Timezome needs to be an int (Numeric: -12 to 13)" ) parameters["timezone"] = kwargs.pop("timezone") if len(kwargs) > 0: not_allowed_parameters = "" for key, value in kwargs.items(): not_allowed_parameters += key + " " raise ValueError( "Parameters not allowed: {}".format(not_allowed_parameters)) return self._voipms_client._get(method, parameters)
def sub_account(self, username, password, protocol, auth_type, device_type, lock_international, international_route, music_on_hold, allowed_codecs, dtmf_mode, nat, **kwargs): """ Adds a new Sub Account entry to your Account :param username: [Required] Username for the Sub Account (Example: 'VoIP') :type username: :py:class:`str` :param password: [Required] Sub Account Password (For Password Authentication) :type password: :py:class:`str` :param protocol: [Required] Protocol used for the Sub Account (Values from accounts.get_protocols) :type protocol: :py:class:`int` :param auth_type: [Required] Authorization Type Code (Values from accounts.get_auth_types) :type auth_type: :py:class:`int` :param device_type: [Required] Device Type Code (Values from accounts.get_device_types) :type device_type: :py:class:`int` :param lock_international: [Required] Lock International Code (Values from accounts.get_lock_international) :type lock_international: :py:class:`int` :param international_route: [Required] Route Code (Values from accounts.get_routes) :type international_route: :py:class:`int` :param music_on_hold: [Required] Music on Hold Code (Values from accounts.get_music_on_hold) :type music_on_hold: :py:class:`str` :param allowed_codecs: [Required] List of Allowed Codecs (Values from accounts.get_allowed_codecs) Codecs separated by semicolon (Example: ulaw;g729;gsm) :type allowed_codecs: :py:class:`str` :param dtmf_mode: [Required] DTMF Mode Code (Values from accounts.get_dtmf_modes) :type dtmf_mode: :py:class:`str` :param nat: [Required] NAT Mode Code (Values from accounts.get_nat) :type nat: :py:class:`str` :param **kwargs: All optional parameters :type **kwargs: :py:class:`dict` :param description: Sub Account Description (Example: 'VoIP Account') :type description: :py:class:`str` :param ip: Sub Account IP (For IP Authentication) :type ip: :py:class:`str` :param callerid_number: Caller ID Override :type callerid_number: :py:class:`str` :param canada_routing: Route Code (Values from accounts.get_routes) :type canada_routing: :py:class:`int` :param internal_extension: Sub Account Internal Extension (Example: 1 -> Creates 101) :type internal_extension: :py:class:`int` :param internal_voicemail: Sub Account Internal Voicemail (Example: 101) :type internal_voicemail: :py:class:`str` :param internal_dialtime: Sub Account Internal Dialtime (Example: 60 -> seconds) :type internal_dialtime: :py:class:`int` :param reseller_client: Reseller Account ID (Example: 561115) :type reseller_client: :py:class:`int` :param reseller_package: Reseller Package (Example: 92364) :type reseller_package: :py:class:`int` :param reseller_nextbilling: Reseller Next Billing Date (Example: '2012-12-31') :type reseller_nextbilling: :py:class:`str` :param reseller_chargesetup: True if you want to charge Package Setup Fee after Save :type reseller_chargesetup: :py:class:`bool` :returns: :py:class:`dict` """ method = "createSubAccount" if not isinstance(username, str): raise ValueError("Username needs to be a str") if not isinstance(password, str): raise ValueError( "Sub Account Password needs to be a str (For Password Authentication)" ) if not isinstance(protocol, int): raise ValueError( "Protocol value needs to be an int (Values from accounts.get_protocols)" ) if not isinstance(auth_type, int): raise ValueError( "Auth type value needs to be an int (Values from accounts.get_auth_types)" ) if not isinstance(device_type, int): raise ValueError( "Device type value needs to be an int (Values from accounts.get_device_types)" ) if not isinstance(lock_international, int): raise ValueError( "Lock International Code value needs to be an int (Values from accounts.get_lock_international)" ) if not isinstance(international_route, int): raise ValueError( "Route Code value needs to be an int (Values from accounts.get_routes)" ) if not isinstance(music_on_hold, str): raise ValueError( "Music on Hold Code value needs to be str (Values from accounts.get_music_on_hold)" ) if not isinstance(allowed_codecs, str): raise ValueError( "List of Allowed Codecs value needs to be str (Values from accounts.get_allowed_codecs)" ) if not isinstance(dtmf_mode, str): raise ValueError( "DTMF Mode Code (Values from needs to be str accounts.get_dtmf_modes)" ) if not isinstance(nat, str): raise ValueError( "DTMF Mode Code (Values from needs to be str accounts.get_nat)" ) parameters = { "username": username, "password": password, "protocol": protocol, "auth_type": auth_type, "device_type": device_type, "lock_international": lock_international, "international_route": international_route, "music_on_hold": music_on_hold, "allowed_codecs": allowed_codecs, "dtmf_mode": dtmf_mode, "nat": nat, } if "description" in kwargs: if not isinstance(kwargs["description"], str): raise ValueError( "Sub Account Description needs to be a str (Example: 'VoIP Account')" ) parameters["description"] = kwargs.pop("description") if "ip" in kwargs: ip = kwargs["ip"] if not isinstance(ip, str): raise ValueError( "Sub Account IP needs to be a str (For IP Authentication)") try: socket.inet_aton(ip) except socket.error: raise ValueError( "The provided IP: {} is not in the correct format (Example: 127.0.0.1)" .format(ip)) parameters["ip"] = kwargs.pop("ip") if "callerid_number" in kwargs: if not isinstance(kwargs["callerid_number"], str): raise ValueError("Caller ID Override needs to be a str") parameters["callerid_number"] = kwargs.pop("callerid_number") if "canada_routing" in kwargs: if not isinstance(kwargs["canada_routing"], int): raise ValueError( "Route Code needs to be an int (Values from accounts.get_routes)" ) parameters["canada_routing"] = kwargs.pop("canada_routing") if "internal_extension" in kwargs: if not isinstance(kwargs["internal_extension"], int): raise ValueError( "Sub Account Internal Extension needs to be an int (Example: 1 -> Creates 101)" ) parameters["internal_extension"] = kwargs.pop("internal_extension") if "internal_voicemail" in kwargs: if not isinstance(kwargs["internal_voicemail"], int): raise ValueError( "Sub Account Internal Voicemail needs to be an int (Example: 101)" ) parameters["internal_voicemail"] = kwargs.pop("internal_voicemail") if "internal_dialtime" in kwargs: if not isinstance(kwargs["internal_dialtime"], int): raise ValueError( "Sub Account Internal Dialtime needs to be an int (Example: 60 -> seconds)" ) parameters["internal_dialtime"] = kwargs.pop("internal_dialtime") if "reseller_client" in kwargs: if not isinstance(kwargs["reseller_client"], int): raise ValueError( "Reseller Account ID needs to be an int (Example: 561115)") parameters["reseller_client"] = kwargs.pop("reseller_client") if "reseller_package" in kwargs: if not isinstance(kwargs["reseller_package"], int): raise ValueError( "Reseller Package needs to be an int (Example: 92364)") parameters["reseller_package"] = kwargs.pop("reseller_package") if "reseller_nextbilling" in kwargs: reseller_nextbilling = kwargs.pop("reseller_nextbilling") if not isinstance(reseller_nextbilling, int): raise ValueError( "Reseller Next Billing Date needs to be a string (Example: '2012-12-31')" ) validate_date(reseller_nextbilling) parameters["reseller_nextbilling"] = reseller_nextbilling if "reseller_chargesetup" in kwargs: if not isinstance(kwargs["reseller_chargesetup"], bool): raise ValueError( "True if you want to charge Package Setup Fee after Save") parameters["reseller_chargesetup"] = convert_bool( kwargs.pop("reseller_chargesetup")) if len(kwargs) > 0: not_allowed_parameters = "" for key, value in kwargs.items(): not_allowed_parameters += key + " " raise ValueError( "Parameters not allowed: {}".format(not_allowed_parameters)) return self._voipms_client._get(method, parameters)