Skip to content

Commit ef8711c

Browse files
authored
Add scheduler support for the EU region (#151)
# Description This PR enables support for scheduler using the EU region. Depending on the regional URL set for the Nylas SDK, the region for the scheduler will get set as well. # Usage ```java public class NylasExample { public static void main(String[] args) throws Exception { // Setup Nylas client, defaulting to US region NylasClient client = new NylasClient(); NylasApplication application = client.account("ACESS_TOKEN"); Schedulers usScheduler = application.schedulers(); // Scheduler URL pointing to https://api.schedule.nylas.com/ // Setup Nylas client for the EU region NylasClient euClient = new NylasClient.Builder() .baseUrl(NylasClient.EU_BASE_URL) .build(); NylasApplication euApplication = euClient.account("ACESS_TOKEN"); Schedulers euScheduler = euApplication.schedulers(); // Scheduler URL pointing to https://ireland.api.schedule.nylas.com/ } } ``` # 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.
1 parent ca7dbca commit ef8711c

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This section contains changes that have been committed but not yet released.
77
### Added
88

99
* Added missing `content_disposition` field in `File`
10+
* Added scheduler support for the EU region
1011

1112
### Changed
1213

src/main/java/com/nylas/NylasClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
*/
2525
public class NylasClient {
2626

27-
public static final String DEFAULT_BASE_URL = "https://api.nylas.com";
28-
27+
public static final String DEFAULT_BASE_URL = "https://api.nylas.com/";
28+
public static final String EU_BASE_URL = "https://ireland.api.nylas.com/";
29+
2930
private final HttpUrl baseUrl;
3031
private final OkHttpClient httpClient;
3132

src/main/java/com/nylas/Schedulers.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.nylas;
22

3-
import com.nylas.*;
43
import com.nylas.scheduler.*;
54
import okhttp3.HttpUrl;
65

@@ -13,14 +12,27 @@
1312

1413
public class Schedulers extends RestfulDAO<Scheduler> {
1514

16-
private final String SCHEDULER_API_BASE_URL = "https://api.schedule.nylas.com";
15+
private static final String SCHEDULER_API_BASE_URL = "https://api.schedule.nylas.com/";
16+
private static final String SCHEDULER_API_EU_BASE_URL = "https://ireland.api.schedule.nylas.com/";
17+
private final String baseUrl;
1718

1819
Schedulers(NylasClient client, String accessToken) {
1920
super(client, Scheduler.class, "manage/pages", accessToken);
21+
22+
// Set the Scheduler URL based on the URL set in the client
23+
switch (client.newUrlBuilder().toString()) {
24+
case NylasClient.EU_BASE_URL:
25+
baseUrl = SCHEDULER_API_EU_BASE_URL;
26+
break;
27+
case NylasClient.DEFAULT_BASE_URL:
28+
default:
29+
baseUrl = SCHEDULER_API_BASE_URL;
30+
break;
31+
}
2032
}
2133

2234
protected HttpUrl.Builder getCollectionUrl() {
23-
return HttpUrl.get(SCHEDULER_API_BASE_URL).newBuilder().addPathSegments(collectionPath);
35+
return HttpUrl.get(baseUrl).newBuilder().addPathSegments(collectionPath);
2436
}
2537

2638
public RemoteCollection<Scheduler> list() throws IOException, RequestFailedException {
@@ -147,6 +159,6 @@ private List<ProviderAvailability> getProviderAvailability(String provider)
147159
}
148160

149161
private HttpUrl.Builder schedulerUrl() {
150-
return HttpUrl.get(SCHEDULER_API_BASE_URL).newBuilder().addPathSegment("schedule");
162+
return HttpUrl.get(baseUrl).newBuilder().addPathSegment("schedule");
151163
}
152164
}

src/test/java/com/nylas/NylasAccountTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class NylasAccountTest {
1717
@BeforeEach
1818
private void init() {
1919
nylasClient = mock(NylasClient.class);
20+
when(nylasClient.newUrlBuilder()).thenReturn(HttpUrl.get(NylasClient.DEFAULT_BASE_URL).newBuilder());
2021
}
2122

2223
@Test

0 commit comments

Comments
 (0)