NAME

WWW::GoDaddy::REST::Util - Mostly URL tweaking utilities for this package

SYNOPSIS

use WWW::GoDaddy::REST::Util qw/ abs_url add_filters_to_url /;

# http://example.com/v1/asdf
abs_url('http://example.com/v1','/asdf');

# http://example.com?sort=asc&fname=Fred
add_filters_to_url('http://example.com?sort=asc',{ 'fname' => [ { 'value': 'Fred' } ] });

DESCRIPTION

Utilities used commonly in this package. Most have to do with URL manipulation.

FUNCTIONS

is_json

Given a json string, return true if it is parsable, false otherwise.

If you need to control the parameters to the JSON module, simply pass additional parameters. These will be passed unchanged to json_instance.

Example:

my $yes = is_json('"asdf"');
my $yes = is_json('{"key":"value"}');
my $no  = is_json('dafsafsadfsdaf');
json_decode

Given a json string, return the perl data structure. This will die() if it can not be parsed.

If you need to control the parameters to the JSON module, simply pass additional parameters. These will be passed unchanged to json_instance.

Example:

my $hashref = json_decode('{"key":"value"}');
json_encode

Given a perl data structure, return the json string. This will die() if it can not be serialized.

If you need to control the parameters to the JSON module, simply pass additional parameters. These will be passed unchanged to json_instance.

Example:

my $json = json_encode({ 'key' => 'value' });
json_instance

Returns JSON instance. If no parameters are given the following defaults are set: convert_blessed, allow_nonref.

If called with one parameter, it is assumed to be a JSON instance and this is returned instead of building a new one.

If called with more than one parameter, it is assumed to be key/value pairs and will be passed to the JSON property method two by two.

Example:

$j = json_instance(); #defaults
$j = json_instance( JSON->new ); #pass through
$j = json_instance( 'convert_blessed' => 1, 'allow_nonref' => 1 ); # set properies
abs_url

Given a base and path fragment, generate an absolute url with the two joined.

Example:

# http://example.com/v1/asdf
abs_url('http://example.com/v1','/asdf');
add_filters_to_url

Given a url and a query filter, generate a url with the filter query parameters added.

Filter syntax can be seen in the docs for WWW::GoDaddy::REST.

Example:

add_filters_to_url('http://example.com?sort=asc',{ 'fname' => [ { 'value': 'Fred' } ] });
# http://example.com?sort=asc&fname=Fred
build_complex_query_url

Return a modified URL string given a URL, an optional filter spec, and optional query parameter hash.

If you specify a sort, then an order parameter will be filled in if not present, and and sort or order query parameters in the input string will be replaced.

All other query parameters (filters etc) will be appended to the query parameters of the input URL instead of replacing.

Example:

build_complex_query_url(
  'http://example.com',
  {
    'foo' => 'bar'
  },
  {
    'sort' => 'surname'
  }
);
# http://example.com?foo=bar&sort=surname&order=asc

EXPORTS

None by default.

AUTHOR

David Bartle, <davidb@mediatemple.net>

COPYRIGHT & LICENSE

Copyright (c) 2014 Go Daddy Operating Company, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.