Permalink
Browse files

Merge pull request #1 from moritz/syncupdate

use syncupdate API, and depend on LWP::UserAgent instead of WWW::Mechanize
  • Loading branch information...
2 parents acfb666 + f153162 commit cdbd0f9fd5ec1f574c75ffe4a830ef6d53b4716f @arhuman arhuman committed Sep 11, 2012
Showing with 22 additions and 37 deletions.
  1. +1 −0 Changes
  2. +1 −1 Makefile.PL
  3. +15 −31 lib/Net/Whois/Object.pm
  4. +5 −5 t/215-SyncUpdates.t
View
@@ -1,5 +1,6 @@
Revision history for net-whois-ripe
+ - Depend on LWP::UserAgent instead of WWW::Mechanize
2.00015 17 Jul 2012
- Change the way to test if t/common.pl was well loaded
View
@@ -16,7 +16,7 @@ WriteMakefile(
},
META_MERGE => {
recommends => {
- 'WWW::Mechanize' => 0,
+ 'LWP::UserAgent' => 0,
},
resources => {
repository => 'https://github.com/arhuman/Net-Whois-RIPE',
@@ -3,15 +3,14 @@ use strict;
use warnings;
use Carp;
-#use WWW::Mechanize;
use Net::Whois::RIPE;
use Data::Dumper;
-our $MECHANIZED;
+our $LWP;
BEGIN {
- $MECHANIZED = do {
+ $LWP = do {
eval {
- require WWW::Mechanize;
+ require LWP::UserAgent;
};
($@) ? 0 : 1;
};
@@ -82,7 +81,7 @@ RIPE provides several web interfaces
Although not the latest one, this simple interface is the first to be wrapped
by this module.
-B<CAUTION: SyncUpdates features require WWW::Mechanize to be installed.>
+B<CAUTION: SyncUpdates features require LWP::UserAgent to be installed.>
=head4 Create
@@ -561,39 +560,24 @@ Return the HTML code of the returned page.
sub _syncupdates_submit {
my ( $self, $text, $password ) = @_;
- croak "WWW::Mechanize required for updates" unless $MECHANIZED;
+ croak "LWP::UserAgent required for updates" unless $LWP;
- $text .= "password: $password\n" if $password;
-
- my $mech = WWW::Mechanize->new();
-
- $mech->get('https://apps.db.ripe.net/syncupdates/simple-rpsl.html');
-
- my $form = $mech->form_number(2);
-
- if ( $self->source() eq 'RIPE' ) {
-
- $mech->set_fields( 'rpslBox:postRpsl:sourceRadioSelect' => 'RIPE_NCC' );
- }
- else {
- $mech->set_fields( 'rpslBox:postRpsl:sourceRadioSelect' => 'TEST' );
- }
+ my $url = $self->source eq 'RIPE'
+ ? 'http://syncupdates.db.ripe.net/'
+ : 'http://syncupdates-test.db.ripe.net';
- $mech->set_fields( 'rpslBox:postRpsl:sourceRadioSelect' => 'TEST' );
- $mech->set_fields( 'rpslBox:postRpsl:rpslObject' => "$text\n" );
-
- my $r = $mech->click_button( value => 'Update' );
-
- croak "Can't submit to syncupdates : " . $mech->response()->status_linel unless $mech->success;
+ $text .= "password: $password\n" if $password;
- my $page = $mech->response()->content;
+ my $ua = LWP::UserAgent->new;
- if ( $page !~ /Number of objects processed successfully: 1/s ) {
+ my $response = $ua->post($url, { DATA => $text });
+ my $response_text = $response->decoded_content;
- # carp "Syncupdate failed :\n$page\n";
+ unless ($response->is_success) {
+ croak "Can't sync object with RIPE database: $response_text"
}
- return $page;
+ return $response_text;
}
=head1 TODO
View
@@ -6,11 +6,11 @@ use Net::Whois::RIPE;
use Net::Whois::Object;
use Data::Dumper;
-our $MECHANIZED;
+our $LWP;
BEGIN {
- $MECHANIZED = do {
+ $LWP = do {
eval {
- require WWW::Mechanize;
+ require LWP::UserAgent;
};
($@) ? 0 : 1;
};
@@ -21,8 +21,8 @@ unless ( $ENV{TEST_MNTNER} && $ENV{TEST_MNTNER_PASSWORD} ) {
plan skip_all => ' Set environment vars for server testing';
}
-unless ($MECHANIZED) {
- plan skip_all => 'WWW::Mechanize installation required for update';
+unless ($LWP) {
+ plan skip_all => 'LWP::UserAgent installation required for update';
}
plan tests => 5;

0 comments on commit cdbd0f9

Please sign in to comment.