-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
DEVEXP-615: SinchClient for mailgun (#165)
* feat (Mailgun): Initial Mailgun configuration and authentication
- Loading branch information
Showing
18 changed files
with
707 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
client/src/main/com/sinch/sdk/domains/mailgun/MailgunService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sinch.sdk.domains.mailgun; | ||
|
||
/** | ||
* Mailgun Service | ||
* | ||
* @see <a | ||
* href="https://documentation.mailgun.com/docs/mailgun/">https://documentation.mailgun.com/docs/mailgun</a> | ||
* @since __TO_BE_DEFINED__ | ||
*/ | ||
public interface MailgunService { | ||
|
||
/** | ||
* Mailgun Service V1 | ||
* | ||
* @return V1 service instance for project | ||
* @see <a href="__TO_BE_DEFINED__">__TO_BE_DEFINED__</a> | ||
* @since __TO_BE_DEFINED__ | ||
*/ | ||
com.sinch.sdk.domains.mailgun.api.v1.MailgunService v1(); | ||
} |
32 changes: 32 additions & 0 deletions
32
client/src/main/com/sinch/sdk/domains/mailgun/adapters/MailgunService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.sinch.sdk.domains.mailgun.adapters; | ||
|
||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.domains.conversation.api.templates.adapters.TemplatesService; | ||
import com.sinch.sdk.models.MailgunContext; | ||
import com.sinch.sdk.models.MailgunCredentials; | ||
|
||
public class MailgunService implements com.sinch.sdk.domains.mailgun.MailgunService { | ||
|
||
private final MailgunCredentials credentials; | ||
private final MailgunContext context; | ||
private final HttpClient httpClient; | ||
|
||
private com.sinch.sdk.domains.mailgun.api.v1.MailgunService mailgunV1; | ||
private TemplatesService templates; | ||
|
||
public MailgunService( | ||
MailgunCredentials credentials, MailgunContext context, HttpClient httpClient) { | ||
this.credentials = credentials; | ||
this.context = context; | ||
this.httpClient = httpClient; | ||
} | ||
|
||
public com.sinch.sdk.domains.mailgun.api.v1.MailgunService v1() { | ||
if (null == this.mailgunV1) { | ||
this.mailgunV1 = | ||
new com.sinch.sdk.domains.mailgun.api.v1.adapters.MailgunService( | ||
credentials, context, httpClient); | ||
} | ||
return this.mailgunV1; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
client/src/main/com/sinch/sdk/domains/mailgun/api/v1/MailgunService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1; | ||
|
||
/** | ||
* Mailgun Service V1 | ||
* | ||
* @see <a href="__TO_BE_DEFINED__">__TO_BE_DEFINED__</a> | ||
* @since __TO_BE_DEFINED__ | ||
*/ | ||
public interface MailgunService { | ||
|
||
/** | ||
* Messages Service instance | ||
* | ||
* @return service instance for project | ||
* @since __TO_BE_DEFINED__ | ||
*/ | ||
MessagesService messages(); | ||
} |
9 changes: 9 additions & 0 deletions
9
client/src/main/com/sinch/sdk/domains/mailgun/api/v1/MessagesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1; | ||
|
||
/** | ||
* Mailgun Message Service V1 | ||
* | ||
* @see <a href="__TO_BE_DEFINED__">__TO_BE_DEFINED__</a> | ||
* @since __TO_BE_DEFINED__ | ||
*/ | ||
public interface MessagesService {} |
59 changes: 59 additions & 0 deletions
59
client/src/main/com/sinch/sdk/domains/mailgun/api/v1/adapters/MailgunService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import com.sinch.sdk.auth.adapters.BasicAuthManager; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.core.utils.StringUtil; | ||
import com.sinch.sdk.models.MailgunContext; | ||
import com.sinch.sdk.models.MailgunCredentials; | ||
import java.util.AbstractMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class MailgunService implements com.sinch.sdk.domains.mailgun.api.v1.MailgunService { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(MailgunService.class.getName()); | ||
private static final String SECURITY_SCHEME_KEYWORD_NUMBERS = "BasicAuth"; | ||
|
||
private final MailgunContext context; | ||
private final HttpClient httpClient; | ||
|
||
private final Map<String, AuthManager> authManagers; | ||
|
||
private MessagesService messages; | ||
|
||
public MailgunService( | ||
MailgunCredentials credentials, MailgunContext context, HttpClient httpClient) { | ||
|
||
Objects.requireNonNull(credentials, "Mailgun service require credentials to be defined"); | ||
Objects.requireNonNull(context, "Mailgun service requires context to be defined"); | ||
StringUtil.requireNonEmpty( | ||
credentials.getApiUser(), "Mailgun service requires 'apiUser' to be defined"); | ||
StringUtil.requireNonEmpty( | ||
credentials.getApiKey(), "Mailgun service requires 'apiKey' to be defined"); | ||
StringUtil.requireNonEmpty( | ||
context.getUrl(), "'Mailgun service requires mailgunUrl' to be defined"); | ||
|
||
LOGGER.fine("Activate Mailgun API with server='" + context.getServer().getUrl() + "'"); | ||
|
||
this.context = context; | ||
this.httpClient = httpClient; | ||
|
||
AuthManager basicAuthManager = | ||
new BasicAuthManager(credentials.getApiUser(), credentials.getApiKey()); | ||
|
||
authManagers = | ||
Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_NUMBERS, basicAuthManager)) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public MessagesService messages() { | ||
if (null == this.messages) { | ||
this.messages = new MessagesService(context, httpClient, authManagers); | ||
} | ||
return this.messages; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
client/src/main/com/sinch/sdk/domains/mailgun/api/v1/adapters/MessagesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.models.MailgunContext; | ||
import java.util.Map; | ||
|
||
public class MessagesService implements com.sinch.sdk.domains.mailgun.api.v1.MessagesService { | ||
|
||
public MessagesService( | ||
MailgunContext context, HttpClient httpClient, Map<String, AuthManager> authManagers) {} | ||
} |
11 changes: 11 additions & 0 deletions
11
client/src/main/com/sinch/sdk/domains/mailgun/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Conversation API interface | ||
* | ||
* <p>The Sinch Conversation API allows you to send and receive messages globally over SMS, RCS, | ||
* WhatsApp, Viber Business, Facebook Messenger and other popular channels. | ||
* | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/conversation">https://developers.sinch.com/docs/conversation</a> | ||
* @since 1.3 | ||
*/ | ||
package com.sinch.sdk.domains.mailgun; |
Oops, something went wrong.