/[notice-sender]/trunk/Nos.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Nos.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 52 by dpavlin, Wed May 25 15:03:10 2005 UTC revision 59 by dpavlin, Tue Jun 21 20:49:27 2005 UTC
# Line 16  our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all' Line 16  our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'
16  our @EXPORT = qw(  our @EXPORT = qw(
17  );  );
18    
19  our $VERSION = '0.4';  our $VERSION = '0.5';
20    
21  use Class::DBI::Loader;  use Class::DBI::Loader;
22  use Email::Valid;  use Email::Valid;
# Line 26  use Email::Auth::AddressHash; Line 26  use Email::Auth::AddressHash;
26  use Email::Simple;  use Email::Simple;
27  use Email::Address;  use Email::Address;
28  use Mail::DeliveryStatus::BounceParser;  use Mail::DeliveryStatus::BounceParser;
29    use Class::DBI::AbstractSearch;
30    
31    
32  =head1 NAME  =head1 NAME
# Line 74  sub new { Line 75  sub new {
75                  user            => $self->{'user'},                  user            => $self->{'user'},
76                  password        => $self->{'passwd'},                  password        => $self->{'passwd'},
77                  namespace       => "Nos",                  namespace       => "Nos",
78  #               additional_classes      => qw/Class::DBI::AbstractSearch/,                  additional_classes      => qw/Class::DBI::AbstractSearch/,
79  #               additional_base_classes => qw/My::Stuff/,  #               additional_base_classes => qw/My::Stuff/,
80                  relationships   => 1,                  relationships   => 1,
81          ) || croak "can't init Class::DBI::Loader";          ) || croak "can't init Class::DBI::Loader";
# Line 129  Add new member to list Line 130  Add new member to list
130          list => "My list",          list => "My list",
131          email => "john.doe@example.com",          email => "john.doe@example.com",
132          name => "John A. Doe",          name => "John A. Doe",
133            ext_id => 42,
134   );   );
135    
136  C<name> parametar is optional.  C<name> and C<ext_id> parametars are optional.
137    
138  Return member ID if user is added.  Return member ID if user is added.
139    
# Line 145  sub add_member_to_list { Line 147  sub add_member_to_list {
147          my $email = lc($arg->{'email'}) || croak "can't add user without e-mail";          my $email = lc($arg->{'email'}) || croak "can't add user without e-mail";
148          my $name = $arg->{'name'} || '';          my $name = $arg->{'name'} || '';
149          my $list_name = lc($arg->{'list'}) || croak "need list name";          my $list_name = lc($arg->{'list'}) || croak "need list name";
150            my $ext_id = $arg->{'ext_id'};
151    
152          my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist";          my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist";
153    
# Line 167  sub add_member_to_list { Line 170  sub add_member_to_list {
170                  $this_user->update;                  $this_user->update;
171          }          }
172    
173            if (defined($ext_id) && ($this_user->ext_id || '') ne $ext_id) {
174                    $this_user->ext_id($ext_id);
175                    $this_user->update;
176            }
177    
178          my $user_on_list = $user_list->find_or_create({          my $user_on_list = $user_list->find_or_create({
179                  user_id => $this_user->id,                  user_id => $this_user->id,
180                  list_id => $list->id,                  list_id => $list->id,
# Line 194  Returns array of hashes with user inform Line 202  Returns array of hashes with user inform
202          email => 'dpavlin@rot13.org          email => 'dpavlin@rot13.org
203   }   }
204    
205  If list is not found, returns false.  If list is not found, returns false. If there is C<ext_id> in user data,
206    that will also be returned.
207    
208  =cut  =cut
209    
# Line 218  sub list_members { Line 227  sub list_members {
227                          email => $user_on_list->user_id->email,                          email => $user_on_list->user_id->email,
228                  };                  };
229    
230                    my $ext_id = $user_on_list->user_id->ext_id;
231                    $row->{'ext_id'} = $ext_id if (defined($ext_id));
232    
233                  push @results, $row;                  push @results, $row;
234          }          }
235    
# Line 263  sub delete_member { Line 275  sub delete_member {
275          return $users->dbi_commit || croak "can't commit";          return $users->dbi_commit || croak "can't commit";
276  }  }
277    
278    =head2 delete_member_from_list
279    
280    Delete member from particular list.
281    
282     my $ok = delete_member_from_list(
283            list => 'My list',
284            email => 'dpavlin@rot13.org',
285     );
286    
287    Returns false if user doesn't exist on that particular list.
288    
289    It will die if list or user doesn't exist. You have been warned (you might
290    want to eval this functon to prevent it from croaking).
291    
292    =cut
293    
294    sub delete_member_from_list {
295            my $self = shift;
296    
297            my $args = {@_};
298    
299            croak "need list name and email of user to delete" unless ($args->{'list'} && $args->{'email'});
300    
301            $args->{'list'} = lc($args->{'list'});
302            $args->{'email'} = lc($args->{'email'});
303    
304            my $user = $self->{'loader'}->find_class('users');
305            my $list = $self->{'loader'}->find_class('lists');
306            my $user_list = $self->{'loader'}->find_class('user_list');
307    
308            my $this_user = $user->search( email => $args->{'email'} )->first || croak "can't find user: ".$args->{'email'};
309            my $this_list = $list->search( name => $args->{'list'} )->first || croak "can't find list: ".$args->{'list'};
310    
311            my $this_user_list = $user_list->search_where( list_id => $this_list->id, user_id => $this_list->id )->first || return;
312    
313            $this_user_list->delete || croak "can't delete user from list\n";
314    
315            return $user_list->dbi_commit || croak "can't commit";
316    }
317    
318  =head2 add_message_to_list  =head2 add_message_to_list
319    
320  Adds message to one list's queue for later sending.  Adds message to one list's queue for later sending.
# Line 661  sub new { Line 713  sub new {
713    
714   $message_id = NewList(   $message_id = NewList(
715          list => 'My list',          list => 'My list',
716            from => 'Name of my list',
717          email => 'my-list@example.com'          email => 'my-list@example.com'
718   );   );
719    
# Line 671  sub NewList { Line 724  sub NewList {
724    
725          if ($_[0] !~ m/^HASH/) {          if ($_[0] !~ m/^HASH/) {
726                  return $nos->new_list(                  return $nos->new_list(
727                          list => $_[0], email => $_[1],                          list => $_[0], from => $_[1], email => $_[2],
728                  );                  );
729          } else {          } else {
730                  return $nos->new_list( %{ shift @_ } );                  return $nos->new_list( %{ shift @_ } );
# Line 684  sub NewList { Line 737  sub NewList {
737   $member_id = AddMemberToList(   $member_id = AddMemberToList(
738          list => 'My list',          list => 'My list',
739          email => 'e-mail@example.com',          email => 'e-mail@example.com',
740          name => 'Full Name'          name => 'Full Name',
741            ext_id => 42,
742   );   );
743    
744  =cut  =cut
# Line 694  sub AddMemberToList { Line 748  sub AddMemberToList {
748    
749          if ($_[0] !~ m/^HASH/) {          if ($_[0] !~ m/^HASH/) {
750                  return $nos->add_member_to_list(                  return $nos->add_member_to_list(
751                          list => $_[0], email => $_[1], name => $_[2],                          list => $_[0], email => $_[1], name => $_[2], ext_id => $_[4],
752                  );                  );
753          } else {          } else {
754                  return $nos->add_member_to_list( %{ shift @_ } );                  return $nos->add_member_to_list( %{ shift @_ } );

Legend:
Removed from v.52  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26