| 1 | package Pikeo::API::Comment; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use base qw( Pikeo::API::Base ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | use Carp; | ||
| 9 | use Data::Dumper; | ||
| 10 | |||
| 11 | sub _info_fields {qw( owner_id owner_username date picture_id parent_id text )} | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | Pikeo::API::Comment - Abstraction of a pikeo user comment | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | Provides access to a comment details | ||
| 20 | |||
| 21 | You should not use this module directly. | ||
| 22 | |||
| 23 | =head1 FUNCTIONS | ||
| 24 | |||
| 25 | =head2 CONSTRUCTORS | ||
| 26 | |||
| 27 | =head3 new( \%args ) | ||
| 28 | |||
| 29 | Returns a Pikeo::API::Comment object. | ||
| 30 | |||
| 31 | Required args are: | ||
| 32 | |||
| 33 | =over 4 | ||
| 34 | |||
| 35 | =item * api | ||
| 36 | |||
| 37 | Pikeo::API object | ||
| 38 | |||
| 39 | =item * from_xml | ||
| 40 | |||
| 41 | XML::LibXML node containing the contact details | ||
| 42 | |||
| 43 | =back | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub new { | ||
| 48 | my $class = shift; | ||
| 49 | my $params = shift; | ||
| 50 | |||
| 51 | my $self = $class->SUPER::new($params); | ||
| 52 | |||
| 53 | if ( $params->{from_xml} ) { | ||
| 54 | $self->_init_from_xml( $params->{from_xml} ); | ||
| 55 | return $self; | ||
| 56 | } | ||
| 57 | croak "Need an xml object"; | ||
| 58 | } | ||
| 59 | |||
| 60 | =head3 id() | ||
| 61 | |||
| 62 | The id of the comment | ||
| 63 | |||
| 64 | =cut | ||
| 65 | sub id { return shift->{id} } | ||
| 66 | |||
| 67 | =head3 update(\%args) | ||
| 68 | |||
| 69 | Updates the text of the comment. | ||
| 70 | |||
| 71 | You must be owner | ||
| 72 | |||
| 73 | Required args are: | ||
| 74 | |||
| 75 | =over 4 | ||
| 76 | |||
| 77 | =item * text | ||
| 78 | |||
| 79 | The text to update | ||
| 80 | |||
| 81 | =back | ||
| 82 | |||
| 83 | =cut | ||
| 84 | sub update { | ||
| 85 | my $self = shift; | ||
| 86 | my $params = shift; | ||
| 87 | |||
| 88 | croak "missing required param 'text'" unless $params->{text}; | ||
| 89 | $self->api->request_parsed( 'pikeo.comments.updateComment', | ||
| 90 | { comment_id => $self->id, | ||
| 91 | text => $params->{text}, | ||
| 92 | } | ||
| 93 | ); | ||
| 94 | return 1; | ||
| 95 | } | ||
| 96 | |||
| 97 | =head3 delete() | ||
| 98 | |||
| 99 | Deletes the comment. You must be owner | ||
| 100 | |||
| 101 | =cut | ||
| 102 | sub delete { | ||
| 103 | my $self = shift; | ||
| 104 | my $params = shift; | ||
| 105 | |||
| 106 | $self->api->request_parsed( 'pikeo.comments.deleteComment', | ||
| 107 | { comment_id => $self->id } | ||
| 108 | ); | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | |||
| 112 | =head3 owner_id | ||
| 113 | |||
| 114 | =head3 owner_username | ||
| 115 | |||
| 116 | =head3 date | ||
| 117 | |||
| 118 | =head3 picture_id | ||
| 119 | |||
| 120 | =head3 parent_id | ||
| 121 | |||
| 122 | =head3 text | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | sub _init_from_xml { | ||
| 127 | my $self = shift; | ||
| 128 | my $doc = shift; | ||
| 129 | my $nodes = $doc->findnodes("./*"); | ||
| 130 | for ($nodes->get_nodelist()) { | ||
| 131 | $self->{$_->nodeName} = ( $_->to_literal eq 'null' ? undef : $_->to_literal ); | ||
| 132 | } | ||
| 133 | croak "could not init from XML, missing id" unless $self->{id}; | ||
| 134 | $self->{_init} = 1; | ||
| 135 | } | ||
| 136 | |||
| 137 | 1; | ||