Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for overriding various fields of outgoing requests #363

Merged
merged 10 commits into from
May 15, 2024

Conversation

mrashed-dev
Copy link
Contributor

@mrashed-dev mrashed-dev commented May 14, 2024

Description

This PR adds support for adding a new RequestOverride object which can be built with fields that can override:

  • API URI
  • API Key
  • Timeout
  • and, adding additional headers

for outgoing requests.

Usage

For all methods that call the Nylas API, there is now an additional overrides: RequestOverrides field that takes in the built object and will override the specific outgoing call with whatever non-null values are present. This can also be used to add additional headers to outgoing calls. Here's an example:

from nylas import Client

nylas = Client(
    api_key="API_KEY",
)

calendars, request_id, next_cursor = nylas.calendars.list("GRANT_ID", overrides={
 "api_key": "SECONDARY_API_KEY",
 "api_uri": "https://random.api.nylas.com",
 "timeout": 360,
 "headers": {
    "X-Header": "value"
  }
})

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

Copy link
Contributor

@atejada atejada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good 👍 But...you code sample is wrong 😑 Should be like this

from nylas import Client

nylas = Client(
    api_key="nyk_v0_z2TBrNMB8zcYl0BUOybx0KwZpEiXx1ZEQREpwrfVTFeZZKLdY7gDgfSacyuhhusy",
)

calendars, request_id, next_cursor = nylas.calendars.list("[email protected]", overrides= {
    "api_key": "SECONDARY_API_KEY",
	"api_uri": "https://random.api.nylas.com",
    "timeout": 360,
    "headers": {
        "X-Header": "123"
     }    
})

I'm going to add a PR to address the test errors 😎

Added override=None for all tests that require it
Went overboard with override=None
Copy link

codecov bot commented May 15, 2024

Codecov Report

Attention: Patch coverage is 94.62366% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 98.55%. Comparing base (b5ca361) to head (192a0d2).
Report is 5 commits behind head on main.

❗ Current head 192a0d2 differs from pull request most recent head 179a5e1. Consider uploading reports for the commit 179a5e1 to get more accurate results

Files Patch % Lines
nylas/handler/http_client.py 76.19% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #363      +/-   ##
==========================================
- Coverage   98.91%   98.55%   -0.36%     
==========================================
  Files          45       45              
  Lines        1654     1734      +80     
==========================================
+ Hits         1636     1709      +73     
- Misses         18       25       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Fixing tests is a never-ending job
@atejada
Copy link
Contributor

atejada commented May 15, 2024

All tests fixed 🥳

@mrashed-dev mrashed-dev merged commit 2656703 into main May 15, 2024
4 checks passed
@mrashed-dev mrashed-dev deleted the TW-2799-python-add-custom-headers-support branch May 15, 2024 16:29
@mrashed-dev mrashed-dev mentioned this pull request May 17, 2024
mrashed-dev added a commit that referenced this pull request May 17, 2024
# Changelog
* Added support for custom headers field for drafts and messages (#360)
* Added support for overriding various fields of outgoing requests (#363)
* Added support for `provider` field in code exchange response (#360)
* Added support for `event_type` filtering field for listing events (#364)
* Added clean messages support (#361)
* Added additional webhook triggers (#357)
* Fixed issue where attachments < 3mb were not being encoded correctly (#362)
* Fixed issue deserializing event and code exchange responses (#358, #368, #369)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants