690 |
bless($self, $class); |
bless($self, $class); |
691 |
|
|
692 |
if (@_) { |
if (@_) { |
693 |
$self->{debug} = 1; |
$self->{debug} = shift; |
694 |
warn "## Node debug on\n"; |
warn "## Node debug on\n"; |
695 |
} |
} |
696 |
|
|
774 |
|
|
775 |
=head2 put_doc |
=head2 put_doc |
776 |
|
|
777 |
$node->put_doc( $document_draft ); |
Add a document |
778 |
|
|
779 |
|
$node->put_doc( $document_draft ) or die "can't add document"; |
780 |
|
|
781 |
|
Return true on success or false on failture. |
782 |
|
|
783 |
=cut |
=cut |
784 |
|
|
785 |
sub put_doc { |
sub put_doc { |
786 |
my $self = shift; |
my $self = shift; |
787 |
my $doc = shift || return; |
my $doc = shift || return; |
788 |
$self->shuttle_url( $self->{url} . '/put_doc', 'text/x-estraier-draft', $doc->dump_draft, undef); |
return unless ($self->{url}); |
789 |
|
$self->shuttle_url( $self->{url} . '/put_doc', |
790 |
|
'text/x-estraier-draft', |
791 |
|
$doc->dump_draft, |
792 |
|
undef |
793 |
|
) == 200; |
794 |
|
} |
795 |
|
|
796 |
|
|
797 |
|
=head2 out_doc |
798 |
|
|
799 |
|
Remove a document |
800 |
|
|
801 |
|
$node->out_doc( document_id ) or "can't remove document"; |
802 |
|
|
803 |
|
Return true on success or false on failture. |
804 |
|
|
805 |
|
=cut |
806 |
|
|
807 |
|
sub out_doc { |
808 |
|
my $self = shift; |
809 |
|
my $id = shift || return; |
810 |
|
return unless ($self->{url}); |
811 |
|
croak "id must be number" unless ($id =~ m/^\d+$/); |
812 |
|
$self->shuttle_url( $self->{url} . '/out_doc', |
813 |
|
'application/x-www-form-urlencoded', |
814 |
|
"id=$id", |
815 |
|
undef |
816 |
|
) == 200; |
817 |
|
} |
818 |
|
|
819 |
|
|
820 |
|
=head2 out_doc_by_uri |
821 |
|
|
822 |
|
Remove a registrated document using it's uri |
823 |
|
|
824 |
|
$node->out_doc_by_uri( 'file:///document_url' ) or "can't remove document"; |
825 |
|
|
826 |
|
Return true on success or false on failture. |
827 |
|
|
828 |
|
=cut |
829 |
|
|
830 |
|
sub out_doc_by_uri { |
831 |
|
my $self = shift; |
832 |
|
my $uri = shift || return; |
833 |
|
return unless ($self->{url}); |
834 |
|
$self->shuttle_url( $self->{url} . '/out_doc', |
835 |
|
'application/x-www-form-urlencoded', |
836 |
|
"uri=$uri", |
837 |
|
undef |
838 |
|
) == 200; |
839 |
} |
} |
840 |
|
|
841 |
=head2 shuttle_url |
=head2 shuttle_url |
857 |
|
|
858 |
$self->{status} = -1; |
$self->{status} = -1; |
859 |
|
|
860 |
warn "## $url\n"; |
warn "## $url\n" if ($self->{debug}); |
861 |
|
|
862 |
$url = new URI($url); |
$url = new URI($url); |
863 |
if ( |
if ( |
916 |
carp "can't send headers to network:\n$headers\n" and return -1; |
carp "can't send headers to network:\n$headers\n" and return -1; |
917 |
|
|
918 |
if ($reqbody) { |
if ($reqbody) { |
919 |
warn $reqbody if ($self->{debug}); |
warn "$reqbody\n" if ($self->{debug}); |
920 |
print $sock $reqbody or |
print $sock $reqbody or |
921 |
carp "can't send request body to network:\n$$reqbody\n" and return -1; |
carp "can't send request body to network:\n$$reqbody\n" and return -1; |
922 |
} |
} |