diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ca2fe69..5ee32f8e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,8 +36,15 @@ jobs: - name: Run codecov uses: codecov/codecov-action@v3 + format: + runs-on: ubuntu-latest + steps: + - name: Format commits + uses: pre-commit-ci/lite-action@v1.0.1 + if: always() + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: psf/black@stable \ No newline at end of file + - uses: psf/black@stable diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ed51c20..b0931861 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,12 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.5.4 + rev: v4.4.0 hooks: - id: trailing-whitespace + - id: end-of-file-fixer language_version: python3.11 - repo: https://github.com/ambv/black - rev: 18.6b4 + rev: 23.7.0 hooks: - id: black language_version: python3.11 diff --git a/README.md b/README.md index 588d6666..a6a6f5f5 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ The delivery receipt URL can be unset by sending an empty string. ## Messages API -The Messages API is an API that allows you to send messages via SMS, MMS, WhatsApp, Messenger and Viber. Call the API from your Python code by +The Messages API is an API that allows you to send messages via SMS, MMS, WhatsApp, Messenger and Viber. Call the API from your Python code by passing a dict of parameters into the `client.messages.send_message()` method. It accepts JWT or API key/secret authentication. @@ -174,9 +174,9 @@ Some basic samples are below. For more detailed information and code snippets, p ### Send an SMS ```python responseData = client.messages.send_message({ - 'channel': 'sms', - 'message_type': 'text', - 'to': '447123456789', + 'channel': 'sms', + 'message_type': 'text', + 'to': '447123456789', 'from': 'Vonage', 'text': 'Hello from Vonage' }) @@ -187,9 +187,9 @@ Note: only available in the US. You will need a 10DLC number to send an MMS mess ```python client.messages.send_message({ - 'channel': 'mms', - 'message_type': 'image', - 'to': '11112223333', + 'channel': 'mms', + 'message_type': 'image', + 'to': '11112223333', 'from': '1223345567', 'image': {'url': 'https://example.com/image.jpg', 'caption': 'Test Image'} }) @@ -203,9 +203,9 @@ type to a user if they have messaged your business number in the last 24 hours. ```python client.messages.send_message({ - 'channel': 'whatsapp', - 'message_type': 'audio', - 'to': '447123456789', + 'channel': 'whatsapp', + 'message_type': 'audio', + 'to': '447123456789', 'from': '440123456789', 'audio': {'url': 'https://example.com/audio.mp3'} }) @@ -218,9 +218,9 @@ You will need to link your Facebook business page to your Vonage account in the ```python client.messages.send_message({ - 'channel': 'messenger', - 'message_type': 'video', - 'to': '594123123123123', + 'channel': 'messenger', + 'message_type': 'video', + 'to': '594123123123123', 'from': '1012312312312', 'video': {'url': 'https://example.com/video.mp4'} }) @@ -420,7 +420,7 @@ You can also verify a user by WhatsApp Interactive Message or by Silent Authenti ```python params = { - 'brand': 'ACME, Inc', + 'brand': 'ACME, Inc', 'workflow': [{'channel': 'sms', 'to': '447700900000'}] } verify_request = verify2.new_request(params) @@ -430,7 +430,7 @@ verify_request = verify2.new_request(params) ```python params = { - 'brand': 'ACME, Inc', + 'brand': 'ACME, Inc', 'workflow': [ {'channel': 'silent_auth', 'to': '447700900000'}, {'channel': 'email', 'to': 'customer@example.com', 'from': 'business@example.com'} @@ -459,8 +459,8 @@ This feature is only enabled if you have requested for it to be added to your ac ```python params = { - 'brand': 'ACME, Inc', - 'fraud_check': False, + 'brand': 'ACME, Inc', + 'fraud_check': False, 'workflow': [{'channel': 'sms', 'to': '447700900000'}] } verify_request = verify2.new_request(params) @@ -845,7 +845,7 @@ client.account.get_balance() This feature is only enabled when you enable auto-reload for your account in the dashboard. ```python # trx is the reference from when auto-reload was enabled and money was added -client.account.topup(trx=transaction_reference) +client.account.topup(trx=transaction_reference) ``` ## Subaccounts API @@ -867,8 +867,8 @@ client.subaccounts.create_subaccount(name='my subaccount') # With options client.subaccounts.create_subaccount( - name='my subaccount', - secret='Password123', + name='my subaccount', + secret='Password123', use_primary_account_balance=False, ) ``` @@ -898,7 +898,7 @@ All fields are optional. If `start_date` or `end_date` are used, the dates must client.subaccounts.list_credit_transfers( start_date='2022-03-29T14:16:56Z', end_date='2023-06-12T17:20:01Z', - subaccount=SUBACCOUNT_API_KEY, # Use to show only the results that contain this key + subaccount=SUBACCOUNT_API_KEY, # Use to show only the results that contain this key ) ``` @@ -908,9 +908,9 @@ Transferring credit is only possible for postpaid accounts, i.e. accounts that c ```python client.subaccounts.transfer_credit( - from_=FROM_ACCOUNT, - to=TO_ACCOUNT, - amount=0.50, + from_=FROM_ACCOUNT, + to=TO_ACCOUNT, + amount=0.50, reference='test credit transfer', ) ``` @@ -923,7 +923,7 @@ All fields are optional. If `start_date` or `end_date` are used, the dates must client.subaccounts.list_balance_transfers( start_date='2022-03-29T14:16:56Z', end_date='2023-06-12T17:20:01Z', - subaccount=SUBACCOUNT_API_KEY, # Use to show only the results that contain this key + subaccount=SUBACCOUNT_API_KEY, # Use to show only the results that contain this key ) ``` @@ -931,9 +931,9 @@ client.subaccounts.list_balance_transfers( ```python client.subaccounts.transfer_balance( - from_=FROM_ACCOUNT, - to=TO_ACCOUNT, - amount=0.50, + from_=FROM_ACCOUNT, + to=TO_ACCOUNT, + amount=0.50, reference='test balance transfer', ) ``` @@ -942,9 +942,9 @@ client.subaccounts.transfer_balance( ```python client.subaccounts.transfer_balance( - from_=FROM_ACCOUNT, - to=TO_ACCOUNT, - number=NUMBER_TO_TRANSFER, + from_=FROM_ACCOUNT, + to=TO_ACCOUNT, + number=NUMBER_TO_TRANSFER, country='US', ) ``` @@ -1217,7 +1217,7 @@ We don't currently support asyncio in the Python SDK but we are planning to do s ## Contributing -We :heart: contributions! But if you plan to work on something big or controversial, please [contact us](mailto:devrel@vonage.com) first! +We :heart: contributions! But if you plan to work on something big or controversial, please contact us by raising an issue first! We recommend working on `vonage-python-sdk` with a [virtualenv][virtualenv]. The following command will install all the Python dependencies you need to run the tests: @@ -1231,6 +1231,8 @@ The tests are all written with pytest. You run them with: make test ``` +We use [Black](https://black.readthedocs.io/en/stable/index.html) for code formatting, with our config in the `pyproject.toml` file. Please make sure your PRs follow this format. + ## License This library is released under the [Apache License][license]. diff --git a/requirements.txt b/requirements.txt index 680153d8..ba35aaa2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ pydantic>=1.10,==1.* bump2version build -twine \ No newline at end of file +twine +pre-commit