From 0fb58d26680b4894cbb220ce6a75d5c4f87a736d Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Mon, 2 Dec 2013 12:21:18 +0100 Subject: [PATCH] MT#3997 Use JSON in OPTIONS methods. --- lib/NGCP/Panel/Controller/API/ContactsItem.pm | 8 ++++---- lib/NGCP/Panel/Controller/API/ContractsItem.pm | 8 ++++---- lib/NGCP/Panel/Controller/API/ResellersItem.pm | 16 ++++++++-------- share/templates/api/precondition_failed.tt | 10 ---------- share/templates/api/require_preference.tt | 10 ---------- 5 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 share/templates/api/precondition_failed.tt delete mode 100644 share/templates/api/require_preference.tt diff --git a/lib/NGCP/Panel/Controller/API/ContactsItem.pm b/lib/NGCP/Panel/Controller/API/ContactsItem.pm index 906379f8dc..eb98c038da 100644 --- a/lib/NGCP/Panel/Controller/API/ContactsItem.pm +++ b/lib/NGCP/Panel/Controller/API/ContactsItem.pm @@ -76,14 +76,14 @@ sub HEAD :Allow { sub OPTIONS :Allow { my ($self, $c, $id) = @_; - my $allowed_methods = $self->allowed_methods->join(q(, )); + my $allowed_methods = $self->allowed_methods; $c->response->headers(HTTP::Headers->new( - Allow => $allowed_methods, + Allow => $allowed_methods->join(', '), Accept_Patch => 'application/json-patch+json', Content_Language => 'en', )); - $c->response->content_type('application/xhtml+xml'); - $c->stash(template => 'api/allowed_methods.tt', allowed_methods => $allowed_methods); + $c->response->content_type('application/json'); + $c->response->body(JSON::to_json({ methods => $allowed_methods })."\n"); return; } diff --git a/lib/NGCP/Panel/Controller/API/ContractsItem.pm b/lib/NGCP/Panel/Controller/API/ContractsItem.pm index 6d3efbd854..0ffd82995f 100644 --- a/lib/NGCP/Panel/Controller/API/ContractsItem.pm +++ b/lib/NGCP/Panel/Controller/API/ContractsItem.pm @@ -78,14 +78,14 @@ sub HEAD :Allow { sub OPTIONS :Allow { my ($self, $c, $id) = @_; - my $allowed_methods = $self->allowed_methods->join(q(, )); + my $allowed_methods = $self->allowed_methods; $c->response->headers(HTTP::Headers->new( - Allow => $allowed_methods, + Allow => $allowed_methods->join(', '), Accept_Patch => 'application/json-patch+json', Content_Language => 'en', )); - $c->response->content_type('application/xhtml+xml'); - $c->stash(template => 'api/allowed_methods.tt', allowed_methods => $allowed_methods); + $c->response->content_type('application/json'); + $c->response->body(JSON::to_json({ methods => $allowed_methods })."\n"); return; } diff --git a/lib/NGCP/Panel/Controller/API/ResellersItem.pm b/lib/NGCP/Panel/Controller/API/ResellersItem.pm index 665e76b599..c67443e071 100644 --- a/lib/NGCP/Panel/Controller/API/ResellersItem.pm +++ b/lib/NGCP/Panel/Controller/API/ResellersItem.pm @@ -30,7 +30,7 @@ __PACKAGE__->config( action_roles => [qw(HTTPMethods)], ); -sub GET : Allow { +sub GET :Allow { my ($self, $c) = @_; $c->response->status(HTTP_NOT_IMPLEMENTED); $c->response->headers(HTTP::Headers->new( @@ -41,26 +41,26 @@ sub GET : Allow { return; } -sub HEAD : Allow { +sub HEAD :Allow { my ($self, $c) = @_; $c->forward(qw(GET)); $c->response->body(q()); return; } -sub OPTIONS : Allow { +sub OPTIONS :Allow { my ($self, $c) = @_; - my $allowed_methods = $self->allowed_methods->join(q(, )); + my $allowed_methods = $self->allowed_methods; $c->response->headers(HTTP::Headers->new( - Allow => $allowed_methods, + Allow => $allowed_methods->join(', '), Content_Language => 'en', )); - $c->response->content_type('application/xhtml+xml'); - $c->stash(template => 'api/allowed_methods.tt', allowed_methods => $allowed_methods); + $c->response->content_type('application/json'); + $c->response->body(JSON::to_json({ methods => $allowed_methods })."\n"); return; } -sub end : Private { +sub end :Private { my ($self, $c) = @_; $c->forward(qw(Controller::Root render)); $c->response->content_type('') diff --git a/share/templates/api/precondition_failed.tt b/share/templates/api/precondition_failed.tt deleted file mode 100644 index fb98ed70e1..0000000000 --- a/share/templates/api/precondition_failed.tt +++ /dev/null @@ -1,10 +0,0 @@ - - - - Precondition failed - - -

This [% entity_name | html %] entity cannot be found, it is either expired or does not exist. - Fetch a fresh one.

- - diff --git a/share/templates/api/require_preference.tt b/share/templates/api/require_preference.tt deleted file mode 100644 index f741a2cd16..0000000000 --- a/share/templates/api/require_preference.tt +++ /dev/null @@ -1,10 +0,0 @@ - - - - Preference required - - -

This request is required to express an expectation about the response. Use the Prefer header with - either a return=minimal or a return=representation preference.

- -