Skip to content

Commit

Permalink
Mavenization of the Java Twilio Client
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristerF committed Jan 24, 2012
1 parent b913afa commit 1723606
Show file tree
Hide file tree
Showing 76 changed files with 258 additions and 349 deletions.
22 changes: 18 additions & 4 deletions .gitignore
@@ -1,6 +1,20 @@
bin
# Make sure to ignore Eclipse files
.classpath
.project
build
ivy
dist
.settings

# Macisms
.DS_Store
# Where maven compiles by default
target

# Java Files that should be ignored
*.class

# Package Files
*.jar
*.war
*.ear

# Backup files
*.bak
20 changes: 20 additions & 0 deletions CHANGES
@@ -0,0 +1,20 @@
twilio-java Changelog
=======================

Here you can see the full list of changes between each twilio-java release.

Version 3.3.7
-------------

Released on TBD

- Mavenized the build
- Removed unnecessary jars from dependencies

Version 3.3.6
-------------

Released on January 18, 2011

- Fixed a bug where the short one second HTTP Connection timeout led to connection exceptions - increased to 10 seconds
- Fixed constructors for resource instances must not accept null Sid
193 changes: 98 additions & 95 deletions README.md
@@ -1,109 +1,112 @@
# Installing

The pre-built jars are available at:
As of version 3.3.7 TwilioJava is now using Maven.

http://twilio.github.com/twilio-java/jars/TwilioJava-3.3.6-with-dependencies.jar
http://twilio.github.com/twilio-java/jars/TwilioJava-3.3.6.jar - use this if
you have issues with conflicting jars in your project. You'll need to include
versions of the dependencies yourself. See the ivy.xml for the list of
libraries.
At present the jars are not available from a public [maven](http://maven.apache.org/download.html) repository.

You can view the javadocs for this project at:
http://twilio.github.com/twilio-java
How to install:

# Building From Source
$ git clone git@github.com:twilio/twilio-java.
$ cd twilio-java
$ mvn install # Requires maven, download from http://maven.apache.org/download.html

Important: you must have ant installed to build the project from source.
This will also build the javadoc in `twilio-java/target/apidocs`. You can open the
index.html located there to view it locally.

If you would like to build twilio-java from source just clone the project
(located at https://github.com/twilio/twilio-java) and run:
Use the following dependency in your project:

cd twilio-java
ant
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio-client</artifactId>
<version>3.3.7</version>
<scope>compile</scope>
</dependency>

This will build two jars in `twilio-java/dist/lib/` The first is a jar of only
code related to the twilio-java project useful when integrating into a larger
project. The second is a jar bundling twilio-java with all of its dependencies
into a standalone jar. (see ivy.xml for the full list of dependencies)
The pre-built jars are available at:

This will also build the javadoc in `twilio-java/dist/api`. You can open the
index.html located there to view it locally.
* [TwilioJava-3.3.7-with-dependencies.jar](http://twilio.github.com/twilio-java/jars/TwilioJava-3.3.7-with-dependencies.jar)
* [TwilioJava-3.3.7.jar](http://twilio.github.com/twilio-java/jars/TwilioJava-3.3.7.jar) - use this if
you have issues with conflicting jars in your project. You'll need to include
versions of the dependencies yourself. See the pom.xml for the list of
libraries.

You can view the javadocs for this project at:
[http://twilio.github.com/twilio-java](http://twilio.github.com/twilio-java)

# Examples

Here are some examples (also found in TwilioRestExamples.java)

``` java
// Create a rest client
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

// Get the main account (The one we used to authenticate the client
Account mainAccount = client.getAccount();

// Get all accounts including sub accounts
AccountList accountList = client.getAccounts();

// All lists implement an iterable interface, you can use the foreach
// syntax on them
for (Account a : accountList) {
System.out.println(a.getFriendlyName());
}

// You can also iterate manually...
Iterator<Account> itr = accountList.iterator();
while (itr.hasNext()) {
Account a = itr.next();
System.out.println(a.getFriendlyName());
}

// You can also get just the first page of data
accountList = client.getAccounts();
List<Account> accounts = accountList.getPageData();

// Make a call
CallFactory callFactory = mainAccount.getCallFactory();
Map<String, String> callParams = new HashMap<String, String>();
callParams.put("To", "5105551212"); // Replace with a valid phone number
callParams.put("From", "(510) 555-1212"); // Replace with a valid phone number in your account
callParams.put("Url", "http://demo.twilio.com/welcome/voice/");
Call call = callFactory.create(callParams);
System.out.println(call.getSid());

// Send an sms
SmsFactory smsFactory = mainAccount.getSmsFactory();
Map<String, String> smsParams = new HashMap<String, String>();
smsParams.put("To", "5105551212"); // Replace with a valid phone number
smsParams.put("From", "(510) 555-1212"); // Replace with a valid phone number in your account
smsParams.put("Body", "This is a test message!");
smsFactory.create(smsParams);

// Search for available phone numbers & then buy a random phone number
AvailablePhoneNumberList phoneNumbers = mainAccount.getAvailablePhoneNumbers();
List<AvailablePhoneNumber> list = phoneNumbers.getPageData();

// Buy the first number returned
Map<String, String> params = new HashMap<String, String>();
params.put("PhoneNumber", list.get(0).getPhoneNumber());
params.put("VoiceUrl", "http://demo.twilio.com/welcome/voice/");
mainAccount.getIncomingPhoneNumberFactory().create(params);

// View a conference using its sid
Conference c = mainAccount.getConference("CA12345...");
ParticipantList participants = c.getParticipants();

for (Participant p : participants) {
// Randomly mute or kick each participant
if (Math.random() > 0.5) {
p.mute();
} else {
p.kick();
}
}

// Make a raw HTTP request to the api... note, this is deprecated style
TwilioRestResponse resp = client.request("/2010-04-01/Accounts", "GET", null);
if (!resp.isError()) {
System.out.println(resp.getResponseText());
}
```
Here are some examples (also found in [TwilioRestExamples.java](https://github.com/twilio/twilio-java/blob/master/src/java/com/twilio/sdk/examples/RestExamples.java) )

```
// Create a rest client
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Get the main account (The one we used to authenticate the client)
Account mainAccount = client.getAccount();
// Get all accounts including sub accounts
AccountList accountList = client.getAccounts();
// All lists implement an iterable interface, you can use the foreach
// syntax on them
for (Account a : accountList) {
System.out.println(a.getFriendlyName());
}
// You can also iterate manually...
Iterator<Account> itr = accountList.iterator();
while (itr.hasNext()) {
Account a = itr.next();
System.out.println(a.getFriendlyName());
}
// You can also get just the first page of data
accountList = client.getAccounts();
List<Account> accounts = accountList.getPageData();
// Make a call
CallFactory callFactory = mainAccount.getCallFactory();
Map<String, String> callParams = new HashMap<String, String>();
callParams.put("To", "5105551212"); // Replace with a valid phone number
callParams.put("From", "(510) 555-1212"); // Replace with a valid phone number in your account
callParams.put("Url", "http://demo.twilio.com/welcome/voice/");
Call call = callFactory.create(callParams);
System.out.println(call.getSid());
// Send an sms
SmsFactory smsFactory = mainAccount.getSmsFactory();
Map<String, String> smsParams = new HashMap<String, String>();
smsParams.put("To", "5105551212"); // Replace with a valid phone number
smsParams.put("From", "(510) 555-1212"); // Replace with a valid phone number in your account
smsParams.put("Body", "This is a test message!");
smsFactory.create(smsParams);
// Search for available phone numbers & then buy a random phone number
AvailablePhoneNumberList phoneNumbers = mainAccount.getAvailablePhoneNumbers();
List<AvailablePhoneNumber> list = phoneNumbers.getPageData();
// Buy the first number returned
Map<String, String> params = new HashMap<String, String>();
params.put("PhoneNumber", list.get(0).getPhoneNumber());
params.put("VoiceUrl", "http://demo.twilio.com/welcome/voice/");
mainAccount.getIncomingPhoneNumberFactory().create(params);
// View a conference using its sid
Conference c = mainAccount.getConference("CA12345...");
ParticipantList participants = c.getParticipants();
for (Participant p : participants) {
// Randomly mute or kick each participant
if (Math.random() > 0.5) {
p.mute();
} else {
p.kick();
}
}
// Make a raw HTTP request to the api... note, this is deprecated style
TwilioRestResponse resp = client.request("/2010-04-01/Accounts", "GET", null);
if (!resp.isError()) {
System.out.println(resp.getResponseText());
}
```
2 changes: 0 additions & 2 deletions build.properties

This file was deleted.

0 comments on commit 1723606

Please sign in to comment.