More work on Zang integration
This commit is contained in:
parent
ff4ac3ab9d
commit
9110acd14a
@ -47,11 +47,15 @@ public final class UserConverter implements Block<Document> {
|
||||
null,
|
||||
null,
|
||||
user.getString("email"),
|
||||
Instant.EPOCH,
|
||||
user.containsKey("email") ? Instant.EPOCH : null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
user.getString("phone"),
|
||||
user.containsKey("phone") ? Instant.EPOCH : null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"INVALID",
|
||||
user.getDate("joined").toInstant(),
|
||||
user.getDate("joined").toInstant(),
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.frozenorb.apiv3.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.mongodb.async.SingleResultCallback;
|
||||
import com.mongodb.async.client.MongoCollection;
|
||||
@ -12,7 +11,6 @@ import fr.javatic.mongo.jacksonCodec.objectId.Id;
|
||||
import lombok.Getter;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
|
||||
import net.frozenorb.apiv3.util.TimeUtils;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.time.Instant;
|
||||
|
@ -5,6 +5,7 @@ import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import net.frozenorb.apiv3.model.NotificationTemplate;
|
||||
import net.frozenorb.apiv3.util.MandrillUtils;
|
||||
import net.frozenorb.apiv3.util.ZangUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -36,7 +37,7 @@ public final class Notification {
|
||||
}
|
||||
|
||||
public void sendAsText(String phoneNumber, SingleResultCallback<Void> callback) {
|
||||
callback.onResult(null, new UnsupportedOperationException());
|
||||
ZangUtils.sendText(phoneNumber, body, callback);
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,27 @@ public class ZangUtils {
|
||||
private static final String zangAuthToken = APIv3.getConfig().getProperty("zang.authToken");
|
||||
private static final HttpClient httpsClient = APIv3.getVertxInstance().createHttpClient(new HttpClientOptions().setSsl(true).setTrustAll(true));
|
||||
|
||||
public static void sendText(String to, String messageBody, SingleResultCallback<Void> callback) {
|
||||
String authHeader = "Basic " + Base64.getEncoder().encodeToString((zangAccountSid + ":" + zangAuthToken).getBytes(Charsets.UTF_8));
|
||||
|
||||
httpsClient.post(443, "api.zang.io", "/v2/Accounts/" + zangAccountSid + "/SMS/Messages.json", (response) -> {
|
||||
response.bodyHandler((body) -> {
|
||||
JsonObject bodyJson = new JsonObject(body.toString());
|
||||
|
||||
if (bodyJson.getString("status", "").equals("queued")) {
|
||||
callback.onResult(null, null);
|
||||
} else {
|
||||
callback.onResult(null, new IOException("Could not send text message: " + bodyJson.encode()));
|
||||
}
|
||||
});
|
||||
|
||||
response.exceptionHandler((error) -> callback.onResult(null, error));
|
||||
})
|
||||
.putHeader("Authorization", authHeader)
|
||||
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
|
||||
.end("To=" + to + "&From=339-337-5300&Body=" + messageBody);
|
||||
}
|
||||
|
||||
public static void getCarrierInfo(String phoneNumber, SingleResultCallback<ZangResult> callback) {
|
||||
String authHeader = "Basic " + Base64.getEncoder().encodeToString((zangAccountSid + ":" + zangAuthToken).getBytes(Charsets.UTF_8));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user