Skip to content

Commit

Permalink
2.0 Update + Prism Mock Support (#67)
Browse files Browse the repository at this point in the history
* API Parity Update + Prism Mock Server

* lint/formatting changes

* more formatting changes

* prism-mock fix

* version increment

Co-authored-by: Vladii <[email protected]>
  • Loading branch information
ADandyGuyInSpace and Quagbot authored Feb 26, 2022
1 parent bee8bde commit c78e3a9
Show file tree
Hide file tree
Showing 117 changed files with 2,077 additions and 209 deletions.
18 changes: 10 additions & 8 deletions .github/scripts/before_install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
if [ ! -d "telnyx-mock/${TELNYX_MOCK_VERSION}" ]; then
mkdir -p telnyx-mock/${TELNYX_MOCK_VERSION}
curl -L "https://github.com/team-telnyx/telnyx-mock/releases/download/v${TELNYX_MOCK_VERSION}/telnyx-mock_${TELNYX_MOCK_VERSION}_linux_amd64.tar.gz" -o "telnyx-mock/${TELNYX_MOCK_VERSION}_linux_amd64.tar.gz"
tar -zxf "telnyx-mock/${TELNYX_MOCK_VERSION}_linux_amd64.tar.gz" -C "telnyx-mock/${TELNYX_MOCK_VERSION}/"
fi
telnyx-mock/${TELNYX_MOCK_VERSION}/telnyx-mock >/dev/null &
TELNYX_MOCK_PID=$!
export PATH="${PATH}:${PWD}/telnyx-mock/${TELNYX_MOCK_VERSION}"
npm install -g @stoplight/prism-cli

echo "Starting up Prism Mock Server with spec file at ${TELNYX_MOCK_OPEN_API_URI}"
prism mock ${TELNYX_MOCK_OPEN_API_URI} > /dev/null &

git clone https://github.com/team-telnyx/telnyx-prism-mock.git
cd telnyx-prism-mock/proxy
npm install
node index.js > /dev/null &
cd -
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
jobs:
test:
env:
TELNYX_MOCK_VERSION: 0.8.13
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
TELNYX_MOCK_OPEN_API_URI: https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -20,7 +20,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- uses: gabrielfalcao/pyenv-action@v7
- uses: dschep/install-pipenv-action@v1
- name: setup-telnyx-mock
- name: setup-telnyx-prism-mock
run: source ./.github/scripts/before_install.sh
- name: init
run: make init
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ htmlcov/
sonar-project.*
.pypirc-telnyx

Pipfile.lock
Pipfile.lock
requirements.txt
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run_tests(self):

setup(
name="telnyx",
version="1.5.0",
version="2.0.0",
description="Python bindings for the Telnyx API",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion telnyx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
log = None


__version__ = "1.5.0"
__version__ = "2.0.0"


# Sets some basic information about the running application that's sent along
Expand Down
2 changes: 1 addition & 1 deletion telnyx/api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def request_raw(self, method, url, params=None, supplied_headers=None):
if params:
abs_url = _build_api_url(abs_url, encoded_params)
post_data = None
elif method == "post" or method == "patch":
elif method == "post" or method == "patch" or method == "put":
if (
supplied_headers.get("Content-Type", "application/json")
== "application/json"
Expand Down
78 changes: 75 additions & 3 deletions telnyx/api_resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,63 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.access_control_ip import AccessControlIP
from telnyx.api_resources.access_ip_address import AccessIPAddress
from telnyx.api_resources.address import Address
from telnyx.api_resources.api_key import APIKey
from telnyx.api_resources.authentication_provider import AuthenticationProvider
from telnyx.api_resources.available_phone_number import AvailablePhoneNumber
from telnyx.api_resources.balance import Balance
from telnyx.api_resources.billing_group import BillingGroup
from telnyx.api_resources.brand import Brand
from telnyx.api_resources.bulk_creation import BulkCreation
from telnyx.api_resources.call import Call
from telnyx.api_resources.call_control_application import CallControlApplication
from telnyx.api_resources.campaign import Campaign
from telnyx.api_resources.comment import Comment
from telnyx.api_resources.conference import Conference
from telnyx.api_resources.connection import Connection
from telnyx.api_resources.credential_connection import CredentialConnection
from telnyx.api_resources.custom_storage_credential import CustomStorageCredential
from telnyx.api_resources.detail_records_report import DetailRecordsReport
from telnyx.api_resources.document import Document, DocumentLink
from telnyx.api_resources.dynamic_emergency_address import DynamicEmergencyAddress
from telnyx.api_resources.event import Event
from telnyx.api_resources.fax import Fax
from telnyx.api_resources.fax_application import FaxApplication
from telnyx.api_resources.fqdn import FQDN
from telnyx.api_resources.fqdn_connection import FQDNConnection
from telnyx.api_resources.inbound_channel import InboundChannel
from telnyx.api_resources.inventory_coverage import InventoryCoverage
from telnyx.api_resources.ip import IP
from telnyx.api_resources.ip_connection import IPConnection
from telnyx.api_resources.list_object import ListObject
from telnyx.api_resources.managed_account import ManagedAccount
from telnyx.api_resources.media import Media
from telnyx.api_resources.message import Message
from telnyx.api_resources.messaging_hosted_number import MessagingHostedNumber
from telnyx.api_resources.messaging_hosted_number_order import (
MessagingHostedNumberOrder,
)
from telnyx.api_resources.messaging_phone_number import MessagingPhoneNumber
from telnyx.api_resources.messaging_profile import MessagingProfile
from telnyx.api_resources.notification_channel import NotificationChannel
from telnyx.api_resources.notification_event import NotificationEvent
from telnyx.api_resources.notification_event_condition import NotificationEventCondition
from telnyx.api_resources.notification_profiles import NotificationProfile
from telnyx.api_resources.notification_setting import NotificationSetting
from telnyx.api_resources.number_lookup import NumberLookup
from telnyx.api_resources.number_order import NumberOrder
from telnyx.api_resources.number_order_phone_number import NumberOrderPhoneNumber
from telnyx.api_resources.number_reservation import NumberReservation
from telnyx.api_resources.outbound_voice_profile import OutboundVoiceProfile
from telnyx.api_resources.phone_assignment_profile import PhoneNumberByProfile
from telnyx.api_resources.phone_number import (
MessagingSettings,
PhoneNumber,
VoiceSettings,
)
from telnyx.api_resources.phone_number_campaign import PhoneNumberCampaign
from telnyx.api_resources.phone_number_jobs import PhoneNumberJob
from telnyx.api_resources.phone_number_regulatory_requirement import (
PhoneNumberRegulatoryRequirement,
)
Expand All @@ -45,49 +66,86 @@
from telnyx.api_resources.portout import PortOut
from telnyx.api_resources.public_key import PublicKey
from telnyx.api_resources.queue import Queue, QueueCall
from telnyx.api_resources.regulatory_requirement import RegulatoryRequirement
from telnyx.api_resources.room import Room
from telnyx.api_resources.room_participant import RoomParticipant
from telnyx.api_resources.room_session import RoomSession, RoomSessionList
from telnyx.api_resources.short_code import ShortCode
from telnyx.api_resources.sim_card import SIMCard
from telnyx.api_resources.sim_card_action import SIMCardAction
from telnyx.api_resources.sim_card_group import SIMCardGroup
from telnyx.api_resources.sim_card_order import SIMCardOrder, SIMCardOrderPreview
from telnyx.api_resources.sub_number_order import SubNumberOrder
from telnyx.api_resources.telephony_credential import TelephonyCredential
from telnyx.api_resources.verification import Verification
from telnyx.api_resources.verify_profile import VerifyProfile
from telnyx.api_resources.webhook_deliveries import WebhookDeliveries
from telnyx.api_resources.whatsapp_business_account import WhatsappBusinessAccount
from telnyx.api_resources.whatsapp_contact import WhatsappContact
from telnyx.api_resources.whatsapp_media import WhatsappMedia
from telnyx.api_resources.whatsapp_message import WhatsappMessage
from telnyx.api_resources.whatsapp_phone_number import WhatsappPhoneNumber
from telnyx.api_resources.wireless_detail_record_report import (
WirelessDetailRecordsReports,
)

# flake8: noqa


__all__ = [
"AccessControlIP",
"AccessIPAddress",
"AuthenticationProvider",
"Address",
"APIKey",
"AvailablePhoneNumber",
"Balance",
"BillingGroup",
"Brand",
"BulkCreation",
"Call",
"CallControlApplication",
"Campaign",
"Comment",
"Conference",
"Connection",
"CredentialConnection",
"CustomStorageCredential",
"DetailRecordsReport",
"Document",
"DocumentLink",
"DynamicEmergencyAddress",
"Event",
"Fax",
"FaxApplication",
"FQDN",
"FQDNConnection",
"InboundChannel",
"InventoryCoverage",
"IP",
"IPConnection",
"ListObject",
"ManagedAccount",
"Media",
"Message",
"MessagingHostedNumber",
"MessagingHostedNumberOrder",
"MessagingPhoneNumber",
"MessagingProfile",
"MessagingSettings",
"NotificationChannel",
"NotificationEvent",
"NotificationEventCondition",
"NotificationProfile",
"NotificationSetting",
"NumberLookup",
"NumberOrder",
"NumberOrderPhoneNumber",
"NumberReservation",
"OutboundVoiceProfile",
"PhoneNumber",
"PhoneNumberByProfile",
"PhoneNumberCampaign",
"PhoneNumberJob",
"PhoneNumberRegulatoryRequirement",
"PortabilityCheck",
"PortingOrder",
Expand All @@ -96,11 +154,25 @@
"PublicKey",
"Queue",
"QueueCall",
"RegulatoryRequirement",
"SIMCard",
"Room",
"RoomParticipant",
"RoomSession",
"ShortCode",
"SIMCard",
"SIMCardAction",
"SIMCardGroup",
"SIMCardOrder",
"SIMCardOrderPreview",
"SubNumberOrder",
"TelephonyCredential",
"Verification",
"VerifyProfile",
"VoiceSettings",
"WebhookDeliveries",
"WhatsappBusinessAccount",
"WhatsappContact",
"WhatsappMedia",
"WhatsappMessage",
"WhatsappPhoneNumber",
"WirelessDetailRecordsReports",
]
12 changes: 12 additions & 0 deletions telnyx/api_resources/abstract/updateable_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def modify(cls, sid, **params):
url = "%s/%s" % (cls.class_url(), quote_plus(util.utf8(sid)))
return cls._modify(url, **params)

@classmethod
def _putify(cls, url, api_key=None, **params):
requestor = api_requestor.APIRequestor(api_key)
params = util.rewrite_reserved_words(params)
response, api_key = requestor.request("put", url, params)
return util.convert_to_telnyx_object(response, api_key)

@classmethod
def putify(cls, sid, **params):
url = "%s/%s" % (cls.class_url(), quote_plus(util.utf8(sid)))
return cls._putify(url, **params)

def save(self):
updated_params = self.serialize(None)

Expand Down
11 changes: 11 additions & 0 deletions telnyx/api_resources/access_control_ip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.abstract import (
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
)


class AccessControlIP(CreateableAPIResource, DeletableAPIResource, ListableAPIResource):
OBJECT_NAME = "access_control_ip"
15 changes: 15 additions & 0 deletions telnyx/api_resources/access_ip_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.abstract import (
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
)


class AccessIPAddress(CreateableAPIResource, DeletableAPIResource, ListableAPIResource):
OBJECT_NAME = "access_ip_address"

@classmethod
def class_url(cls):
return "/v2/access_ip_address"
17 changes: 17 additions & 0 deletions telnyx/api_resources/authentication_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.abstract import (
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
UpdateableAPIResource,
)


class AuthenticationProvider(
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
UpdateableAPIResource,
):
OBJECT_NAME = "authentication_provider"
34 changes: 34 additions & 0 deletions telnyx/api_resources/brand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.abstract import (
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
UpdateableAPIResource,
nested_resource_class_methods,
)


@nested_resource_class_methods(
"list_external_vetting", path="externalVetting", operations=["list"]
)
@nested_resource_class_methods(
"order_external_vetting", path="externalVetting", operations=["create"]
)
class Brand(
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
UpdateableAPIResource,
):
OBJECT_NAME = "brand"

@classmethod
def class_url(cls):
return "/10dlc/brand"

def list_external_vetting(self, **params):
return Brand.list_external_vetting(self.name, **params)

def operation_status(self, **params):
return Brand.create_external_vetting(self.id, **params)
28 changes: 28 additions & 0 deletions telnyx/api_resources/bulk_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.abstract import (
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
UpdateableAPIResource,
nested_resource_class_methods,
)


@nested_resource_class_methods(
"detailed_status", path="detailedStatus", operations=["list"]
)
class BulkCreation(
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
UpdateableAPIResource,
):
OBJECT_NAME = "bulk_creation"

@classmethod
def class_url(cls):
return "/10dlc/bulkCreation"

def detailed_status(self, **params):
return BulkCreation.list_detailed_status(self.name, **params)
Loading

0 comments on commit c78e3a9

Please sign in to comment.