com.techventus.server.voice
Class Voice

java.lang.Object
  extended by com.techventus.server.voice.Voice

public class Voice
extends java.lang.Object

The Class Voice. This class is the basis of the entire API and contains all the components necessary to connect and authenticate with Google Voice, place calls and SMS, and pull in the raw data from the account.


Field Summary
(package private) static java.lang.String ACCOUNT_TYPE
          Type of account to request authorization for.
(package private)  java.lang.String general
           
(package private) static java.lang.String generalSettingsURLString
           
(package private) static java.lang.String generalURLString
           
(package private) static java.lang.String groupsInfoURLString
           
(package private) static java.lang.String groupsSettingsURLString
           
(package private) static java.lang.String inboxURLString
           
(package private) static java.lang.String loginURLString
           
(package private) static java.lang.String missedURLString
           
(package private) static java.lang.String phoneEnableURLString
           
(package private)  java.lang.String phonesInfo
           
(package private) static java.lang.String phonesInfoURLString
           
(package private) static java.lang.String placedURLString
           
 boolean PRINT_TO_CONSOLE
           
(package private) static java.lang.String receivedURLString
           
(package private) static java.lang.String recentAllURLString
           
(package private) static java.lang.String recordedURLString
           
(package private)  java.lang.String rnrSEE
           
(package private) static java.lang.String SERVICE
          Name of the Google service you're requesting authorization for.
(package private) static java.lang.String smsURLString
           
(package private)  java.lang.String source
          Short string identifying your application, for logging purposes.
(package private) static java.lang.String spamURLString
           
(package private) static java.lang.String starredURLString
           
(package private) static java.lang.String trashURLString
           
(package private) static java.lang.String USER_AGENT
           
(package private) static java.lang.String voicemailInfoURLString
           
(package private) static java.lang.String voicemailURLString
           
 
Constructor Summary
Voice(java.lang.String user, java.lang.String pass)
          Instantiates a new Voice Object.
Voice(java.lang.String user, java.lang.String pass, java.lang.String source)
          A constructor which which allows a custom source.
Voice(java.lang.String user, java.lang.String pass, java.lang.String source, boolean printDebugIntoToSystemOut)
          Instantiates a new voice.
Voice(java.lang.String user, java.lang.String pass, java.lang.String source, java.lang.String rnrSee)
          Deprecated. 
 
Method Summary
 java.lang.String call(java.lang.String originNumber, java.lang.String destinationNumber, java.lang.String phoneType)
          Place a call.
 java.lang.String cancelCall(java.lang.String originNumber, java.lang.String destinationNumber, java.lang.String phoneType)
          Cancel a call that was just placed.
(package private)  java.lang.String get(java.lang.String urlString)
          HTML GET request for a given URL String.
(package private)  java.lang.String get(java.lang.String urlString, int page)
          HTML GET request for a given URL String and a given page number
 java.lang.String getGeneral()
          Fetches the page Source Code for the Voice homepage.
 java.lang.String getGeneralPage(int page)
           
 java.util.List<java.lang.String> getGroupSettingsList(boolean forceUpdate)
          Returns the Group list - Lazy
 java.lang.String getInbox()
          Fetches and returns the raw page source code for the Inbox.
 java.lang.String getInboxPage(int page)
           
 java.lang.String getMissed()
          Gets the missed calls source code.
 java.lang.String getMissedPage(int page)
           
 java.lang.String getONLYFORTEST(java.lang.String urlString)
           
 java.util.List<PhoneOld> getPhoneList(boolean forceUpdate)
          Returns the phone list - Lazy TODO move this function in the Settings class
 java.lang.String getPlaced()
          Gets the raw source code for the placed calls page.
 java.lang.String getPlacedPage(int page)
           
 java.lang.String getRawPhonesInfo()
           
 java.lang.String getReceived()
          Gets the received calls source code.
 java.lang.String getReceivedPage(int page)
           
 java.lang.String getRecent()
          Gets the raw page source code for the recent items.
 java.lang.String getRecentPage(int page)
           
 java.lang.String getRecorded()
          Gets the page source for the recorded calls.
 java.lang.String getRecordedPage(int page)
           
 AllSettings getSettings(boolean forceUpdate)
          returns all users settings - lazy
 java.lang.String getSMS()
          Gets the SMS page raw source code.
 java.lang.String getSMSPage(int page)
           
 java.lang.String getSpam()
          Gets the page source for the spam.
 java.lang.String getSpamPage(int page)
           
 java.lang.String getStarred()
          Gets the raw page source code for the starred items.
 java.lang.String getStarredPage(int page)
           
 java.util.List<Greeting> getVoicemailList(boolean forceUpdate)
          Returns the Greeting list - Lazy
 boolean isLoggedIn()
          Fires a Get request for Recent Items.
 void login()
          Login Method to refresh authentication with Google Voice.
 java.lang.String phoneDisable(int ID)
          Disable one of the the phones attached to the account from ringing.
 java.lang.String phoneEnable(int ID)
          Enables one of the the phones attached to the account from ringing.
 void phonesDisable(int[] IDs)
          Disables multiple phones in one post TODO Test this with multiple phones in an account Make faster - spawn threads Best would be to be able to construct a url which can switch multiple phones at a time
 void phonesEnable(int[] IDs)
          Enables multiple phones in one post TODO Test this with multiple phones in an account Best would be to be able to construct a url which can switch multiple phones at a time
 java.lang.String sendSMS(java.lang.String destinationNumber, java.lang.String txt)
          Send an SMS
 java.lang.String setCallPresentation(boolean announceCaller)
          Enables/disables the call Announcement setting (general for all phones)
 java.lang.String setDoNotDisturb(boolean dndEnabled)
          Activated or deactivated the Do Not disturb function.
Enable this to send to voicemail all calls made to your Google number.
 java.lang.String setNewGroupSettings(Group group)
          Applies the settings for this group
 java.lang.String setVoicemailGreetingId(java.lang.String greetingToSet)
          This is the general voicemail greeting callers hear
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRINT_TO_CONSOLE

public boolean PRINT_TO_CONSOLE

general

java.lang.String general

phonesInfo

java.lang.String phonesInfo

rnrSEE

java.lang.String rnrSEE

source

java.lang.String source
Short string identifying your application, for logging purposes. This string should take the form: "companyName-applicationName-versionID". See: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Request


USER_AGENT

static final java.lang.String USER_AGENT
See Also:
Constant Field Values

ACCOUNT_TYPE

static final java.lang.String ACCOUNT_TYPE
Type of account to request authorization for. Possible values are:

-GOOGLE (get authorization for a Google account only)
-HOSTED (get authorization for a hosted account only)
-HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account)

Use HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized.

See Also:
Constant Field Values

SERVICE

static final java.lang.String SERVICE
Name of the Google service you're requesting authorization for. Each service using the Authorization service is assigned a name value; for example, the name associated with Google Calendar is 'cl'. This parameter is required when accessing services based on Google Data APIs. For specific service names, refer to the service documentation.

See Also:
Constant Field Values

generalURLString

static final java.lang.String generalURLString
See Also:
Constant Field Values

loginURLString

static final java.lang.String loginURLString
See Also:
Constant Field Values

inboxURLString

static final java.lang.String inboxURLString
See Also:
Constant Field Values

starredURLString

static final java.lang.String starredURLString
See Also:
Constant Field Values

recentAllURLString

static final java.lang.String recentAllURLString
See Also:
Constant Field Values

spamURLString

static final java.lang.String spamURLString
See Also:
Constant Field Values

trashURLString

static final java.lang.String trashURLString
See Also:
Constant Field Values

voicemailURLString

static final java.lang.String voicemailURLString
See Also:
Constant Field Values

smsURLString

static final java.lang.String smsURLString
See Also:
Constant Field Values

recordedURLString

static final java.lang.String recordedURLString
See Also:
Constant Field Values

placedURLString

static final java.lang.String placedURLString
See Also:
Constant Field Values

receivedURLString

static final java.lang.String receivedURLString
See Also:
Constant Field Values

missedURLString

static final java.lang.String missedURLString
See Also:
Constant Field Values

phoneEnableURLString

static final java.lang.String phoneEnableURLString
See Also:
Constant Field Values

generalSettingsURLString

static final java.lang.String generalSettingsURLString
See Also:
Constant Field Values

phonesInfoURLString

static final java.lang.String phonesInfoURLString
See Also:
Constant Field Values

groupsInfoURLString

static final java.lang.String groupsInfoURLString
See Also:
Constant Field Values

voicemailInfoURLString

static final java.lang.String voicemailInfoURLString
See Also:
Constant Field Values

groupsSettingsURLString

static final java.lang.String groupsSettingsURLString
See Also:
Constant Field Values
Constructor Detail

Voice

@Deprecated
public Voice(java.lang.String user,
                        java.lang.String pass,
                        java.lang.String source,
                        java.lang.String rnrSee)
      throws java.io.IOException
Deprecated. 

Instantiates a new voice. This constructor is deprecated. Try Voice(String user, String pass) which automatically determines rnrSee and assigns a source.

Parameters:
user - the user
pass - the pass
source - the source
rnrSee - the rnr see
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

Voice

public Voice(java.lang.String user,
             java.lang.String pass,
             java.lang.String source)
      throws java.io.IOException
A constructor which which allows a custom source.

Parameters:
user - the username in the format of user@gmail.com or user@googlemail.com
pass - the password
source - Short string identifying your application, for logging purposes. This string should take the form: "companyName-applicationName-versionID". See: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Request
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

Voice

public Voice(java.lang.String user,
             java.lang.String pass)
      throws java.io.IOException
Instantiates a new Voice Object. This is generally the simplest and preferred constructor. This Constructor enables verbose output.

Parameters:
user - the username in the format of user@gmail.com or user@googlemail.com
pass - the pass
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

Voice

public Voice(java.lang.String user,
             java.lang.String pass,
             java.lang.String source,
             boolean printDebugIntoToSystemOut)
      throws java.io.IOException
Instantiates a new voice. Custom Source Variable allowed, and printDebugIntoSystemOut which allows for Verbose output.

Parameters:
user - the username in the format of user@gmail.com or user@googlemail.com
pass - the password
source - the arbitrary source identifier. Can be anything.
printDebugIntoToSystemOut - the print debug into to system out
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
Method Detail

getPhoneList

public java.util.List<PhoneOld> getPhoneList(boolean forceUpdate)
                                      throws java.io.IOException
Returns the phone list - Lazy TODO move this function in the Settings class

Parameters:
refresh - - set to true to force a List update from the server
Returns:
List of PhoneOld objects
Throws:
java.io.IOException

getVoicemailList

public java.util.List<Greeting> getVoicemailList(boolean forceUpdate)
                                          throws java.io.IOException,
                                                 gvjava.org.json.JSONException
Returns the Greeting list - Lazy

Parameters:
refresh - - set to true to force a List update from the server
Returns:
List of Greeting objects
Throws:
java.io.IOException
gvjava.org.json.JSONException

getGroupSettingsList

public java.util.List<java.lang.String> getGroupSettingsList(boolean forceUpdate)
                                                      throws java.io.IOException
Returns the Group list - Lazy

Parameters:
refresh - - set to true to force a List update from the server
Returns:
List of Greeting objects
Throws:
java.io.IOException

getSettings

public AllSettings getSettings(boolean forceUpdate)
                        throws java.io.IOException,
                               gvjava.org.json.JSONException
returns all users settings - lazy

Parameters:
forceUpdate -
Returns:
Throws:
java.io.IOException
gvjava.org.json.JSONException

getInbox

public java.lang.String getInbox()
                          throws java.io.IOException
Fetches and returns the raw page source code for the Inbox.

Returns:
the inbox
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getInboxPage

public java.lang.String getInboxPage(int page)
                              throws java.io.IOException
Throws:
java.io.IOException

getGeneral

public java.lang.String getGeneral()
                            throws java.io.IOException
Fetches the page Source Code for the Voice homepage. This file contains most of the useful information for the Google Voice Account such as attached PhoneOld info and Contacts.

Returns:
the general
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getGeneralPage

public java.lang.String getGeneralPage(int page)
                                throws java.io.IOException
Throws:
java.io.IOException

getStarred

public java.lang.String getStarred()
                            throws java.io.IOException
Gets the raw page source code for the starred items.

Returns:
the starred item page source
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getStarredPage

public java.lang.String getStarredPage(int page)
                                throws java.io.IOException
Throws:
java.io.IOException

getRecent

public java.lang.String getRecent()
                           throws java.io.IOException
Gets the raw page source code for the recent items.

Returns:
the recent raw source code
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getRecentPage

public java.lang.String getRecentPage(int page)
                               throws java.io.IOException
Throws:
java.io.IOException

getSpam

public java.lang.String getSpam()
                         throws java.io.IOException
Gets the page source for the spam.

Returns:
the spam
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getSpamPage

public java.lang.String getSpamPage(int page)
                             throws java.io.IOException
Throws:
java.io.IOException

getRecorded

public java.lang.String getRecorded()
                             throws java.io.IOException
Gets the page source for the recorded calls.

Returns:
the recorded
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getRecordedPage

public java.lang.String getRecordedPage(int page)
                                 throws java.io.IOException
Throws:
java.io.IOException

getPlaced

public java.lang.String getPlaced()
                           throws java.io.IOException
Gets the raw source code for the placed calls page.

Returns:
the placed calls source code
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getPlacedPage

public java.lang.String getPlacedPage(int page)
                               throws java.io.IOException
Throws:
java.io.IOException

getReceived

public java.lang.String getReceived()
                             throws java.io.IOException
Gets the received calls source code.

Returns:
the received
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getReceivedPage

public java.lang.String getReceivedPage(int page)
                                 throws java.io.IOException
Throws:
java.io.IOException

getMissed

public java.lang.String getMissed()
                           throws java.io.IOException
Gets the missed calls source code.

Returns:
the missed
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getMissedPage

public java.lang.String getMissedPage(int page)
                               throws java.io.IOException
Throws:
java.io.IOException

getSMS

public java.lang.String getSMS()
                        throws java.io.IOException
Gets the SMS page raw source code.

Returns:
the sMS
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getSMSPage

public java.lang.String getSMSPage(int page)
                            throws java.io.IOException
Throws:
java.io.IOException

getRawPhonesInfo

public java.lang.String getRawPhonesInfo()
                                  throws java.io.IOException
Throws:
java.io.IOException

call

public java.lang.String call(java.lang.String originNumber,
                             java.lang.String destinationNumber,
                             java.lang.String phoneType)
                      throws java.io.IOException
Place a call.

Parameters:
originNumber - the origin number
destinationNumber - the destination number
phoneType - the phone type, this is a number such as 1,2,7 formatted as a String
Returns:
the raw response string received from Google Voice.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

cancelCall

public java.lang.String cancelCall(java.lang.String originNumber,
                                   java.lang.String destinationNumber,
                                   java.lang.String phoneType)
                            throws java.io.IOException
Cancel a call that was just placed.

Parameters:
originNumber - the origin number
destinationNumber - the destination number
phoneType - the phone type
Returns:
the string
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

phonesEnable

public void phonesEnable(int[] IDs)
                  throws java.io.IOException
Enables multiple phones in one post TODO Test this with multiple phones in an account Best would be to be able to construct a url which can switch multiple phones at a time

Parameters:
IDs - Array of Phones to enable
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

phoneEnable

public java.lang.String phoneEnable(int ID)
                             throws java.io.IOException
Enables one of the the phones attached to the account from ringing. Requires the internal ID for that phone, as an integer, usually 1,2,3, etc.

Parameters:
ID - the iD
Returns:
the raw response of the enable action.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

phonesDisable

public void phonesDisable(int[] IDs)
                   throws java.io.IOException
Disables multiple phones in one post TODO Test this with multiple phones in an account Make faster - spawn threads Best would be to be able to construct a url which can switch multiple phones at a time

Parameters:
IDs - Array of Phones to disable
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

phoneDisable

public java.lang.String phoneDisable(int ID)
                              throws java.io.IOException
Disable one of the the phones attached to the account from ringing. Requires the internal ID for that phone, as an integer, usually 1,2,3, etc.

Parameters:
ID - the iD
Returns:
the raw response of the disable action.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

setCallPresentation

public java.lang.String setCallPresentation(boolean announceCaller)
                                     throws java.io.IOException
Enables/disables the call Announcement setting (general for all phones)

Parameters:
announceCaller -
true Announces caller's name and gives answering options
false Directly connects calls when phones are answered
Returns:
the raw response of the disable action.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

setVoicemailGreetingId

public java.lang.String setVoicemailGreetingId(java.lang.String greetingToSet)
                                        throws java.io.IOException
This is the general voicemail greeting callers hear

Parameters:
greetingToSet -
number of the greeting to choose
Returns:
the raw response of the disable action.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

setDoNotDisturb

public java.lang.String setDoNotDisturb(boolean dndEnabled)
                                 throws java.io.IOException
Activated or deactivated the Do Not disturb function.
Enable this to send to voicemail all calls made to your Google number.

Parameters:
dndEnabled - true to enable dnd, false to disable it
Returns:
Throws:
java.io.IOException

setNewGroupSettings

public java.lang.String setNewGroupSettings(Group group)
                                     throws java.io.IOException
Applies the settings for this group

Parameters:
group -
Returns:
Throws:
java.io.IOException

sendSMS

public java.lang.String sendSMS(java.lang.String destinationNumber,
                                java.lang.String txt)
                         throws java.io.IOException
Send an SMS

Parameters:
destinationNumber - the destination number
txt - the Text of the message. Messages longer than the allowed character length will be split into multiple messages.
Returns:
the string
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getONLYFORTEST

public java.lang.String getONLYFORTEST(java.lang.String urlString)
                                throws java.io.IOException
Throws:
java.io.IOException

get

java.lang.String get(java.lang.String urlString)
               throws java.io.IOException
HTML GET request for a given URL String.

Parameters:
urlString - the url string
Returns:
the string
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

get

java.lang.String get(java.lang.String urlString,
                     int page)
               throws java.io.IOException
HTML GET request for a given URL String and a given page number

Parameters:
urlString - the url string
page - number must be a natural number
Returns:
the string
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

login

public void login()
           throws java.io.IOException
Login Method to refresh authentication with Google Voice.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

isLoggedIn

public boolean isLoggedIn()
Fires a Get request for Recent Items. If the Response requests login authentication or if an exception is thrown, a false is returned, otherwise if arbitrary text is contained for a logged in account, a true is returned. TODO Examine methodology.

Returns:
true, if is logged in