ICal-QuickAdd

 view release on metacpan or  search on metacpan

lib/ICal/QuickAdd.pm  view on Meta::CPAN

 my $desc = $iqa->parsed_string;

Return a short description. Useful for confirming to the user how the Quick Add string was
parsed.

Limitations: the description returned currently always includes hours/minute compontent
and is in 24 hour time.

=cut

sub parsed_string {
    my $self = shift;
    my $dt = $self->get_dt;
    return sprintf("Event: %s on %s %d, %d at %02d:%02d",
            $self->get_msg, $dt->month_abbr, $dt->day, $dt->year, $dt->hour, $dt->minute);

}

=head2 as_vevent()

 my $vevent = $iqa->as_vevent;

Return a L<Data::ICal::Entry::Event> object representing the event.

For now, hard-code a one hour duration

=cut

sub as_vevent {
    my $self = shift;

    # XXX Could add caching here.

    require Data::ICal::Entry::Event;
    require DateTime::Format::ICal;
    my $vevent = Data::ICal::Entry::Event->new;
       $vevent->add_properties(
           summary => $self->get_msg,
           dtstart => DateTime::Format::ICal->format_datetime($self->get_dt),
           dtend   => DateTime::Format::ICal->format_datetime( $self->get_dt->add( hours => 1 ) ),
       );
    return $vevent;

}

=head2 as_ical()

 my $data_ical = $iqa->as_ical;

Returns a L<Data::ICal> object with the "PUBLISH" method set.

The PUBLISH method is used when mailing iCalendar events.

=cut

sub as_ical {
    my $self = shift;

    require Data::ICal;

     my $calendar = Data::ICal->new;
     $calendar->add_entry( $self->as_vevent );
     $calendar->add_properties( method => 'PUBLISH');

     return $calendar;
}

=head2 as_ical_email()

 my $email_simple_obj = $iqa->as_ical_email(
        To    => $your_regular_email,
        From  => $from_email, # Defaults to $iqa->from_email
  );

Returns a ready-to-mail L<Email::Simple> object with an iCalendar body.
Extra headers  can be passed in.

=cut

sub as_ical_email {
    my $self = shift;
    my %in = validate(@_, {
        To    => { type => SCALAR },
        From  => { type => SCALAR, default => $self->from_email },
    });

     require Email::Simple;
     my $email = Email::Simple->new('');
     $email->header_set("Content-Type", "text/calendar; name=calendar.ics; charset=utf-8; METHOD=PUBLISH");
     $email->header_set(From => $in{From} );
     $email->header_set(To => $in{To} );

     $email->header_set("Subject", $self->parsed_string );
     $email->body_set( $self->as_ical->as_string );

     use Email::Date;
     $email->header_set( Date => format_date );

     return $email;
}



=head2 from_email()

Returns the 'from' email address. It can also be used as a check
to see if the SMS came from an email at all, since will only be set in that case.

=cut

sub from_email {
    my $self = shift;
    return $self->{from_email};
}

=head2 from_email_obj()

If the input was an email, returns the object representing
the incoming message. Currently a L<Mail::Audit> object.

=cut

sub from_email_obj {
    my $self = shift;
    return $self->{from_email_obj}

}

=head2 get_msg()

 Return the event name found in the SMS message.

=cut

sub get_msg {
    my $self = shift;
    return $self->{msg};
}

=head2 get_dt()

Returns DateTime object found in SMS.

=cut

sub get_dt {
    my $self = shift;
    return $self->{dt};
}



( run in 1.076 second using v1.01-cache-2.11-cpan-39bf76dae61 )