Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use URI::Template to Level 2 RFC 6570 URI Template parameters. #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"JSON::WebToken" : "0",
"LWP::Protocol::https" : "0",
"URI" : "0",
"URI::Escape" : "0"
"URI::Escape" : "0",
"URI::Template" : "0"
}
},
"test" : {
Expand Down Expand Up @@ -77,4 +78,3 @@
"shigeta <shigeta@typhoon.(none)>"
]
}

1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
requires 'URI';
requires 'URI::Escape';
requires 'URI::Template';
requires 'HTTP::Request';
requires 'JSON';
requires 'JSON::WebToken';
Expand Down
10 changes: 8 additions & 2 deletions lib/Google/API/Method.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Encode;
use HTTP::Request;
use URI;
use URI::Escape qw/uri_escape/;
use URI::Template;

sub new {
my $class = shift;
Expand All @@ -28,7 +29,12 @@ sub execute {
$required_param{$p} = delete $self->{opt}{body}{$p};
}
}
$url =~ s/{([^}]+)}/uri_escape(delete $required_param{$1})/eg;
my $template = URI::Template->new($url);
$url = $template->process( %required_param );
# remove from required_param all variables in the url template (the path
# variables)
delete @required_param{$template->variables()};

my $uri = URI->new($url);
my $request;
if ($http_method eq 'POST' ||
Expand All @@ -39,7 +45,7 @@ sub execute {
$request = HTTP::Request->new($http_method => $uri);
# Some API's (ie: admin/directoryv1/groups/delete) require requests
# with an empty body section to be explicitly zero length.
if (%{$self->{opt}{body}}) {
if ($self->{opt}{body} && %{$self->{opt}{body}}) {
$request->content_type('application/json');
$request->content($self->{json_parser}->encode($self->{opt}{body}));
} else {
Expand Down