NAME

Net::Travis::API::UA::Response - Subclass of HTTP::Tiny::UA::Response for utility methods

VERSION

version 0.001000

DESCRIPTION

This class warps extends HTTP::Tiny::UA::Response and adds a few utility methods and features that either

1. Have not yet been approved for merge
2. Don't make sense to propagate to a general purpose HTTP User Agent.

METHODS

content_type

Returns the type/subtype portion of the content-type header.

Returns undef if there was no content-type header.

if ( $result->content_type eq 'application/json' ) {
    ...
}

content_type_params

Returns all parameter parts of the content-type header as an ArrayRef.

Returns an empty ArrayRef if no such parameters were sent in the content-type header, or there was no content-type header.

for my $header ( @{ $result->content_type_params } ) {
    if ( $header =~ /^charset=(.+)/ ) {
        print "A charset of $1 was specified! :D";
    }
}

decoded_content

Returns ->content after applying type specific decoding.

At present, this means everything that is not text/* will simply yield ->content

And everything that is text/* without a text/*;charset=someencoding will simply yield ->content

my $foo = $result->decoded_content(); # text/* with a specified encoding interpreted properly.

Optionally, you can pass a forced encoding to apply and override smart detection.

my $foo = $result->decoded_content('utf-8'); # type specific encodings ignored, utf-8 forced.

content_json

Returns a the data decoded from JSON.

Returns undef if the data

->content_json() # decodes automatically as per applicable encoding
               # or returns undef if its not application/json

->content_json(undef) # Forces decoding as json, but defers the text encoding
                    # method to use either utf-8 or an encoding specified
                    # by a ;charset= parameter.

->content_json('utf-8') # Forces decoding as json, and forces the text decoding to utf-

ATTRIBUTES

json

Optional.

A JSON Object for decoding JSON

AUTHOR

Kent Fredric <kentfredric@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.