|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectuk.co.textmarketer.RestAPI.RestClient
public class RestClient
The RESTful API is an advanced version of the simple SMS API giving you greater flexibility with enhanced tools and services. As with all our developer solutions, we also offer support if you have any integration questions.
Copyright © 2012 Text Marketer Ltd
Client class to access Text Marketer RESTful API
| Field Summary | |
|---|---|
static boolean |
ENV_PRODUCTION
|
static boolean |
ENV_SANDBOX
|
| Constructor Summary | |
|---|---|
RestClient(java.lang.String username,
java.lang.String password,
boolean env)
Constructor for the RestClient class. |
|
| Method Summary | |
|---|---|
boolean |
addGroup(java.lang.String group)
Create a new group. |
int |
addNumbersToGroup(java.lang.String group,
java.lang.String numbers)
Add a number/numbers to a 'send group' (excluding 'merge' groups). |
java.util.Hashtable<java.lang.String,java.lang.String> |
createSubAccount(java.lang.String companyName,
java.lang.String notificationMobile,
java.lang.String notificationEmail,
java.lang.String username,
java.lang.String password,
java.lang.String promoCode,
boolean overrideRates)
Create a new account (requires additional permissions on your account, please contact Text Marketer to apply) |
java.util.Hashtable<java.lang.String,java.lang.String> |
deleteSMS(java.lang.String scheduled_id)
Delete a scheduled text message. |
int |
getCredits()
Get the number of credits currently available on your account. |
DeliveryReport[] |
getDeliveryReport(java.lang.String name)
Retrieve individual delivery report shows the current known status of all messages sent on a given day, or for a particular campaign. |
DeliveryReport[] |
getDeliveryReport(java.lang.String name,
java.util.Date start,
java.util.Date end)
Retrieve individual delivery report shows the current known status of all messages sent on a given day, or for a particular campaign. |
DeliveryReport[] |
getDeliveryReport(java.lang.String name,
java.lang.String custom)
Retrieve individual delivery report shows the current known status of all messages sent on a given day, or for a particular campaign. |
DeliveryReport[] |
getDeliveryReport(java.lang.String name,
java.lang.String custom,
java.util.Date start,
java.util.Date end)
Retrieve individual delivery report shows the current known status of all messages sent on a given day, or for a particular campaign. |
java.lang.String[] |
getDeliveryReports()
Retrieve a list of available delivery report names. |
java.lang.String[] |
getGroup(java.lang.String group)
Get all the numbers in the group, if there are any. |
java.util.Hashtable<java.lang.String,java.lang.String>[] |
getGroups()
Get a list of available 'send groups' - pre-defined groups containing a list of mobile numbers to send a message to. |
java.util.Hashtable<java.lang.String,java.lang.String> |
getKeyword(java.lang.String keyword)
Get the availability of a given reply keyword. |
int |
getLastErrorCode()
Return the last error code raised from the last RestClient call |
java.lang.String |
getLastErrorMessage()
Return the last error message raised from the last RestClient call |
java.util.Hashtable<java.lang.String,java.lang.String> |
getLastErrors()
Return the all the errors raised from the last RestClient call |
java.lang.String |
getXML()
Return the last xml string returned from the last RestClient call |
boolean |
isLoginValid()
Make a call to TM Rest API Gateway to test if the username and password are correct. |
java.util.Hashtable<java.lang.String,java.lang.String> |
sendSMS(java.lang.String message,
java.lang.String mobile_number,
java.lang.String originator,
int validity,
java.lang.String email,
java.lang.String custom,
java.util.Date schedule)
Send a text message to the specified recipient. |
java.util.Hashtable<java.lang.String,java.lang.String> |
transferCreditsToAccount(int quantity,
java.lang.String target)
Transfer credits from one account to another account, using the account number for the target. |
java.util.Hashtable<java.lang.String,java.lang.String> |
transferCreditsToUser(int quantity,
java.lang.String target_username,
java.lang.String target_password)
Transfer credits from one account to another account, using the username for the target. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final boolean ENV_SANDBOX
public static final boolean ENV_PRODUCTION
| Constructor Detail |
|---|
public RestClient(java.lang.String username,
java.lang.String password,
boolean env)
username - your API Gateway Usernamepassword - your API Gateway Passwordenv - possible values RestClient.ENV_SANDBOX or RestClient.ENV_PRODUCTION
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
| Method Detail |
|---|
public boolean isLoginValid()
throws RestClientException
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
if(tmClient.isLoginvalid())
System.out.println("Login is OK!");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public int getCredits()
throws RestClientException
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
credits = tmClient.getCredits();
System.out.println("Account have " + credits + " credits.");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.util.Hashtable<java.lang.String,java.lang.String> sendSMS(java.lang.String message,
java.lang.String mobile_number,
java.lang.String originator,
int validity,
java.lang.String email,
java.lang.String custom,
java.util.Date schedule)
throws RestClientException
message - The textual content of the message to be sent. Up to 612 characters from the GSM alphabet. The SMS characters we can support is documented at GSM character set. Please ensure that data is encoded in UTF-8.mobile_number - The mobile number of the intended recipient, in international format, e.g. 447777123123. Only one number is allowed. To send a message to multiple recipients, you must call the API for each number.originator - A string (up to 11 alpha-numeric characters) or the international mobile number (up to 16 digits) of the sender, to be displayed to the recipient, e.g. 447777123123 for a UK number.validity - An integer from 1 to 72, indicating the number of hours during which the message is valid for delivery. Messages which cannot be delivered within the specified time will fail.email - Optional. Available to txtUs Plus customers only. Specifies the email address for incoming responses. If you specify an email address, you must specify an originator that is a txtUs Plus number that is on your account, or you will get an error response.custom - Optional. An alpha-numeric string, 1-20 characters long, which will be used to 'tag' your outgoing message and will appear in delivery reports, thus facilitating filtering of reports.schedule - Optional. Date parameter to schedule the message to send at a given time.
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable result = tmClient.sendSMS("Hello SMS World!", "447777123123", "Hello World", 72, "", "");
System.out.println("Used " + result.get("credits_used") + " Credits, ID: " + result.get("message_id") + ", Scheduled ID: " + result.get("scheduled_id") + ", Status: " + result.get("status"));
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.util.Hashtable<java.lang.String,java.lang.String> transferCreditsToAccount(int quantity,
java.lang.String target)
throws RestClientException
quantity - The number of credits to transfer from the source account to the target account.target - The account number of the account to transfer the credits to
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable result = tmClient.transferCreditsToAccount(3, "902");
System.out.println("Transfered 3 Credits (have " + result.get("source_credits_after") + " now), to account 902, now with " + result.get("target_credits_after") + "Credits");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.util.Hashtable<java.lang.String,java.lang.String> transferCreditsToUser(int quantity,
java.lang.String target_username,
java.lang.String target_password)
throws RestClientException
quantity - The number of credits to transfer from the source account to the target account.target_username - The username of the account to transfer the credits to.target_password - The password of the account to transfer the credits to.
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable result = tmClient.transferCreditsToUser(3, "targetusername", "targetuserpass");
System.out.println("Transfered 3 Credits (have " + result.get("source_credits_after") + " now), to account targetusername, now with " + result.get("target_credits_after") + "Credits");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.util.Hashtable<java.lang.String,java.lang.String> getKeyword(java.lang.String keyword)
throws RestClientException
A reply keyword allows you receive incoming text messages to your account by providing people with a keyword, which they text to the short code 88802, e.g. text 'INFO' to 88802 to see this in action.
keyword - The keyword to check is availability
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable result = tmClient.getKeyword("gold");
System.out.println("The 'gold' keyword is available (" + result.get("available") + "), recycled ("+ result.get("recycle") + ")");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.util.Hashtable<java.lang.String,java.lang.String>[] getGroups()
throws RestClientException
Also lists 'stop groups' - numbers in these groups will never be sent messages.
Every account has at least one stop group, so that your recipients can always opt out of receiving messages from you. This is a legal requirement.
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable[] result = tmClient.getGroups();
for(Hashtable group: result) {
System.out.println("Group ID: " + group.get("id"));
System.out.println("Group numbers: " + group.get("numbers"));
System.out.println("Group name: " + group.get("name"));
System.out.println("Group IS STOP: " + group.get("is_stop"));
}
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.lang.String[] getGroup(java.lang.String group)
throws RestClientException
group - Group name or group ID to get the numbers of
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
String[] numbers = tmClient.getGroup("directors");
for(String number: numbers)
System.out.println("Number: " + number);
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public int addNumbersToGroup(java.lang.String group,
java.lang.String numbers)
throws RestClientException
group - name or group ID to add the numbers tonumbers - The MSISDN (mobile number) you wish to add, if you want to add more then one use a comma delimited list
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
int numAdded = tmClient.addNumbersToGroup("My Group", "447777000001,447777000002,44777700000");
System.out.println("Added " + numAdded + " to My Group");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public boolean addGroup(java.lang.String group)
throws RestClientException
group - the new Group name to be created
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
if(tmClient.addGroup("New Group"))
System.out.println("'New Group' added with success.");
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.lang.String[] getDeliveryReports()
throws RestClientException
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
String[] reports = tmClient.getDeliveryReports();
for(String report: reports)
System.out.println("Report name: " + report);
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public DeliveryReport[] getDeliveryReport(java.lang.String name)
throws RestClientException
Whereas the function getDeliveryReports() gets a list of available delivery report names, including delivery reports for campaigns.
name - Name of the delivery report to retrieve or 'all' to retrieve all campaign/API report data
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
DeliveryReport[] reports = tmClient.getDeliveryReport("all");
for(DeliveryReport report: reports) {
System.out.println(report);
for(Hashtable row: report.getRows()) {
System.out.println("\tMessage ID: " + row.get("message_id"));
System.out.println("\tLast Updated: " + row.get("last_updated"));
System.out.println("\tMobile Number: " + row.get("mobile_number"));
System.out.println("\tStatus: " + row.get("status"));
System.out.println("\tCustom Tag: " + row.get("custom"));
}
}
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
RestClientException
public DeliveryReport[] getDeliveryReport(java.lang.String name,
java.lang.String custom)
throws RestClientException
Whereas the function getDeliveryReports() gets a list of available delivery report names, including delivery reports for campaigns.
name - Name of the delivery report to retrieve or 'all' to retrieve all campaign/API report datacustom - Can specify a custom 'tag', which will restrict the search to those messages
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
DeliveryReport[] reports = tmClient.getDeliveryReport("all", "test");
for(DeliveryReport report: reports) {
System.out.println(report);
for(Hashtable row: report.getRows()) {
System.out.println("\tMessage ID: " + row.get("message_id"));
System.out.println("\tLast Updated: " + row.get("last_updated"));
System.out.println("\tMobile Number: " + row.get("mobile_number"));
System.out.println("\tStatus: " + row.get("status"));
System.out.println("\tCustom Tag: " + row.get("custom"));
}
}
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
RestClientException
public DeliveryReport[] getDeliveryReport(java.lang.String name,
java.util.Date start,
java.util.Date end)
throws RestClientException
Whereas the function getDeliveryReports() gets a list of available delivery report names, including delivery reports for campaigns.
name - Name of the delivery report to retrieve or 'all' to retrieve all campaign/API report datastart - Get delivery report from start Dateend - Get delivery report to end Date
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
// Get all reports from Year 2012
Calendar cal = Calendar.getInstance();
cal.set(2012, 1, 1);
DeliveryReport[] reports = tmClient.getDeliveryReport("all", cal.getTime(), new Date());
for(DeliveryReport report: reports) {
System.out.println(report);
for(Hashtable row: report.getRows()) {
System.out.println("\tMessage ID: " + row.get("message_id"));
System.out.println("\tLast Updated: " + row.get("last_updated"));
System.out.println("\tMobile Number: " + row.get("mobile_number"));
System.out.println("\tStatus: " + row.get("status"));
System.out.println("\tCustom Tag: " + row.get("custom"));
}
}
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
RestClientException
public DeliveryReport[] getDeliveryReport(java.lang.String name,
java.lang.String custom,
java.util.Date start,
java.util.Date end)
throws RestClientException
Whereas the function getDeliveryReports() gets a list of available delivery report names, including delivery reports for campaigns.
name - Name of the delivery report to retrieve or 'all' to retrieve all campaign/API report datacustom - Can specify a custom 'tag', which will restrict the search to those messagesstart - Get delivery report from start Dateend - Get delivery report to end Date
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
// Get all reports from Year 2012 with the custom tag 'test'
Calendar cal = Calendar.getInstance();
cal.set(2012, 1, 1);
DeliveryReport[] reports = tmClient.getDeliveryReport("all", "test", cal.getTime(), new Date());
for(DeliveryReport report: reports) {
System.out.println(report);
for(Hashtable row: report.getRows()) {
System.out.println("\tMessage ID: " + row.get("message_id"));
System.out.println("\tLast Updated: " + row.get("last_updated"));
System.out.println("\tMobile Number: " + row.get("mobile_number"));
System.out.println("\tStatus: " + row.get("status"));
System.out.println("\tCustom Tag: " + row.get("custom"));
}
}
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
RestClientException
public java.util.Hashtable<java.lang.String,java.lang.String> createSubAccount(java.lang.String companyName,
java.lang.String notificationMobile,
java.lang.String notificationEmail,
java.lang.String username,
java.lang.String password,
java.lang.String promoCode,
boolean overrideRates)
throws RestClientException
companyName - The company name for the new account ownernotificationMobile - (Optional*) the mobile number of the account (*required if notificationEmail is not set)notificationEmail - (Optional*) the email address of the account (*required if notificationMobile is not set)username - (Optional) the username you wish to set on the new account - the API username will be the samepassword - (Optional) the password you wish to set on the new account - the API password will be the samepromoCode - (Optional) a promotional code entitling the account to extra creditsoverrideRates - If set to true, use the credits rates set on your main account (the account used to access the API), rather than the Text Marketer defaults.
RestClientException - Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable result = tmClient.createSubAccount("my subaccount", "44123456789", null, "subusername", "subpassword", null, false);
System.out.println("Account ID: " + result.get("account_id"));
System.out.println("Company Name: " + result.get("company_name"));
System.out.println("Create Date: " + result.get("create_date"));
System.out.println("Credits: " + result.get("credits"));
System.out.println("Notification Email: " + result.get("notification_email"));
System.out.println("Notification Mobile: " + result.get("notification_mobile"));
System.out.println("Username: " + result.get("username"));
System.out.println("Password: " + result.get("password"));
System.out.println("API Username: " + result.get("api_username"));
System.out.println("API Password: " + result.get("api_password"));
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public java.lang.String getXML()
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
tmClient.getGroup("directors");
xml = tmClient.getXML();
System.out.println(xml);
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
public int getLastErrorCode()
public java.lang.String getLastErrorMessage()
public java.util.Hashtable<java.lang.String,java.lang.String> getLastErrors()
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
credits = tmClient.getCredits();
System.out.println("Account have " + credits + " credits.");
} catch(RestClientException e) {
Hashtable errors = tmClient.getLastErrors();
for(Map.Entry error: errors.entrySet())
System.out.println("Error code " + error.getKey() + ": " + error.getValue());
}
public java.util.Hashtable<java.lang.String,java.lang.String> deleteSMS(java.lang.String scheduled_id)
throws RestClientException
scheduled_id - The id of the scheduled text message, as returned by the sendSMS method.
RestClientException - on error
Example:
RestClient tmClient = new RestClient("myuser", "mypass", RestClient.ENV_SANDBOX);
try {
Hashtable result = tmClient.deleteSMS();
System.out.println("Scheduled ID: " + result.get("scheduled_id") + ", Status: " + result.get("status"));
} catch(RestClientException e) {
System.out.println(e.getMessage());
}
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||