From 0c0acdbf859f9dbf0e4818fdf3333496bcab511e Mon Sep 17 00:00:00 2001 From: Suhas Reddy Mulkalla Date: Sat, 26 Jan 2019 19:19:02 +0530 Subject: [PATCH 1/2] [SDKS-144] Update address verification API's with latest spec --- .../com/plivo/api/models/address/Address.java | 7 +- .../api/models/address/AddressCreator.java | 298 ++++++++++-------- .../api/models/address/AddressProofType.java | 24 ++ .../api/models/address/AddressUpdater.java | 148 ++++++++- .../api/models/address/FileExtensionType.java | 18 ++ .../plivo/api/models/address/NumberType.java | 20 ++ .../api/models/address/SalutationType.java | 17 + src/main/java/com/plivo/api/util/Utils.java | 27 ++ src/test/java/com/plivo/api/AddressTest.java | 14 +- 9 files changed, 439 insertions(+), 134 deletions(-) create mode 100644 src/main/java/com/plivo/api/models/address/AddressProofType.java create mode 100644 src/main/java/com/plivo/api/models/address/FileExtensionType.java create mode 100644 src/main/java/com/plivo/api/models/address/NumberType.java create mode 100644 src/main/java/com/plivo/api/models/address/SalutationType.java diff --git a/src/main/java/com/plivo/api/models/address/Address.java b/src/main/java/com/plivo/api/models/address/Address.java index 6aa0688b..93bd88be 100644 --- a/src/main/java/com/plivo/api/models/address/Address.java +++ b/src/main/java/com/plivo/api/models/address/Address.java @@ -27,10 +27,11 @@ public class Address extends BaseResource { private String addressProofType; private JsonNode documentDetails; + public static AddressCreator creator( - String countryIso, String salutation, String firstName, String lastName, - String addressLine1, String addressLine2, String city, String region, String postalCode) { - return new AddressCreator(countryIso, salutation, firstName, lastName, addressLine1, addressLine2, city, region, postalCode); + String phoneNumberCountry, NumberType numberType, SalutationType salutation, String firstName, + String lastName, String addressLine1, String addressLine2, String city, String region, String postalCode, String countryIso) { + return new AddressCreator(phoneNumberCountry, numberType, salutation, firstName, lastName, addressLine1, addressLine2, city, region, postalCode, countryIso); } public static AddressUpdater updater(String id){ diff --git a/src/main/java/com/plivo/api/models/address/AddressCreator.java b/src/main/java/com/plivo/api/models/address/AddressCreator.java index 8ea37b7e..b0e27a4b 100644 --- a/src/main/java/com/plivo/api/models/address/AddressCreator.java +++ b/src/main/java/com/plivo/api/models/address/AddressCreator.java @@ -1,5 +1,7 @@ package com.plivo.api.models.address; +import java.io.File; + import com.plivo.api.models.base.Creator; import com.plivo.api.util.Utils; import retrofit2.Call; @@ -16,129 +18,146 @@ public class AddressCreator extends Creator { private String city; private String region; private String postalCode; - private String file; + private File file; private Boolean autoCorrectAddress; private String addressProofType; - - public String countryIso() { - return countryIso; - } - - public String salutation() { - return salutation; - } - - public String firstName() { - return firstName; - } - - public String lastName() { - return lastName; - } - - public String addressLine1() { - return addressLine1; - } - - public String addressLine2() { - return addressLine2; - } - - public String city() { - return city; - } - - public String region() { - return region; - } - - public String postalCode() { - return postalCode; - } - - public String file() { - return file; - } - - public Boolean autoCorrectAddress() { - return autoCorrectAddress; - } - - public String addressProofType() { - return addressProofType; - } - - public AddressCreator(String countryIso, String salutation, String firstName, String lastName, - String addressLine1, String addressLine2, String city, String region, String postalCode) { - if (!Utils.allNotNull(countryIso, salutation, firstName, lastName, - addressLine1, addressLine2, city, region, postalCode)) { - throw new IllegalArgumentException("countryIso, salutation, firstName, lastName," + - "addressLine1, addressLine2, city, region and postalCode must not be null"); - } - this.countryIso = countryIso; - this.salutation = salutation; - this.firstName = firstName; - this.lastName = lastName; - this.addressLine1 = addressLine1; - this.addressLine2 = addressLine2; - this.city = city; - this.region = region; - this.postalCode = postalCode; - } - - public AddressCreator countryIso(String countryIso) { - this.countryIso = countryIso; - return this; - } - + private String phoneNumberCountry; + private String fiscalIdentificationCode; + private String streetCode; + private String municipalCode; + private String numberType; + private String idNumber; + private String callBackUrl; + + + public String getCountryIso() { + return countryIso; + } + + public String getAlias() { + return alias; + } + + public String getSalutation() { + return salutation; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getAddressLine1() { + return addressLine1; + } + + public String getAddressLine2() { + return addressLine2; + } + + public String getCity() { + return city; + } + + public String getRegion() { + return region; + } + + public String getPostalCode() { + return postalCode; + } + + public File getFile() { + return file; + } + + public Boolean getAutoCorrectAddress() { + return autoCorrectAddress; + } + + public String getAddressProofType() { + return addressProofType; + } + + public String getPhoneNumberCountry() { + return phoneNumberCountry; + } + + public String getFiscalIdentificationCode() { + return fiscalIdentificationCode; + } + + public String getStreetCode() { + return streetCode; + } + + public String getMunicipalCode() { + return municipalCode; + } + + public String getNumberType() { + return numberType; + } + + public String getIdNumber() { + return idNumber; + } + + public String getCallBackUrl() { + return callBackUrl; + } + + public AddressCreator(String phoneNumberCountry, NumberType numberType, SalutationType salutation, String firstName, String lastName, + String addressLine1, String addressLine2, String city, String region, String postalCode, String countryIso) { + + if (!Utils.allNotNull(phoneNumberCountry, numberType, salutation, firstName, lastName, + addressLine1, addressLine2, city, region, postalCode, countryIso)) { + throw new IllegalArgumentException("phoneNumberCountry, numberType, salutation, firstName, lastName," + + "addressLine1, addressLine2, city, region, postalCode and countryIso must not be null"); + } + + this.phoneNumberCountry = phoneNumberCountry; + this.numberType = numberType.toString(); + this.salutation = salutation.toString(); + this.firstName = firstName; + this.lastName = lastName; + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.city = city; + this.region = region; + this.postalCode = postalCode; + this.countryIso = countryIso; + + } + + public AddressCreator callbackUrl(String callbackUrl) { + this.callBackUrl = callbackUrl; + return this; + } + public AddressCreator alias(String alias) { this.alias = alias; return this; } - public AddressCreator salutation(String salutation) { - this.salutation = salutation; - return this; - } - - public AddressCreator firstName(String firstName) { - this.firstName = firstName; - return this; - } - - public AddressCreator lastName(String lastName) { - this.lastName = lastName; - return this; - } - - public AddressCreator addressLine1(String addressLine1) { - this.addressLine1 = addressLine1; - return this; - } - - public AddressCreator addressLine2(String addressLine2) { - this.addressLine2 = addressLine2; - return this; - } - - public AddressCreator city(String city) { - this.city = city; - return this; - } - - public AddressCreator region(String region) { - this.region = region; - return this; - } - - public AddressCreator postalCode(String postalCode) { - this.postalCode = postalCode; - return this; - } - - public AddressCreator file(String file) { - this.file = file; - return this; + public AddressCreator file(String fileName) { + File file = null; + if(!Utils.isValidExtension(fileName)) { + throw new IllegalArgumentException("File that are supported are png,jpg and pdf"); + } + file = new File(fileName); + if(!file.exists()) { + throw new IllegalArgumentException("File not found in the specified path"); + } + if(!Utils.isValidSize(file)) { + throw new IllegalArgumentException("File size exceeds 5 MB"); + } + + this.file = file; + return this; } public AddressCreator autoCorrectAddress(Boolean autoCorrectAddress) { @@ -146,15 +165,48 @@ public AddressCreator autoCorrectAddress(Boolean autoCorrectAddress) { return this; } - public AddressCreator addressProofType(String addressProofType) { - this.addressProofType = addressProofType; + public AddressCreator addressProofType(AddressProofType addressProofType) { + this.addressProofType = addressProofType.toString(); return this; } - - @Override - protected Call obtainCall() { - return client().getApiService().addressCreate(client().getAuthId(), this); - } + + public AddressCreator fiscalIdentificationCode(String fiscalIdentificationCode) { + this.fiscalIdentificationCode = fiscalIdentificationCode; + return this; + } + + public AddressCreator streetCode(String streetCode) { + this.streetCode = streetCode; + return this; + } + + public AddressCreator municipalCode(String municipalCode) { + this.municipalCode = municipalCode; + return this; + } + + public AddressCreator idNumber(String idNumber) { + this.idNumber = idNumber; + return this; + } + + @Override + protected Call obtainCall() { + if(this.countryIso != null && this.countryIso.equals("ES")) { + if(this.fiscalIdentificationCode == null) { + throw new IllegalArgumentException("The parameter fiscal_identification_code is required for Spain numbers"); + } + } + + if(this.countryIso != null && this.countryIso.equals("DK")) { + if(this.streetCode == null || this.municipalCode == null) { + throw new IllegalArgumentException("The parameters street_code and municipal_code are required for Denmark numbers"); + } + } + + return client().getApiService().addressCreate(client().getAuthId(), this); + } + } diff --git a/src/main/java/com/plivo/api/models/address/AddressProofType.java b/src/main/java/com/plivo/api/models/address/AddressProofType.java new file mode 100644 index 00000000..665e90c9 --- /dev/null +++ b/src/main/java/com/plivo/api/models/address/AddressProofType.java @@ -0,0 +1,24 @@ +package com.plivo.api.models.address; + +public enum AddressProofType { + + NATIONALID("national_id"), + PASSPORT("passport"), + BUISNESSID("business_id"), + NIF("NIF"), + NIE("NIE"), + DNI("DNI"); + + private final String addressProofType; + + AddressProofType(final String proofType) { + this.addressProofType = proofType; + } + + @Override + public String toString() { + return this.addressProofType; + } + + +} diff --git a/src/main/java/com/plivo/api/models/address/AddressUpdater.java b/src/main/java/com/plivo/api/models/address/AddressUpdater.java index 75613c58..a5633517 100644 --- a/src/main/java/com/plivo/api/models/address/AddressUpdater.java +++ b/src/main/java/com/plivo/api/models/address/AddressUpdater.java @@ -1,6 +1,10 @@ package com.plivo.api.models.address; +import java.io.File; + import com.plivo.api.models.base.Updater; +import com.plivo.api.util.Utils; + import retrofit2.Call; public class AddressUpdater extends Updater { @@ -14,6 +18,18 @@ public class AddressUpdater extends Updater { private String city; private String region; private String postalCode; + private String callbackUrl; + private Boolean autoCorrectAddress; + private String idNumber; + private String phoneNumberCountry; + private String numberType; + private File file; + private String fiscalIdentificationCode; + private String streetCode; + private String municipalCode; + private String alias; + private String addressProofType; + private String callBackUrl; public AddressUpdater(String id) { super(id); @@ -23,7 +39,55 @@ public String getCountryIso() { return countryIso; } - public String getSalutation() { + public String getCallbackUrl() { + return callbackUrl; + } + + public Boolean getAutoCorrectAddress() { + return autoCorrectAddress; + } + + public String getIdNumber() { + return idNumber; + } + + public String getPhoneNumberCountry() { + return phoneNumberCountry; + } + + public String getNumberType() { + return numberType; + } + + public File getFile() { + return file; + } + + public String getFiscalIdentificationCode() { + return fiscalIdentificationCode; + } + + public String getStreetCode() { + return streetCode; + } + + public String getMunicipalCode() { + return municipalCode; + } + + public String getAlias() { + return alias; + } + + public String getAddressProofType() { + return addressProofType; + } + + public String getCallBackUrl() { + return callBackUrl; + } + + public String getSalutation() { return salutation; } @@ -60,8 +124,8 @@ public AddressUpdater countryIso(String countryIso) { return this; } - public AddressUpdater salutation(String salutation) { - this.salutation = salutation; + public AddressUpdater salutation(SalutationType salutation) { + this.salutation = salutation.toString(); return this; } @@ -99,9 +163,85 @@ public AddressUpdater postalCode(String postalCode) { this.postalCode = postalCode; return this; } - + + public AddressUpdater file(String fileName) { + File file = null; + if(!Utils.isValidExtension(fileName)) { + throw new IllegalArgumentException("File that are supported are png,jpg and pdf"); + } + file = new File(fileName); + if(!file.exists()) { + throw new IllegalArgumentException("File not found in the specified path"); + } + if(!Utils.isValidSize(file)) { + throw new IllegalArgumentException("File size exceeds 5 MB"); + } + this.file = file; + return this; + } + + public AddressUpdater autoCorrectAddress(Boolean autoCorrectAddress) { + this.autoCorrectAddress = autoCorrectAddress; + return this; + } + + public AddressUpdater idNumber(String idNumber) { + this.idNumber = idNumber; + return this; + } + + public AddressUpdater phoneNumberCountry(String phoneNumberCountry) { + this.phoneNumberCountry = phoneNumberCountry; + return this; + } + + public AddressUpdater numberType(NumberType numberType) { + this.numberType = numberType.toString(); + return this; + } + public AddressUpdater fiscalIdentificationCode(String fiscalIdentificationCode) { + this.fiscalIdentificationCode = fiscalIdentificationCode; + return this; + } + + public AddressUpdater streetCode(String streetCode) { + this.streetCode = streetCode; + return this; + } + + public AddressUpdater municipalCode(String municipalCode) { + this.municipalCode = municipalCode; + return this; + } + + public AddressUpdater addressProofType(AddressProofType proofType) { + this.addressProofType = proofType.toString(); + return this; + } + + public AddressUpdater alias(String alias) { + this.alias = alias; + return this; + } + + public AddressUpdater callBackUrl(String callBackUrl) { + this.callBackUrl = callBackUrl; + return this; + } + @Override protected Call obtainCall() { + if(this.countryIso != null && this.countryIso.equals("ES")) { + if(this.fiscalIdentificationCode == null) { + throw new IllegalArgumentException("The parameter fiscal_identification_code is required for Spain numbers"); + } + } + + if(this.countryIso != null && this.countryIso.equals("DK")) { + if(this.streetCode == null || this.municipalCode == null) { + throw new IllegalArgumentException("The parameters street_code and municipal_code are required for Denmark numbers"); + } + } return client().getApiService().addressUpdate(client().getAuthId(), id, this); } } diff --git a/src/main/java/com/plivo/api/models/address/FileExtensionType.java b/src/main/java/com/plivo/api/models/address/FileExtensionType.java new file mode 100644 index 00000000..14199efd --- /dev/null +++ b/src/main/java/com/plivo/api/models/address/FileExtensionType.java @@ -0,0 +1,18 @@ +package com.plivo.api.models.address; + +public enum FileExtensionType { + PNG("png"), + JPG("jpg"), + PDF("pdf"); + + private final String fileType; + + FileExtensionType(final String fileType) { + this.fileType = fileType; + } + + @Override + public String toString() { + return this.fileType; + } +} diff --git a/src/main/java/com/plivo/api/models/address/NumberType.java b/src/main/java/com/plivo/api/models/address/NumberType.java new file mode 100644 index 00000000..2c44e126 --- /dev/null +++ b/src/main/java/com/plivo/api/models/address/NumberType.java @@ -0,0 +1,20 @@ +package com.plivo.api.models.address; + +public enum NumberType { + LOCAL("local"), + NATIONAL("national"), + MOBILE("mobile"), + TOLLFREE("tollfree"); + + private final String numberType; + + NumberType(final String numberType) { + this.numberType = numberType; + } + + @Override + public String toString() { + return this.numberType; + } + +} diff --git a/src/main/java/com/plivo/api/models/address/SalutationType.java b/src/main/java/com/plivo/api/models/address/SalutationType.java new file mode 100644 index 00000000..97a23335 --- /dev/null +++ b/src/main/java/com/plivo/api/models/address/SalutationType.java @@ -0,0 +1,17 @@ +package com.plivo.api.models.address; + +public enum SalutationType { + MR("Mr"), + MRS("Mrs"); + + private final String salutation; + + SalutationType(final String salutation) { + this.salutation = salutation; + } + + @Override + public String toString() { + return this.salutation; + } +} diff --git a/src/main/java/com/plivo/api/util/Utils.java b/src/main/java/com/plivo/api/util/Utils.java index 8b96d592..cb148218 100644 --- a/src/main/java/com/plivo/api/util/Utils.java +++ b/src/main/java/com/plivo/api/util/Utils.java @@ -1,6 +1,8 @@ package com.plivo.api.util; import com.fasterxml.jackson.databind.ObjectMapper; +import com.plivo.api.models.address.FileExtensionType; + import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -18,6 +20,7 @@ import javax.crypto.spec.SecretKeySpec; import java.net.URL; import java.net.MalformedURLException; +import java.io.File; import java.io.UnsupportedEncodingException; public class Utils { @@ -83,4 +86,28 @@ public static boolean validateSignature(String url, String nonce, String signatu throws NoSuchAlgorithmException, InvalidKeyException, MalformedURLException, UnsupportedEncodingException { return computeSignature(url, nonce, authToken).equals(signature); } + + public static boolean isValidExtension(String fileName) { + String[] fileParts = fileName.split("\\."); + if(fileParts.length<2) { + throw new IllegalArgumentException("Invalid file specified"); + } + String extension = fileParts[fileParts.length-1].toLowerCase(); + if(extension.equals(FileExtensionType.JPG.toString()) || + extension.equals(FileExtensionType.PNG.toString()) || + extension.equals(FileExtensionType.PDF.toString())) { + return true; + } + return false; + } + + public static boolean isValidSize(File file) { + long sizeInBytes = file.length(); + long sizeInMb = sizeInBytes / (1024 * 1024); + if(sizeInMb >= 5) { + return false; + } + return true; + } + } diff --git a/src/test/java/com/plivo/api/AddressTest.java b/src/test/java/com/plivo/api/AddressTest.java index c85b27c4..4580d801 100644 --- a/src/test/java/com/plivo/api/AddressTest.java +++ b/src/test/java/com/plivo/api/AddressTest.java @@ -4,6 +4,8 @@ import static junit.framework.TestCase.assertEquals; import com.plivo.api.models.address.Address; +import com.plivo.api.models.address.NumberType; +import com.plivo.api.models.address.SalutationType; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.RecordedRequest; import org.junit.Test; @@ -14,14 +16,16 @@ public void addressCreateShouldSucceed() throws Exception { expectResponse("addressCreateResponse.json", 201); Address.creator("FR", - "Mr", + NumberType.LOCAL, + SalutationType.MR, "Bruce", "Wayne", "128", "RUE DU COMMANDANT GUILBAUD", "PARIS", "PARIS", - "75016") + "75016", + "UK") .create(); assertRequest("POST", "Verification/Address/"); @@ -34,14 +38,16 @@ public void addressCreateWithClientShouldSucceed() throws Exception { "Zmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); Address.creator("FR", - "Ms", + NumberType.LOCAL, + SalutationType.MR, "Bruce", "Wayne", "128", "RUE DU COMMANDANT GUILBAUD", "PARIS", "PARIS", - "75016") + "75016", + "UK") .client(client) .create(); From 49a47a661901c0da1c85d7201bdeea7246c9c913 Mon Sep 17 00:00:00 2001 From: Suhas Reddy Mulkalla Date: Fri, 22 Feb 2019 15:13:23 +0530 Subject: [PATCH 2/2] [SDK-141] Code samples with latest SDK: Java --- .../java/com/plivo/examples/Accounts.java | 242 +++++--- .../java/com/plivo/examples/Addresses.java | 169 ++++++ .../java/com/plivo/examples/Applications.java | 172 ++++++ src/main/java/com/plivo/examples/Calls.java | 528 ++++++++++++++++++ .../java/com/plivo/examples/Conferences.java | 515 +++++++++++++++++ .../java/com/plivo/examples/Endpoints.java | 176 ++++++ .../java/com/plivo/examples/Identities.java | 207 +++++++ .../java/com/plivo/examples/Messages.java | 114 ++++ src/main/java/com/plivo/examples/Numbers.java | 236 ++++++++ .../com/plivo/examples/PricingExample.java | 50 ++ .../java/com/plivo/examples/Recordings.java | 113 ++++ 11 files changed, 2435 insertions(+), 87 deletions(-) create mode 100644 src/main/java/com/plivo/examples/Addresses.java create mode 100644 src/main/java/com/plivo/examples/Applications.java create mode 100644 src/main/java/com/plivo/examples/Calls.java create mode 100644 src/main/java/com/plivo/examples/Conferences.java create mode 100644 src/main/java/com/plivo/examples/Endpoints.java create mode 100644 src/main/java/com/plivo/examples/Identities.java create mode 100644 src/main/java/com/plivo/examples/Messages.java create mode 100644 src/main/java/com/plivo/examples/Numbers.java create mode 100644 src/main/java/com/plivo/examples/PricingExample.java create mode 100644 src/main/java/com/plivo/examples/Recordings.java diff --git a/src/main/java/com/plivo/examples/Accounts.java b/src/main/java/com/plivo/examples/Accounts.java index 34a1e2f3..b770fc72 100644 --- a/src/main/java/com/plivo/examples/Accounts.java +++ b/src/main/java/com/plivo/examples/Accounts.java @@ -8,96 +8,164 @@ import com.plivo.api.models.account.AccountUpdateResponse; import com.plivo.api.models.account.Subaccount; import com.plivo.api.models.account.SubaccountCreateResponse; +import com.plivo.api.models.base.ListResponse; import java.io.IOException; public class Accounts { - private static final String authId = "MANTXXXXXXXXXXXXXXXX"; - private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; - private static PlivoClient client = new PlivoClient(authId, authToken); - - public static void main(String[] args) { - Plivo.init(authId, authToken); -// getAccountInfo(); -// getAccountInfoBySettingClient(); -// modifyAccount(); -// modifyAccountBySettingClient(); - createSubAccount(); -// createSubAccountBySettingClient(); - - } - - // trying to get account info without setting the client - private static void getAccountInfo() { - try { - Account response = Account.getter() - .get(); - System.out.println(response); - } catch (PlivoRestException | IOException e) { - e.printStackTrace(); - } - } - - // trying to get account info by setting the client - private static void getAccountInfoBySettingClient() { - try { - Account response = Account.getter() - .client(client) - .get(); - System.out.println(response); - } catch (PlivoRestException | IOException e) { - e.printStackTrace(); - } - } - - // update account - private static void modifyAccount() { - try { - AccountUpdateResponse response = Account.updater() - .address("Test Address") - .update(); - System.out.println(response); - } catch (PlivoRestException | IOException e) { - e.printStackTrace(); - } - } - - // update account with different client settings - private static void modifyAccountBySettingClient() { - try { - AccountUpdateResponse response = Account.updater() - .city("Test city") - .client(client) - .update(); - System.out.println(response); - } catch (PlivoRestException | IOException e) { - e.printStackTrace(); - } - } - - // create subaccount - private static void createSubAccount() { - try { - SubaccountCreateResponse subaccount = Subaccount.creator("Test") - .enabled(true) - .create(); - System.out.println(subaccount); - } catch (PlivoRestException | IOException e) { - e.printStackTrace(); - } - } - - // create subaccount with different client settings - private static void createSubAccountBySettingClient() { - try { - SubaccountCreateResponse subaccount = Subaccount.creator("Test 2") - .enabled(true) - .client(client) - .create(); - System.out.println(subaccount); - } catch (PlivoRestException | IOException e) { - e.printStackTrace(); - } - } + +//Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createSubAccount(); + } + + // Example to get Account details + // Client is set by Plivo.init helper method in main() + private static void getAccountInfo() { + try { + Account response = Account.getter() + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get Account details with client + // Client is set explicitly as shown below + private static void getAccountWithClient() { + try { + Account response = Account.getter() + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to update Account details + // Client is set by Plivo.init helper method in main() + + private static void modifyAccount() { + try { + AccountUpdateResponse response = Account.updater() + .address("Test Address") + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update Account details with client + // Client is set explicitly as shown below + + private static void modifyAccountWithClient() { + try { + AccountUpdateResponse response = Account.updater() + .city("Test city") + .client(client) + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to create a sub-account + //Client is set by Plivo.init helper method in main() + + private static void createSubAccount() { + try { + SubaccountCreateResponse subaccount = Subaccount.creator("Test") + .enabled(true) + .create(); + System.out.println(subaccount); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to create a sub-account + // Client is set explicitly as shown below + + private static void createSubAccountWithClient() { + try { + SubaccountCreateResponse subaccount = Subaccount.creator("Test 2") + .enabled(true) + .client(client) + .create(); + System.out.println(subaccount); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all sub-accounts + // Client is set by Plivo.init helper method in main() + + private static void listAllSubAccount() { + try { + ListResponse response = Subaccount.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all sub accounts with client + // Client is set explicitly as shown below + + private static void listAllSubAccountWithClient() { + try { + ListResponse response = Subaccount.lister() + .client(client) + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + + // Example to delete a sub-account + //Client is set by Plivo.init helper method in main() + + private static void deleteSubAccount() { + try { + Subaccount.deleter("sub_account_id").delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete sub-account with client + // Client is set explicitly as shown below + + private static void deleteSubAccountWithClient() { + try { + Subaccount.deleter("sub_account_id").client(client).delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/plivo/examples/Addresses.java b/src/main/java/com/plivo/examples/Addresses.java new file mode 100644 index 00000000..b6a00237 --- /dev/null +++ b/src/main/java/com/plivo/examples/Addresses.java @@ -0,0 +1,169 @@ +package com.plivo.examples; + +import java.io.IOException; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.address.Address; +import com.plivo.api.models.address.AddressCreateResponse; +import com.plivo.api.models.address.AddressUpdateResponse; +import com.plivo.api.models.address.NumberType; +import com.plivo.api.models.address.SalutationType; +import com.plivo.api.models.base.ListResponse; + +public class Addresses { + //Initialize the following authId and authToken with valid authId and authToken + + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createAddress(); + } + + // Example to create a address + // Client is set by Plivo.init helper method in main() + // The following params are mandatory + private static void createAddress() { + try { + AddressCreateResponse response = Address.creator( + "DK", + NumberType.LOCAL, + SalutationType.MR , + "firstName", + "lastName", + "addressLine1", + "addressLine2", + "City", + "Region", + "PostalCode", + "IN") + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to create a address with client + // Client is set explicitly as shown below + // The following params are mandatory + private static void createAddressWithClient() { + try { + AddressCreateResponse response = Address.creator( + "DK", + NumberType.LOCAL, + SalutationType.MR , + "firstName", + "lastName", + "addressLine1", + "addressLine2", + "City", + "Region", + "PostalCode", + "IN") + .client(client) + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a address + // Client is set by Plivo.init helper method in main() + private static void getAddressInfo() { + try { + Address response = Address.getter("document_id").get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a address with client + // Client is set explicitly as shown below + private static void getAddressInfoWithClient() { + try { + Address response = Address.getter("document_id").client(client).get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list addresses + // Client is set by Plivo.init helper method in main() + private static void listAddresses() { + try { + ListResponse
response = Address.lister().list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list addresses with client + // Client is set explicitly as shown below + private static void listAddressesWithClient() { + try { + ListResponse
response = Address.lister().client(client).list(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update address + // Client is set by Plivo.init helper method in main() + private static void updateAddressInfo() { + try { + AddressUpdateResponse response = Address.updater("documentId"). + streetCode("PK").update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update address with client + // Client is set explicitly as shown below + private static void updateAddressInfoWithClient() { + try { + AddressUpdateResponse response = Address.updater("documentId"). + streetCode("PK").client(client).update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete a address + // Client is set by Plivo.init helper method in main() + private static void deleteAddressInfo() { + try { + Address.deleter("documentID").delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + //Example to delete a address with client + // Client is set by Plivo.init helper method in main() + private static void deleteAddressInfoWithClient() { + try { + Address.deleter("documentID").client(client).delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/plivo/examples/Applications.java b/src/main/java/com/plivo/examples/Applications.java new file mode 100644 index 00000000..bbe7a0ae --- /dev/null +++ b/src/main/java/com/plivo/examples/Applications.java @@ -0,0 +1,172 @@ +package com.plivo.examples; + +import java.io.IOException; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.application.Application; +import com.plivo.api.models.application.ApplicationCreateResponse; +import com.plivo.api.models.application.ApplicationUpdateResponse; +import com.plivo.api.models.base.ListResponse; + +public class Applications { + +//Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createApplication(); + } + + // Example to create a application + // Client is set by Plivo.init helper method in main() + // Application name and answer url are mandatory params + + private static void createApplication() { + try { + ApplicationCreateResponse response = Application.creator("Test Application") + .answerUrl("http://answerurl") + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to create a application with client + // client is set explicitly as shown below + // Application name and answer url are mandatory params + + private static void createApplicationWithClient() { + try { + ApplicationCreateResponse response = Application.creator("Test Application") + .answerUrl("http://answerurl") + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a application + // Client is set by Plivo.init helper method in main() + // Pass the app_id of the application + private static void getApplicationInfo() { + try { + Application response = Application.getter("997752XXXJJDXXX265") + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to get details of a application with client + // client is set explicitly as shown below + // Pass the app_id of the application + private static void getApplicationInfoWithClient() { + try { + Application response = Application.getter("997752XXXJJDXXX265") + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a application + // Client is set by Plivo.init helper method in main() + // Pass the app_id of the application + private static void updateApplicationInfo() { + try { + ApplicationUpdateResponse response = Application.updater("997752XXXJJDXXX265") + .answerUrl("http://updatedanswerurl") + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a application with client + // client is set explicitly as shown below + // Pass the app_id of the application + private static void updateApplicationInfoWithClient() { + try { + ApplicationUpdateResponse response = Application.updater("997752XXXJJDXXX265") + .answerUrl("http://updatedanswerurl") + .client(client) + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + //Example to delete a application with client + // Client is set by Plivo.init helper method in main() + // Pass the app_id of the application + private static void deleteApplication() { + try { + Application.deleter("997752XXXJJDXXX265").delete(); + System.out.println("Application deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete a application with client + // client is set explicitly as shown below + // Pass the app_id of the application + private static void deleteApplicationWithClient() { + try { + Application.deleter("997752XXXJJDXXX265").client(client).delete(); + System.out.println("Application deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all applications + // Client is set by Plivo.init helper method in main() + private static void listAllApplications() { + try { + ListResponse response = Application.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all applications with client + // client is set explicitly as shown below + // Pass the app_id of the application + private static void listAllApplicationsWithClient() { + try { + ListResponse response = Application.lister() + .client(client) + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/plivo/examples/Calls.java b/src/main/java/com/plivo/examples/Calls.java new file mode 100644 index 00000000..96c6d331 --- /dev/null +++ b/src/main/java/com/plivo/examples/Calls.java @@ -0,0 +1,528 @@ +package com.plivo.examples; + +import java.io.IOException; +import java.util.Collections; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.base.ListResponse; +import com.plivo.api.models.call.Call; +import com.plivo.api.models.call.CallCreateResponse; +import com.plivo.api.models.call.CallDirection; +import com.plivo.api.models.call.CallUpdateResponse; +import com.plivo.api.models.call.LegSpecifier; +import com.plivo.api.models.call.LiveCall; +import com.plivo.api.models.call.LiveCallListResponse; +import com.plivo.api.models.call.QueuedCall; +import com.plivo.api.models.call.QueuedCallListResponse; +import com.plivo.api.models.call.actions.CallDtmfCreateResponse; +import com.plivo.api.models.call.actions.CallPlayCreateResponse; +import com.plivo.api.models.call.actions.CallRecordCreateResponse; +import com.plivo.api.models.call.actions.CallSpeakCreateResponse; + +public class Calls { + +//Initialize the following authId and authToken with valid authId and authToken + + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createCall(); + } + + // Example to create a call + // Client is set by Plivo.init helper method in main() + // from, to and answer_url are mandatory params + + private static void createCall() { + try { + CallCreateResponse response = Call.creator("from_number", Collections.singletonList("to_number"), "http://answerurl") + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to create a call with client + // Client is set explicitly as shown below + // from, to and answer_url are mandatory params + + private static void createCallWithClient() { + try { + CallCreateResponse response = Call.creator("from_number", Collections.singletonList("to_number"), "http://answerurl") + .client(client) + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to get call details + // Client is set by Plivo.init helper method in main() + // pass call_id of corresponding call + + private static void getCallDetails() { + try { + Call response = Call.getter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + //Example to get call details with client + // Client is set explicitly as shown below + // pass call_id of corresponding call + + private static void getCallDetailsWithClient() { + try { + Call response = Call.getter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a call + // Client is set by Plivo.init helper method in main() + // pass call_id of corresponding call + + private static void updateCallDetails() { + try { + CallUpdateResponse response = Call.updater("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .legs(LegSpecifier.ALEG) + .alegUrl("https://example.com/connect") + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a call with client + // Client is set explicitly as shown below + // pass call_id of corresponding call + + private static void updateDetailsWithClient() { + try { + CallUpdateResponse response = Call.updater("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .legs(LegSpecifier.ALEG) + .alegUrl("https://example.com/connect") + .client(client) + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a call + // Client is set by Plivo.init helper method in main() + // pass call_id of corresponding call + + private static void deleteACall() { + try { + Call.deleter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .delete(); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a call with client + // Client is set explicitly as shown below + // pass call_id of corresponding call + + private static void deleteACallWithClient() { + try { + Call.deleter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .delete(); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + //Example to list all calls + // Client is set by Plivo.init helper method in main() + + private static void listAllCalls() { + try { + ListResponse response = Call.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all calls with client + // Client is set explicitly as shown below + + private static void listAllCallsWithClient() { + try { + ListResponse response = Call.lister() + .client(client) + .limit(5) + .offset(0) + .list(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a live call + // Client is set by Plivo.init helper method in main() + // pass LiveCallID of corresponding call + + private static void getLiveCallInfo() { + try { + LiveCall response = LiveCall.getter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .get(); + System.out.println(response); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a live call with client + // Client is set explicitly as shown below + // pass LiveCallID of corresponding call + + private static void getLiveCallInfoWithClient() { + try { + LiveCall response = LiveCall.getter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .get(); + System.out.println(response); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all Live calls + // Client is set by Plivo.init helper method in main() + + private static void listAllLiveCalls() { + try { + LiveCallListResponse response = LiveCall.listGetter() + .callDirection(CallDirection.INBOUND) + .fromNumber("from_number") + .toNumber("to_number") + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all Live calls with client + // Client is set explicitly as shown below + + private static void listAllLiveCallsWithClient() { + try { + LiveCallListResponse response = LiveCall.listGetter() + .callDirection(CallDirection.INBOUND) + .fromNumber("from_number") + .toNumber("to_number") + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + //Example to get details of a QueuedCall + // Client is set by Plivo.init helper method in main() + // pass CallID of corresponding call + + private static void getQueuedCallInfo() { + try { + QueuedCall response = QueuedCall.getter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a queued call with client + // Client is set explicitly as shown below + // pass callId of corresponding call + + private static void getQueuedCallInfoWithClient() { + try { + QueuedCall response = QueuedCall.getter("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all queued calls + // Client is set by Plivo.init helper method in main() + + private static void listAllQueuedCalls() { + try { + QueuedCallListResponse response = QueuedCall.listGetter() + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all Queued calls with client + // Client is set explicitly as shown below + + private static void listAllQueuedCallsWithClient() { + try { + QueuedCallListResponse response = QueuedCall.listGetter() + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to record a call + // Client is set by Plivo.init helper method in main() + // Pass call_id of the call + private static void recordACall() { + try { + CallRecordCreateResponse response = Call.recorder("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .record(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to record a call with client + // Client is set explicitly as shown below + // Pass call_id of the call + private static void recordACallWithClient() { + try { + CallRecordCreateResponse response = Call.recorder("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .record(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to stop call record + // Client is set by Plivo.init helper method in main() + // Pass call_id of the call + private static void stopACallRecord() { + try { + Call.recordStopper("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .recordStop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to stop call record with client + // Client is set explicitly as shown below + // Pass call_id of the call + private static void stopACallRecordWithClient() { + try { + Call.recordStopper("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .recordStop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to play audio on call + // Client is set by Plivo.init helper method in main() + // Pass call_id of the call and audio url of the call + private static void playAudioOnACall() { + try { + CallPlayCreateResponse response = Call.player("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", Collections.singletonList("https://audio_url")) + .play(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to play audio on call with client + // Client is set explicitly as shown below + // Pass call_id of the call and audio url of the call + + private static void playAudioOnACallWithClient() { + try { + CallPlayCreateResponse response = Call.player("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", Collections.singletonList("https://audio_url")) + .client(client) + .play(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to stop audio on call + // Client is set by Plivo.init helper method in main() + // Pass call_id of the call + + private static void stopAudioOnACall() { + try { + Call.playStopper("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .playStop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to stop audio on call with client + // Client is set explicitly as shown below + + private static void stopAudioOnACallWithClient() { + try { + Call.playStopper("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .playStop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to speak text on call + // Client is set by Plivo.init helper method in main() + //Pass call_id of the call and text to speak + + + private static void speakTextOnACall() { + try { + CallSpeakCreateResponse response = Call.speaker("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", "Hello World") + .speak(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to speak text on call with client + // Client is set explicitly as shown below + //Pass call_id of the call and text to speak + private static void speakTextOnACallWithClient() { + try { + CallSpeakCreateResponse response = Call.speaker("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", "Hello World") + .client(client) + .speak(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to stop text speak on call + // Client is set by Plivo.init helper method in main() + // Pass call_id of the call + + private static void stopSpeakTextOnACall() { + try { + CallSpeakCreateResponse response = Call.speaker("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", "Hello World") + .speak(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to stop text speak on call with client + // Client is set explicitly as shown below + // Pass call_id of the call + + private static void stopSpeakTextOnACallWithClient() { + try { + Call.speakStopper("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4") + .client(client) + .speakStop(); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example send digits on call + // Client is set by Plivo.init helper method in main() + // Pass call_id of the active call + private static void sendDigitsOnACall() { + try { + CallDtmfCreateResponse response = Call.digitSender("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", "123") + .sendDigits(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to send digits on call with client + // Client is set explicitly as shown below + // Pass call_id of the active call + + private static void sendDigitsOnCallWithClient() { + try { + CallDtmfCreateResponse response = Call.digitSender("10f0cb68-XXX-XXXXX-acb5-87ceac29ee4", "123") + .client(client) + .sendDigits(); + + System.out.println(response); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/plivo/examples/Conferences.java b/src/main/java/com/plivo/examples/Conferences.java new file mode 100644 index 00000000..3822fd5f --- /dev/null +++ b/src/main/java/com/plivo/examples/Conferences.java @@ -0,0 +1,515 @@ +package com.plivo.examples; + +import java.io.IOException; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.conference.Conference; +import com.plivo.api.models.conference.ConferenceList; +import com.plivo.api.models.conference.ConferenceMemberActionResponse; +import com.plivo.api.models.conference.ConferenceRecordCreateResponse; + +public class Conferences { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + getConferenceDetails(); + } + + // Example to get details of a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name + private static void getConferenceDetails() { + try { + Conference response = Conference.getter("My Conf Room") + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a Conference with client + // Client is set explicitly as shown below + // Pass the conference name + + private static void getConferenceDetailsWithClient() { + try { + Conference response = Conference.getter("My Conf Room") + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to record a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name + private static void recordConference() { + + try { + ConferenceRecordCreateResponse response = Conference.recorder("My Conf Room") + .record(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to record a Conference with client + // Client is set explicitly as shown below + // Pass the conference name + private static void recordConferenceWithClient() { + + try { + ConferenceRecordCreateResponse response = Conference.recorder("My Conf Room") + .client(client) + .record(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to stop a Conference record + // Client is set by Plivo.init helper method in main() + // Pass the conference name + private static void stopConferenceRecord() { + + try { + Conference.recordStopper("My Conf Room") + .stop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to stop a Conference record with client + // Client is set explicitly as shown below + // Pass the conference name + private static void stopConferenceRecordWithClient() { + + try { + Conference.recordStopper("My Conf Room") + .client(client) + .stop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name + private static void deleteConference() { + + try { + Conference.deleter("My Conf Room") + .delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete a Conference with client + // Client is set explicitly as shown below + // Pass the conference name + private static void deleteConferenceWithClient() { + + try { + Conference.deleter("My Conf Room") + .client(client) + .delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete all Conference + // Client is set by Plivo.init helper method in main() + + private static void deleteAllConferences() { + + try { + Conference.allDeleter() + .delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete all Conference with client + // Client is set explicitly as shown below + + private static void deleteAllConferencesWithClient() { + + try { + Conference.allDeleter() + .client(client) + .delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all Conferences + // Client is set by Plivo.init helper method in main() + // Pass the conference name + private static void listConferences() { + + try { + ConferenceList response = Conference.listGetter() + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all Conferences with client + // Client is set explicitly as shown below + // Pass the conference name + private static void listConferencesWithClient() { + + try { + ConferenceList response = Conference.listGetter() + .client(client) + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to hang up a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name and member ID + private static void hangupAMemberInConferences() { + + try { + Conference.memberHangupper("My Conf Room", "1") + .hangup(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to hang up a member in a Conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void hangupAMemberInConferencesWithClient() { + + try { + Conference.memberHangupper("My Conf Room", "1") + .client(client) + .hangup(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to kickout a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name and member ID + private static void kickAMemberInConferences() { + + try { + Conference.memberKicker("My Conf Room", "1") + .kick(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to kick a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void kickAMemberInConferencesWithClient() { + + try { + Conference.memberKicker("My Conf Room", "1") + .client(client) + .kick(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + + // Example to mute a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name and member ID + private static void muteAMemberInConferences() { + + try { + Conference.memberMuter("My Conf Room", "1") + .mute(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to mute a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void muteAMemberInConferencesWithClient() { + + try { + Conference.memberMuter("My Conf Room", "1") + .client(client) + .mute(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + + + // Example to unmute a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name and member ID + private static void unmuteAMemberInConferences() { + + try { + Conference.memberMuteStopper("My Conf Room", "1") + .stop(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to unmute a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void unmuteAMemberInConferencesWithClient() { + + try { + Conference.memberMuteStopper("My Conf Room", "1") + .client(client) + .stop(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + // Example to deaf a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name and member ID + private static void deafAMemberInConferences() { + + try { + Conference.memberDeafer("My Conf Room", "1") + .deaf(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to deaf a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void deafAMemberInConferencesWithClient() { + + try { + Conference.memberDeafer("My Conf Room", "1") + .client(client) + .deaf(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + + // Example to undeaf a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name and member ID + private static void undeafAMemberInConferences() { + + try { + Conference.memberDeafStopper("My Conf Room", "1") + .stop(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to undeaf a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void undeafAMemberInConferencesWithClient() { + + try { + Conference.memberDeafStopper("My Conf Room", "1") + .client(client) + .stop(); + + System.out.println("Deleted successfully."); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + + // Example to play audio to a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name , member ID and audio url + private static void playAudioToAMemberInConferences() { + + try { + ConferenceMemberActionResponse response = Conference.memberPlayer("My Conf Room", "10", "https://audio_url") + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to play audio to a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID and audio url + private static void playAudioToMemberInConferencesWithClient() { + + try { + ConferenceMemberActionResponse response = Conference.memberPlayer("My Conf Room", "10", "https://audio_url") + .client(client) + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + + // Example to stop audio to a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name , member ID + private static void stopAudioToAMemberInConferences() { + + try { + Conference.memberPlayStopper("My Conf Room", "10") + .stop(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to stop audio to a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void stopAudioToMemberInConferencesWithClient() { + + try { + Conference.memberPlayStopper("My Conf Room", "10") + .stop(); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + // Example to play Text to a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name , member ID and text to play + private static void playTextToAMemberInConferences() { + + try { + ConferenceMemberActionResponse response = Conference.memberSpeaker("My Conf Room", "10", "Hello World!") + .speak(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to play Text to a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID and text to play + private static void playTextToMemberInConferencesWithClient() { + try { + ConferenceMemberActionResponse response = Conference.memberSpeaker("My Conf Room", "10", "Hello World!") + .client(client) + .speak(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to stop play text to a member in a Conference + // Client is set by Plivo.init helper method in main() + // Pass the conference name , member ID + private static void stopPlayTextToAMemberInConferences() { + + try { + Conference.memberSpeakStopper("My Conf Room", "10") + .delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to stop play text to a member in a conference with client + // Client is set explicitly as shown below + // Pass the conference name and member ID + private static void stopPlayTextToMemberInConferencesWithClient() { + + try { + Conference.memberSpeakStopper("My Conf Room", "10") + .client(client) + .delete(); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/com/plivo/examples/Endpoints.java b/src/main/java/com/plivo/examples/Endpoints.java new file mode 100644 index 00000000..ca25f814 --- /dev/null +++ b/src/main/java/com/plivo/examples/Endpoints.java @@ -0,0 +1,176 @@ +package com.plivo.examples; + +import java.io.IOException; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.base.ListResponse; +import com.plivo.api.models.endpoint.Endpoint; +import com.plivo.api.models.endpoint.EndpointCreateResponse; +import com.plivo.api.models.endpoint.EndpointUpdateResponse; + +public class Endpoints { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createEndpoint(); + } + + // Example to create a endpoint + // Client is set by Plivo.init helper method in main() + // username, password and alias for the endpoint are mandatory params + private static void createEndpoint() { + try { + EndpointCreateResponse response = Endpoint.creator("testusername", "testpassword", "Test Account") + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to create a endpoint with client + // Client is set explicitly as shown below + // username, password and alias for the endpoint are mandatory params + private static void createEndpointWithClient() { + try { + EndpointCreateResponse response = Endpoint.creator("testusername", "testpassword", "Test Account") + .client(client) + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + + // Example to get endpoint details + // Client is set by Plivo.init helper method in main() + // Pass endpointID to fetch the details + private static void getEndpoint() { + try { + Endpoint response = Endpoint.getter("endpoint_id") + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get a endpoint details with client + // Client is set explicitly as shown below + //Pass endpointID to fetch the details + + private static void getEndpointWithClient() { + try { + Endpoint response = Endpoint.getter("endpoint_id") + .client(client) + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to update endpoint details + // Client is set by Plivo.init helper method in main() + // Pass endpointID to update the endpoint + private static void updateEndpoint() { + try { + EndpointUpdateResponse response = Endpoint.updater("endpoint_id") + .alias("Updated Endpoint Alias") + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a endpoint details with client + // Client is set explicitly as shown below + // Pass endpointID to update the endpoint + + private static void updateEndpointWithClient() { + try { + EndpointUpdateResponse response = Endpoint.updater("endpoint_id") + .alias("Updated Endpoint Alias") + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all endpoints + // Client is set by Plivo.init helper method in main() + private static void listAllEndpoints() { + try { + ListResponse response = Endpoint.lister() + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all endpoints + // Client is set explicitly as shown below + + private static void listAllEndpointsWithClient() { + try { + ListResponse response = Endpoint.lister() + .client(client) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a endpoint + // Client is set by Plivo.init helper method in main() + // Pass endpointID to delete + private static void deleteAEndpoint() { + try { + Endpoint.deleter("endpoint_id") + .delete(); + + System.out.println("Deleted endpoint successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete a endpoint with client + // Client is set explicitly as shown below + // Pass endpointID to delete + + private static void deleteAEndpointWithClient() { + try { + Endpoint.deleter("endpoint_id") + .client(client) + .delete(); + + System.out.println("Deleted endpoint successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/plivo/examples/Identities.java b/src/main/java/com/plivo/examples/Identities.java new file mode 100644 index 00000000..10d06509 --- /dev/null +++ b/src/main/java/com/plivo/examples/Identities.java @@ -0,0 +1,207 @@ +package com.plivo.examples; + +import java.io.IOException; +import java.time.LocalDate; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.base.ListResponse; +import com.plivo.api.models.identity.Identity; +import com.plivo.api.models.identity.IdentityCreateResponse; +import com.plivo.api.models.identity.IdentityUpdateResponse; + +public class Identities { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createIdentity(); + } + + // Example to create a Identity + // Client is set by Plivo.init helper method in main() + // The following params that are passed are mandatory + private static void createIdentity() { + try { + + IdentityCreateResponse response = Identity.creator( + "IN", + "MR" , + "firstName", + "lastName", + "birthPlace", + LocalDate.of(1990,11,12), + "nationality", + "idNationality", + LocalDate.of(2000,12,23), + "businessName", + "idType", + "idNumber", + "addressLine1", + "addressLine2", + "City", + "Region", + "PostalCode") + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + + // Example to create a Identity with client + // Client is set explicitly as shown below + // The following params that are passed are mandatory + private static void createIdentityWithClient() { + try { + + IdentityCreateResponse response = Identity.creator( + "IN", + "MR" , + "firstName", + "lastName", + "birthPlace", + LocalDate.of(1990,11,12), + "nationality", + "idNationality", + LocalDate.of(2000,12,23), + "businessName", + "idType", + "idNumber", + "addressLine1", + "addressLine2", + "City", + "Region", + "PostalCode") + .client(client) + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all identities + // Client is set by Plivo.init helper method in main() + private static void listAllIdentites() { + try { + ListResponse response = Identity.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all identities with client + // Client is set explicitly as shown below + private static void listAllIdentitesWithClient() { + try { + ListResponse response = Identity.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a identity + // Client is set by Plivo.init helper method in main() + // Pass the documentId of the identity + private static void getIdentityInfo() { + try { + Identity response = Identity.getter("document_id") + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get details of a identity with client + // Client is set explicitly as shown below + // Pass the documentId of the identity + private static void getIdentityInfoWithClient() { + try { + Identity response = Identity.getter("document_id") + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a identity + // Client is set by Plivo.init helper method in main() + // Pass the document_id of the identity + private static void updateIdentityInfo() { + try { + IdentityUpdateResponse response = Identity.updater("document_id") + .city("newCity") + .postalCode("newPostalCode") + .countryIso("newCountryISO") + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update a identity with client + // Client is set explicitly as shown below + // Pass the document_id of the identity + private static void updateIdentityInfowithClient() { + try { + IdentityUpdateResponse response = Identity.updater("document_id") + .city("newCity") + .postalCode("newPostalCode") + .countryIso("newCountryISO") + .client(client) + .update(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to delete a identity + // Client is set by Plivo.init helper method in main() + // Pass the app_id of the identity + private static void deleteIdentity() { + try { + Identity.deleter("document_id").delete(); + System.out.println("Identity deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a identity with client + // Client is set explicitly as shown below + // Pass the app_id of the identity + private static void deleteIdentityWithClient() { + try { + Identity.deleter("document_id").client(client).delete(); + System.out.println("Identity deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + +} diff --git a/src/main/java/com/plivo/examples/Messages.java b/src/main/java/com/plivo/examples/Messages.java new file mode 100644 index 00000000..8af726ab --- /dev/null +++ b/src/main/java/com/plivo/examples/Messages.java @@ -0,0 +1,114 @@ +package com.plivo.examples; + +import java.io.IOException; +import java.util.Collections; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.base.ListResponse; +import com.plivo.api.models.message.Message; +import com.plivo.api.models.message.MessageCreateResponse; + +public class Messages { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + createMessage(); + } + + // Example to create a Message + // Client is set by Plivo.init helper method in main() + // The following params that are passed are mandatory + private static void createMessage() { + try { + MessageCreateResponse response = Message.creator("from_number", Collections.singletonList("to_number"), "Test Message") + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to create a Message with client + // Client is set explicitly as shown below + // The following params that are passed are mandatory + private static void createMessageWithClient() { + try { + MessageCreateResponse response = Message.creator("from_number", Collections.singletonList("to_number"), "Test Message") + .client(client) + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get Message info + // Client is set by Plivo.init helper method in main() + // Pass message_uuid to get the info + private static void getMessageInfo() { + try { + Message response = Message.getter("message_uuid") + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to get Message info with client + // Client is set explicitly as shown below + // Pass message_uuid to get the info + private static void getMessageInfoWithClient() { + try { + Message response = Message.getter("message_uuid") + .client(client) + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all messages + // Client is set by Plivo.init helper method in main() + private static void listAllMessages() { + try { + ListResponse response = Message.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all messages with client + // Client is set explicitly as shown below + private static void listAllMessagesWithClient() { + try { + ListResponse response = Message.lister() + .limit(5) + .offset(0) + .client(client) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/plivo/examples/Numbers.java b/src/main/java/com/plivo/examples/Numbers.java new file mode 100644 index 00000000..1e28318e --- /dev/null +++ b/src/main/java/com/plivo/examples/Numbers.java @@ -0,0 +1,236 @@ +package com.plivo.examples; + +import java.io.IOException; +import java.util.Collections; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.base.ListResponse; +import com.plivo.api.models.number.Number; +import com.plivo.api.models.number.NumberCreateResponse; +import com.plivo.api.models.number.NumberUpdateResponse; +import com.plivo.api.models.number.PhoneNumber; +import com.plivo.api.models.number.PhoneNumberCreateResponse; + +public class Numbers { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + getNumberInfo(); + } + + // Example to get Number Info + // Client is set by Plivo.init helper method in main() + // Pass the number param to fetch the details + private static void getNumberInfo() { + try { + Number response = Number.getter("number").get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get Number Info with client + // Client is set explicitly as shown below + // Pass the number param to fetch the details + private static void getNumberInfoWithClient() { + try { + Number response = Number.getter("number").client(client).get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to update Number Info + // Client is set by Plivo.init helper method in main() + // Pass the number param to fetch the details + private static void updateNumberInfo() { + try { + NumberUpdateResponse response = Number.updater("number") + .alias("new_alias") + .appId("new_app_id") + .update(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to get Number Info with client + // Client is set explicitly as shown below + // Pass the number param to fetch the details + private static void updateNumberInfoWithClient() { + try { + NumberUpdateResponse response = Number.updater("number") + .alias("new_alias") + .appId("new_app_id") + .client(client) + .update(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all numbers + // Client is set by Plivo.init helper method in main() + private static void listAllNumbers() { + try { + ListResponse response = Number.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to listall numbers with client + // Client is set explicitly as shown below + private static void listAllNumbersWithClient() { + try { + ListResponse response = Number.lister() + .limit(5) + .offset(0) + .client(client) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a number + // Client is set by Plivo.init helper method in main() + // Pass the number param to delete + private static void deleteNumber() { + try { + Number.deleter("number").delete(); + System.out.println("Number deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a number with client + // Client is set explicitly as shown below + // Pass the number param to delete + private static void deleteNumberWithClient() { + try { + Number.deleter("number").client(client).delete(); + System.out.println("Number deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to create a number + // Client is set by Plivo.init helper method in main() + private static void createNumber() { + try { + + NumberCreateResponse response = Number.creator(Collections.singletonList("number"),"carrier_id", "region") + .create(); + System.out.println(response); + + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to create a number with client + // Client is set explicitly as shown below + private static void createNumberWithClient() { + try { + NumberCreateResponse response = Number.creator(Collections.singletonList("number"),"carrier_id", "region") + .client(client) + .create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to list all phoneNumbers available for purchase + // Client is set by Plivo.init helper method in main() + private static void listAllPhoneNumbers() { + try { + ListResponse response = PhoneNumber.lister("Countruy_code") + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example all phoneNumbers available for purchase with client + // Client is set explicitly as shown below + private static void listAllPhoneNumbersWithClient() { + try { + ListResponse response = PhoneNumber.lister("Countruy_code") + .limit(5) + .offset(0) + .client(client) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to buy a phoneNumber + // Client is set by Plivo.init helper method in main() + //Pass the number and app_id of application to be assigned to the phone number + + private static void buyAPhoneNumber() { + try { + PhoneNumberCreateResponse response = PhoneNumber.creator("number").appId("appId").create(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to buy a phoneNumber with client + // Client is set explicitly as shown below + //Pass the number and app_id of application to be assigned to the phone number + + private static void buyAPhoneNumberWithClient() { + try { + PhoneNumberCreateResponse response = PhoneNumber.creator("number").appId("appId") + .client(client) + .create(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + +} diff --git a/src/main/java/com/plivo/examples/PricingExample.java b/src/main/java/com/plivo/examples/PricingExample.java new file mode 100644 index 00000000..1cc71be0 --- /dev/null +++ b/src/main/java/com/plivo/examples/PricingExample.java @@ -0,0 +1,50 @@ +package com.plivo.examples; + +import java.io.IOException; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.pricing.Pricing; + +public class PricingExample { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + getPricingInfo(); + } + + // Example to get Pricing info + // Client is set by Plivo.init helper method in main() + // Pass the countryISO param to fetch pricing details + private static void getPricingInfo() { + try { + Pricing response = Pricing.getter("CountryISO") + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to get Pricing info with client + // Client is set explicitly as shown below + // Pass the countryISO param to fetch pricing details + private static void getPricingInfoWithClient() { + try { + Pricing response = Pricing.getter("CountryISO") + .client(client) + .get(); + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/plivo/examples/Recordings.java b/src/main/java/com/plivo/examples/Recordings.java new file mode 100644 index 00000000..fd4429c0 --- /dev/null +++ b/src/main/java/com/plivo/examples/Recordings.java @@ -0,0 +1,113 @@ +package com.plivo.examples; + +import java.io.IOException; + +import com.plivo.api.Plivo; +import com.plivo.api.PlivoClient; +import com.plivo.api.exceptions.PlivoRestException; +import com.plivo.api.models.base.ListResponse; +import com.plivo.api.models.identity.Identity; +import com.plivo.api.models.pricing.Pricing; +import com.plivo.api.models.recording.Recording; + +public class Recordings { + //Initialize the following authId and authToken with valid authId and authToken + + private static final String authId = "MANTXXXXXXXXXXXXXXXX"; + private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static PlivoClient client = new PlivoClient(authId, authToken); + + public static void main(String[] args) { + Plivo.init(authId, authToken); + getRecordingInfo(); + } + + // Example to get recording info + // Client is set by Plivo.init helper method in main() + // Pass the recordingID to get the details + private static void getRecordingInfo() { + try { + Recording response = Recording.getter("recordingId") + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to get recording info with client + // Client is set explicitly as shown below + // Pass the recordingID to get the details + private static void getRecordingInfoWithClient() { + try { + Recording response = Recording.getter("recordingId") + .client(client) + .get(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a recording + // Client is set by Plivo.init helper method in main() + // Pass the recordingID to delete + private static void deleteRecordingInfo() { + try { + Recording.deleter("recordingId").delete(); + System.out.println("Recording deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + + // Example to delete a recording with client + // Client is set explicitly as shown below + // Pass the recordingID to delete + private static void deleteRecordingInfoWithClient() { + try { + Recording.deleter("recordingId").client(client).delete(); + System.out.println("Recording deleted successfully"); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } + + // Example to list all recordings + // Client is set by Plivo.init helper method in main() + private static void listRecordings() { + try { + ListResponse response = Recording.lister() + .limit(5) + .offset(0) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + + } + + + // Example to list all recordings with client + // Client is set explicitly as shown below + private static void listRecordingsWithClient() { + try { + ListResponse response = Recording.lister() + .limit(5) + .offset(0) + .client(client) + .list(); + + System.out.println(response); + } catch (PlivoRestException | IOException e) { + e.printStackTrace(); + } + } +}