1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
# RT::Client::REST::Attachment -- attachment object representation.
package RT::Client::REST::Attachment;
use strict;
use warnings;
use vars qw($VERSION);
$VERSION = 0.03;
use Params::Validate qw(:types);
use RT::Client::REST::Object 0.01;
use RT::Client::REST::Object::Exception 0.03;
use base 'RT::Client::REST::Object';
sub _attributes {{
id => {
validation => {
type => SCALAR,
regex => qr/^\d+$/,
},
},
creator_id => {
validation => {
type => SCALAR,
regex => qr/^\d+$/,
},
rest_name => 'Creator',
},
parent_id => {
validation => {
type => SCALAR,
regex => qr/^\d+$/,
},
},
subject => {
validation => {
type => SCALAR,
},
},
content_type => {
validation => {
type => SCALAR,
},
rest_name => "ContentType",
},
file_name => {
validation => {
type => SCALAR,
},
rest_name => 'Filename',
},
transaction_id => {
validation => {
type => SCALAR,
regex => qr/^\d+$/,
},
rest_name => 'Transaction',
},
message_id => {
validation => {
type => SCALAR,
},
rest_name => 'MessageId',
},
created => {
validation => {
type => SCALAR,
},
is_datetime => 1,
},
content => {
validation => {
type => SCALAR,
},
},
headers => {
validation => {
type => SCALAR,
},
},
parent => {
validation => {
type => SCALAR,
},
},
content_encoding => {
validation => {
type => SCALAR,
},
rest_name => 'ContentEncoding',
},
}}
sub rt_type { 'attachment' }
sub retrieve {
my $self = shift;
$self->from_form(
$self->rt->get_attachment(
parent_id => $self->parent_id,
id => $self->id,
),
);
$self->{__dirty} = {};
return $self;
}
my @unsupported = qw(store search count);
# Override unsupported methods.
for my $method (@unsupported) {
no strict 'refs';
*$method = sub {
my $self = shift;
RT::Client::REST::Object::IllegalMethodException->throw(
ref($self) . " does not support '$method' method",
);
};
}
sub can {
my ($self, $method) = @_;
if (grep { $_ eq $method } @unsupported) {
return;
}
return $self->SUPER::can($method);
}
__PACKAGE__->_generate_methods;
1;
__END__
=head1 NAME
RT::Client::REST::Attachment -- this object represents an attachment.
=head1 SYNOPSIS
my $attachments = $ticket->attachments;
my $count = $attachments->count;
print "There are $count attachments.\n";
my $iterator = $attachments->get_iterator;
while (my $att = &$iterator) {
print "Id: ", $att->id, "; Subject: ", $att->subject, "\n";
}
=head1 DESCRIPTION
An attachment is a second-class citizen, as it does not exist (at least
from the current REST protocol implementation) by itself. At the moment,
it is always associated with a ticket (see B<parent_id> attribute).
Thus, you will
rarely retrieve an attachment by itself; instead, you should use
C<attachments()> method of L<RT::Client::REST::Ticket> object to get
an iterator for all attachments for that ticket.
=head1 ATTRIBUTES
=over 2
=item B<id>
Numeric ID of the attachment.
=item B<creator_id>
Numeric ID of the user who created the attachment.
=item B<parent_id>
Numeric ID of the object the attachment is associated with. This is not
a proper attribute of the attachment as specified by REST -- it is simply
to store the ID of the L<RT::Client::REST::Ticket> object this attachment
belongs to.
=item B<subject>
Subject of the attachment.
=item B<content_type>
Content type.
=item B<file_name>
File name (if any).
=item B<transaction_id>
Numeric ID of the L<RT::Client::REST::Transaction> object this attachment
is associated with.
=item B<message_id>
Message ID.
=item B<created>
Time when the attachment was created
=item B<content>
Actual content of the attachment.
=item B<headers>
Headers (not parsed), if any.
=item B<parent>
Parent (not sure what this is yet).
=item B<content_encoding>
Content encoding, if any.
=back
=head1 METHODS
B<RT::Client::REST::Attachment> is a read-only object, so you cannot
C<store()> it. Also, because it is a second-class citizen, you cannot
C<search()> or C<count()> it -- use C<attachments()> method provided
by L<RT::Client::REST::Ticket>.
=over 2
=item retrieve
To retrieve an attachment, attributes B<id> and B<parent_id> must
be set.
=back
=head1 INTERNAL METHODS
=over 2
=item B<rt_type>
Returns 'attachment'.
=back
=head1 SEE ALSO
L<RT::Client::REST::Ticket>,
L<RT::Client::REST::SearchResult>.
=head1 AUTHOR
Dmitri Tikhonov <dtikhonov@yahoo.com>
=head1 LICENSE
Perl license.
=cut
|