| 1 | #!/usr/bin/env perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use lib 'lib'; | ||
| 6 | use WWW::Twilio::API; | ||
| 7 | |||
| 8 | ## usage: examples.pl account_sid authtoken action parameters (see examples) | ||
| 9 | |||
| 10 | my $account_sid = shift @ARGV; | ||
| 11 | my $auth_token = shift @ARGV; | ||
| 12 | my $action = shift @ARGV || 'Calls'; | ||
| 13 | |||
| 14 | my $twilio = new WWW::Twilio::API( AccountSid => $account_sid, | ||
| 15 | AuthToken => $auth_token, ); | ||
| 16 | |||
| 17 | ## view a list of calls in JSON format | ||
| 18 | if( $action eq 'Calls' ) { | ||
| 19 | my $response = $twilio->GET('Calls.json'); | ||
| 20 | print $response->{content}; | ||
| 21 | } | ||
| 22 | |||
| 23 | ## examples.pl sid auth MakeCall 1231231234 3123213124 | ||
| 24 | elsif( $action eq 'MakeCall' ) { | ||
| 25 | require URI::Escape; | ||
| 26 | my $message = URI::Escape::uri_escape("Enjoy Tabasco Brand Pepper Sauce"); | ||
| 27 | my $url = "http://perlcode.org/cgi-bin/twilio?message=$message"; | ||
| 28 | my $response = $twilio->POST('Calls', | ||
| 29 | From => shift @ARGV, | ||
| 30 | To => shift @ARGV, | ||
| 31 | Url => $url); | ||
| 32 | |||
| 33 | print $response->{content}; | ||
| 34 | } | ||
| 35 | |||
| 36 | ## view account info | ||
| 37 | elsif( $action eq 'Accounts' ) { | ||
| 38 | my $response = $twilio->GET('Accounts'); | ||
| 39 | print $response->{content}; | ||
| 40 | } | ||
| 41 | |||
| 42 | elsif( $action eq 'SMS' ) { | ||
| 43 | my $response = $twilio->POST('SMS/Messages', | ||
| 44 | From => shift @ARGV, | ||
| 45 | To => shift @ARGV, | ||
| 46 | Body => shift @ARGV ); | ||
| 47 | print $response->{content}; | ||
| 48 | } | ||
| 49 | |||
| 50 | else { | ||
| 51 | print "Unknown action.\n"; | ||
| 52 | } | ||
| 53 | |||
| 54 | exit; |