Net-DRI

 view release on metacpan or  search on metacpan

lib/Net/DRI/Protocol/EPP/Extensions/Nominet/Account.pm  view on Meta::CPAN

   $c->pc($n->textContent());
  } elsif ($name eq 'country')
  {
   $c->cc($n->textContent());
  }
 }

 $c->street(\@street);
}

sub build_addr
{
 my ($c,$type)=@_;
 my @d;
 my @s=$c->street();
 if (@s)
 {
  @s=@{$s[0]};
  push @d,['account:street',$s[0]];
  push @d,['account:locality',$s[1]];
 }
 push @d,['account:city',$c->city()] if $c->city();
 push @d,['account:county',$c->sp()] if $c->sp();
 push @d,['account:postcode',$c->pc()] if $c->pc();
 push @d,['account:country',$c->cc()] if $c->cc();
 return @d? ['account:addr',{type=>$type},@d] : ();
}

sub add_account_data
{
 my ($mes,$cs,$ischange)=@_;
 my $modtype=$ischange? 'update' : 'create';
 my @a;
 my @o=$cs->get('registrant');
 if (Net::DRI::Util::isa_contact($o[0],'Net::DRI::Data::Contact::Nominet'))
 {
  $o[0]->validate($ischange);
  push @a,['account:name',$o[0]->name()] unless $ischange;
  push @a,['account:trad-name',$o[0]->org()] if $o[0]->org();
  push @a,['account:type',$o[0]->type()] if (!$ischange || $o[0]->type());
  push @a,['account:co-no',$o[0]->co_no()] if $o[0]->co_no();
  push @a,['account:opt-out',$o[0]->opt_out()] if (!$ischange || $o[0]->opt_out());
  push @a,build_addr($o[0],'admin');
 } else
 {
  Net::DRI::Exception::usererr_insufficient_parameters('registrant data is mandatory') unless $ischange;
 }

 if (Net::DRI::Util::isa_contact($o[1],'Net::DRI::Data::Contact::Nominet'))
 {
  $o[1]->validate() unless $ischange;
  my @t=build_addr($o[1],'billing');
  push @a,($ischange && !@t)? ['account:addr',{type=>'billing'}] : @t;
 }

 @o=$cs->get('admin');
 Net::DRI::Exception::usererr_insufficient_parameters('admin data is mandatory') unless ($ischange || Net::DRI::Util::isa_contact($o[0],'Net::DRI::Data::Contact::Nominet'));
 foreach my $o (0..2)
 {
   last unless defined($o[$o]);
   my @t=Net::DRI::Protocol::EPP::Extensions::Nominet::Contact::build_cdata($o[$o]);
   my $contype=$ischange? (($o[$o]->srid())? 'update' : 'create') : $modtype;
   push @a,['account:contact',{type=>'admin',order=>$o+1},($ischange && !@t)? () : ['contact:'.$contype,@t]];
 }
 @o=$cs->get('billing');
 foreach my $o (0..2)
 {
   last unless defined($o[$o]);
   my @t=Net::DRI::Protocol::EPP::Extensions::Nominet::Contact::build_cdata($o[$o]);
   my $contype=$ischange? (($o[$o]->srid())? 'update' : 'create') : $modtype;
   push @a,['account:contact',{type=>'billing',order=>$o+1},($ischange && !@t)? () : ['contact:'.$contype,@t]];
 }
 return @a;
}

sub update
{
 my ($epp,$c,$todo)=@_;
 my $mes=$epp->message();
 Net::DRI::Exception::usererr_invalid_parameters($todo.' must be a Net::DRI::Data::Changes object') unless Net::DRI::Util::isa_changes($todo);
 my $cs=$todo->set('contact');
 Net::DRI::Exception::usererr_invalid_parameters($cs.' must be a Net::DRI::Data::ContactSet object') unless Net::DRI::Util::isa_contactset($cs);
 my @d=build_command($mes,'update',$c);
 push @d,add_account_data($mes,$cs,1);
 $mes->command_body(\@d);
}

sub fork
{
 my ($epp,$c,$rh)=@_;
 Net::DRI::Exception::usererr_invalid_parameters('For account fork, a domains key must be there with a ref array of domain names to fork') unless (Net::DRI::Util::has_key($rh,'domains') && (ref($rh->{domains}) eq 'ARRAY'));

 my $mes=$epp->message();
 $mes->command(['update','account:fork',sprintf('xmlns:account="%s" xsi:schemaLocation="%s %s"',$mes->nsattrs('account'))]);
 my @d;
 my $id=extract_contact_id($c);
 push @d,['account:roid',$id] if (defined($id) && $id);
 foreach my $d (@{$rh->{domains}})
 {
  next unless (defined($d) && $d && Net::DRI::Util::is_hostname($d));
  push @d,['account:domain-name',$d];
 }
 $mes->command_body(\@d);
}

sub parse_credata
{
 my ($mes,$node,$po,$cs,$rinfo)=@_;
 my %c;
 my $nsa=$mes->ns('account');
 my $roid=$node->getChildrenByTagNameNS($nsa,'roid')->get_node(1)->textContent();
 my $name=$node->getChildrenByTagNameNS($nsa,'name')->get_node(1)->textContent();
 my $co=$po->create_local_object('contact')->srid($roid)->name($name);
 $cs->set($co,'registrant');
 $rinfo->{contact}->{$roid}->{exist}=1;
 $rinfo->{contact}->{$roid}->{roid}=$roid;
 $rinfo->{contact}->{$roid}->{self}=$co;
 my $nsc=$mes->ns('contact');
 foreach my $ac ($node->getChildrenByTagNameNS($nsa,'contact'))
 {
  my $type=$ac->getAttribute('type');
  my $order=$ac->getAttribute('order');
  my $credata=$ac->getChildrenByTagNameNS($nsc,'creData')->get_node(1);
  my $roid2=$credata->getChildrenByTagNameNS($nsc,'roid')->get_node(1)->textContent();
  my $name2=$credata->getChildrenByTagNameNS($nsc,'name')->get_node(1)->textContent();
  $co=$po->create_local_object('contact')->srid($roid2)->name($name2);
  $c{$type}->{$order}=$co;
  $rinfo->{contact}->{$roid2}->{exist}=1;
  $rinfo->{contact}->{$roid2}->{roid}=$roid2;



( run in 0.502 second using v1.01-cache-2.11-cpan-140bd7fdf52 )