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 #224

Merged
merged 8 commits into from
Apr 30, 2024

Conversation

mrashed-dev
Copy link
Contributor

@mrashed-dev mrashed-dev commented Apr 19, 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:

package com.nylas

import com.nylas.models.RequestOverrides

object Main {
  @Throws(Exception::class)
  @JvmStatic
  fun main(args: Array<String>) {
    val nylas = NylasClient("API_KEY")
    
    val override = RequestOverrides(
      apiKey = "SECONDARY_API_KEY",
      apiUri = "https://random.api.nylas.com",
      timeout = 360,
      headers = mapOf("X-Header" to "value"),
    )
    
    val calendars = nylas.calendars().list("[email protected]", overrides = override)
  }
}

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.

@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2024

Codecov Report

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

Project coverage is 80.46%. Comparing base (2a3eef8) to head (a4c2536).

Files Patch % Lines
src/main/kotlin/com/nylas/NylasClient.kt 68.42% 8 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #224      +/-   ##
============================================
+ Coverage     79.64%   80.46%   +0.81%     
- Complexity      209      281      +72     
============================================
  Files            29       29              
  Lines           732      824      +92     
  Branches         75       79       +4     
============================================
+ Hits            583      663      +80     
- Misses          111      119       +8     
- Partials         38       42       +4     

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

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.

Looks good 👍

@mrashed-dev mrashed-dev merged commit ded393a into main Apr 30, 2024
2 checks passed
@mrashed-dev mrashed-dev deleted the TW-2801-kotlin-add-custom-headers-support branch April 30, 2024 03:15
@mrashed-dev mrashed-dev mentioned this pull request Apr 30, 2024
mrashed-dev added a commit that referenced this pull request Apr 30, 2024
# Changelog
### Added
* Added missing webhook triggers (#220)
* Added provider field to token exchange response (#225)
* Added support for clean messages endpoint (#226, #228)
* Added support for custom headers field for Drafts and Messages (#223)
* Added support for overriding various fields of outgoing requests
(#224)

### Changed
* Fixed issue where attachments < 3mb were not being encoded correctly
(#227, #222)

# License
<!-- Your PR comment must contain the following line for us to merge the
PR. -->
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.
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.

3 participants