added the joker-whois
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Sun, 21 Dec 2014 18:02:02 +0100
changeset 5 21e23104454c
parent 4 08a632c3244f
child 6 3319abec33a5
added the joker-whois And added a new lib Joker::Result
joker-whois
joker2
lib/Joker.pm
lib/Joker/Result.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/joker-whois	Sun Dec 21 18:02:02 2014 +0100
@@ -0,0 +1,39 @@
+#! /usr/bin/perl
+
+use 5.010;
+use strict;
+use warnings;
+use Smart::Comments;
+
+use lib 'lib';
+use Joker;
+
+my %conf = do 'joker.conf';
+
+my $joker = Joker->new(
+    username => $conf{username},
+    password => $conf{password},
+);
+
+my $x =  $joker->request('query-whois', domain => shift);
+say $x->code, ':', $x->status;
+if ($x->code == 0) {
+    my %result = %{ $x->data };
+    foreach (sort keys %result) {
+	say "$_: $result{$_}";
+    }
+}
+
+exit 0;
+
+### $x
+
+__END__
+
+#say $joker->request('query-domain-list');
+my @results = map { (split)[1] } grep { /^\d/ } split /\r?\n/,
+  $joker->request('result-list', status => 'nack');
+
+foreach (@results) {    ### deleting: [===|    ] [%]
+    $joker->request('result-delete', 'svtrid' => $_);
+}
--- a/joker2	Fri Aug 08 16:35:25 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#! /usr/bin/perl
-
-use 5.010;
-use strict;
-use warnings;
-use Smart::Comments;
-
-use lib 'lib';
-use Joker;
-
-my %conf = do 'joker.conf';
-
-my $joker = Joker->new(
-    username => $conf{username},
-    password => $conf{password},
-);
-
-#say $joker->request('query-domain-list');
-my @results = map { (split)[1] } grep { /^\d/ } split /\r?\n/,
-  $joker->request('result-list', status => 'nack');
-
-foreach (@results) {    ### deleting: [===|    ] [%]
-    $joker->request('result-delete', 'svtrid' => $_);
-}
--- a/lib/Joker.pm	Fri Aug 08 16:35:25 2014 +0200
+++ b/lib/Joker.pm	Sun Dec 21 18:02:02 2014 +0100
@@ -8,6 +8,7 @@
 use Moose;
 use MooseX::SemiAffordanceAccessor;
 use LWP::UserAgent;
+use Joker::Result;
 
 has [qw(username password)] => (
     isa => 'Str',
@@ -44,7 +45,7 @@
 	GET => $self->uri . "$type?" .  join '&', map { "$_=$parm{$_}" } keys %parm);
     my $result = $self->ua->request($req);
     croak $result->status_line if not $result->is_success;
-    return $result->content;
+    return Joker::Result->new(response => $result->content);
 }
 
 sub login {
@@ -61,4 +62,4 @@
     croak q{Can't get Auth-Sid};
 }
 
-1;
+__PACKAGE__->meta->make_immutable;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Joker/Result.pm	Sun Dec 21 18:02:02 2014 +0100
@@ -0,0 +1,64 @@
+package Joker::Result;
+use Moose;
+use MooseX::SemiAffordanceAccessor;
+
+has response => (is => 'ro', isa => 'Str');
+
+has fields => (
+    is       => 'ro',
+    isa	     => 'ArrayRef',
+    lazy     => 1,
+    init_arg => undef,
+    builder  => '_fields'
+);
+
+has status => (
+    is       => 'ro',
+    lazy     => 1,
+    init_arg => undef,
+    builder => '_status'
+);
+
+has data => (
+    is => 'ro',
+    isa => 'HashRef',
+    lazy => 1,
+    init_arg => undef,
+    builder => '_data',
+);
+
+has fields => (
+    is => 'ro',
+    isa => 'ArrayRef',
+    lazy => 1,
+    init_arg => undef,
+    default => sub { sort keys %{ $_[0]->data } },
+);
+
+has code => (
+    is => 'ro',
+    isa => 'Int',
+    lazy => 1,
+    init_arg => undef,
+    default => sub { $_[0]->data->{'status-code'} },
+);
+
+has status => (
+    is => 'ro',
+    isa => 'Str',
+    lazy => 1,
+    init_arg => undef,
+    default => sub { $_[0]->data->{'status-text'} },
+);
+
+sub _data {
+    my $self = shift;
+    my %_data;
+    my $_ = $self->response;
+    while (/^(\S+):\s*(.*)$/gm) {
+	$_data{lc $1} = $2;
+    }
+    return \%_data;
+}
+
+__PACKAGE__->meta->make_immutable;