Atompub

 view release on metacpan or  search on metacpan

lib/Atompub/Client.pm  view on Meta::CPAN

    $client->updateEntry($edit_uri, $entry);

    $client->deleteEntry($edit_uri);

    # CRUD a Media Resource; assuming that the 1-st collection supports
    # Media Resources
    my $collection_uri = $collections[1]->href;

    my $name = 'My Photo';

    my $edit_uri = $client->createMedia($collection_uri, 'sample1.png',
                                        'image/png', $name);

    # Get a href attribute of an "edit-media" link
    my $edit_media_uri = $client->resource->edit_media_link;

    my $binary = $client->getMedia($edit_media_uri);

    $client->updateMedia($edit_media_uri, 'sample2.png', 'image/png');

    $client->deleteEntry($edit_media_uri);

    # Access to the requested HTTP::Request object
    my $request  = $client->request;

    # Access to the received HTTP::Response object
    my $response = $client->response;

    # Access to the received resource (XML::Atom object or binary data)

lib/Atompub/Client.pm  view on Meta::CPAN



=head2 $client->createMedia($collection_uri, $media, $media_type, [ $slug ])

Creates a new Media Resource and a Media Link Entry in the collection
at URI $collection_uri.

If $media is a reference to a scalar, it is treated as the binary.
If a scalar, treated as a file containing the Media Resource.

$media_type is the media type of the Media Resource, such as 'image/png'.

$slug is set in the I<Slug> header, and may be used as part of
the resource URI.

Returns a I<Location> header, which contains a URI of the newly created resource,
or false on error.


=head2 $client->getEntry($edit_uri)

lib/Atompub/Client.pm  view on Meta::CPAN

Returns true on success, false otherwise.


=head2 $client->updateMedia($edit_uri, $media, $media_type)

Updates the Media Resource at URI $edit_uri with the $media.

If $media is a reference to a scalar, it is treated as the binary.
If a scalar, treated as a file containing the Media Resource.

$media_type is the media type of the Media Resource, such as 'image/png'.

Returns true on success, false otherwise.


=head2 $client->deleteEntry($edit_uri)

Deletes the Entry Document at URI $edit_uri.

Returns true on success, false otherwise.

lib/Atompub/MediaType.pm  view on Meta::CPAN

__END__

=head1 NAME

Atompub::MediaType - a media type object for the Atom Publishing Protocol

=head1 SYNOPSIS

    use Atompub::MediaType qw(media_type);

    my $type = media_type('image/png');

    "$type";                        # 'image/png'
    $type->type;                    # 'image'
    $type->subtype;                 # 'png'

    $type->extension;               # 'png'

    $type->is_a('image/*');         # true
    $type->is_a('image/gif');       # false

    my $type = media_type('entry');

    "$type";                        # 'application/atom+xml;type=entry'
    $type->type;                    # 'application'
    $type->subtype;                 # 'atom+xml'
    $type->parameters;              # 'type=entry'

lib/Atompub/MediaType.pm  view on Meta::CPAN


    $type->is_a('application/xml'); # true
    $type->is_a('feed');            # false

=head1 METHODS

=head2 Atompub::MediaType->new([ $type ])

Returns a media type object representing the time $type.

$type is string representing media type like 'image/png'.
Some aliases are defined for Atom, 'entry', 'feed', 'service', and 'categories'.

=head2 media_type([ $str ])

Alias for Atompub::MediaType->new

=head2 $type->type

=head2 $type->subtype

t/03.media_type.t  view on Meta::CPAN

use strict;
use warnings;
#use Data::Dumper; $Data::Dumper::Indent = 1;
use Test::More tests => 37;

use Atompub::MediaType qw(media_type);

my $png = media_type('image/png');
isa_ok $png, 'Atompub::MediaType';

is $png->type, 'image';
is $png->subtype, 'png';
is $png->parameters, undef;

is $png->subtype_major, 'png';

is $png->without_parameters, 'image/png';
is $png->as_string, 'image/png';

is $png->extensions, 'png';
is $png->extension, 'png';

ok $png->is_a('*/*');
ok $png->is_a('image/*');
ok $png->is_a('image/png');

ok $png->is_not_a('text/*');
ok $png->is_not_a('image/jpeg');

is "$png", 'image/png';

ok $png eq '*/*';
ok $png ne 'text/*';

my $atom = media_type('entry');
isa_ok $atom, 'Atompub::MediaType';

is $atom->type, 'application';
is $atom->subtype, 'atom+xml';
is $atom->parameters, 'type=entry';

is $atom->subtype_major, 'xml';

t/04.util.t  view on Meta::CPAN


use Atompub::MediaType qw(media_type);
use Atompub::Util qw(is_acceptable_media_type is_allowed_category);
use XML::Atom::Service;

# is_acceptable_media_type

my $coll = XML::Atom::Collection->new;

ok  is_acceptable_media_type($coll, media_type('entry'));
ok !is_acceptable_media_type($coll, 'image/png');

$coll->accept('application/xml');
ok  is_acceptable_media_type($coll, media_type('entry'));
ok !is_acceptable_media_type($coll, 'image/png');

$coll->accept(media_type('entry'));
ok  is_acceptable_media_type($coll, media_type('entry'));
ok !is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/png');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/*');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/png', 'image/jpeg', 'image/gif');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');

$coll->accept('image/png,image/jpeg,image/gif');
ok !is_acceptable_media_type($coll, media_type('entry'));
ok  is_acceptable_media_type($coll, 'image/png');


# is_allowed_category

my $cat1 = XML::Atom::Category->new;
$cat1->term('animal');
my $cat1_s = XML::Atom::Category->new;
$cat1_s->term('animal');
$cat1_s->scheme('http://example.com/cats/big3');
my $cat2 = XML::Atom::Category->new;

t/05.info.t  view on Meta::CPAN

is $cat[1]->term, 'vegetable';
is $cat[1]->scheme, undef;
is $cat[2]->term, 'mineral';
is $cat[2]->scheme, 'http://example.com/dogs/big3';

# put and get a resource, which has app:accept

$coll = XML::Atom::Collection->new;
$coll->title( 'Photo' );
$coll->href( 'http://example.com/photo' );
$coll->accept( 'image/png', 'image/jpeg', 'image/gif' );

$info->put( $coll->href, $coll );
$coll = $info->get( $coll->href );
isa_ok $coll, 'XML::Atom::Collection';

my @accepts = $coll->accepts;
is $accepts[0], 'image/png';
is $accepts[1], 'image/jpeg';
is $accepts[2], 'image/gif';

# remove a resource

$info->put( $coll->href );
is $info->get( $coll->href ), undef;



( run in 2.974 seconds using v1.01-cache-2.11-cpan-df04353d9ac )