jbowshaw has asked for the wisdom of the Perl Monks concerning the following question:
use WWW::Curl::Easy; use Data::Dumper; use XML::DOM; { package accounts; my $ss_username; my $ss_account_id; my $ss_email_address; my $ss_password; my $self = { ss_username => $ss_username, ss_password => $ss_password, ss_account_id => $ss_account_id, ss_email_address => $ss_email_address }; # Anonymous hash reference holds instance attrib +utes sub new { my($class, $ss_username,$ss_password) = @_; # Class name is i +n the first parameter bless($self, $class); # Say: $self is a $class my $ret_list = getAccountInfo(); print $ret_list."\n"; return $self; } sub getAccountInfo { my @authHeader = ('Accept: application/xml', 'Content-Type: application/xml'); # Setting the options my $curl = new WWW::Curl::Easy; $curl->setopt(CURLOPT_HEADER,0); $curl->setopt(CURLOPT_HTTPHEADER, \@authHeader); $curl->setopt(CURLOPT_SSL_VERIFYPEER, 0); $curl->setopt(CURLOPT_USERPWD, 'myusername:mypassword'); $curl->setopt(CURLOPT_URL, "https://app.streamsend.com/ audiences"); $curl->setopt(CURLOPT_RETURNTRANSFER,1); $curl->setopt(CURLOPT_WRITEFUNCTION,\&ret_data2); my $result = $curl->perform(); my $err = $curl->errbuff; print "err = ".$err."\n"; $curl->dispose(); } ###################################################################### +## # ret_data2 # is called once curl is completed ###################################################################### +## sub ret_data2 { print "ret_data\n"; my $chunk = shift; #this will get the xml print $chunk; $xp = new XML::DOM::Parser(); $doc = $xp->parse($chunk); $self->{ss_account_id} = $doc->getElementsByTagName("id")->item(0)- >getFirstChild->getNodeValue; $self->{ss_email_address} = $doc->getElementsByTagName("from-email- address")->item(0)->getFirstChild->getNodeValue; return 0; } } 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl Package & Curl
by Anonymous Monk on Dec 15, 2008 at 15:09 UTC | |
by Bloodnok (Vicar) on Dec 15, 2008 at 15:23 UTC | |
Re: Perl Package & Curl
by Anonymous Monk on Dec 15, 2008 at 15:11 UTC |