[Bps-public-commit] rt-extension-rest2 branch, dev, updated. f81d5ce58c114ad66beafa8d3de511206ec4f8ad

Dustin Graves dustin at bestpractical.com
Wed Aug 3 18:26:18 EDT 2016


The branch, dev has been updated
       via  f81d5ce58c114ad66beafa8d3de511206ec4f8ad (commit)
       via  e94a59177e0201c69f982b5421d6baa319578148 (commit)
       via  ecb7b2928f32b6cb845f3ad54e6f60f371e97220 (commit)
       via  89cb25c08dde9f42bbf54c4d2a62cca9f7d431a8 (commit)
      from  365f37a142c2b83f61425d25072cf2b38901bf9e (commit)

Summary of changes:
 lib/RT/Extension/REST2/Middleware/ErrorAsJSON.pm |  4 ++--
 lib/RT/Extension/REST2/Resource/Collection.pm    |  5 +++--
 lib/RT/Extension/REST2/Resource/Record.pm        |  6 +++---
 lib/RT/Extension/REST2/Resource/Tickets.pm       | 14 +++-----------
 4 files changed, 11 insertions(+), 18 deletions(-)

- Log -----------------------------------------------------------------
commit 89cb25c08dde9f42bbf54c4d2a62cca9f7d431a8
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Wed Aug 3 16:10:08 2016 +0000

    avoid "Use of uninitialized value in pattern match" warning

diff --git a/lib/RT/Extension/REST2/Middleware/ErrorAsJSON.pm b/lib/RT/Extension/REST2/Middleware/ErrorAsJSON.pm
index 7bf3686..265f9d7 100644
--- a/lib/RT/Extension/REST2/Middleware/ErrorAsJSON.pm
+++ b/lib/RT/Extension/REST2/Middleware/ErrorAsJSON.pm
@@ -16,8 +16,8 @@ sub call {
         my $psgi_res = shift;
         my $status_code = $psgi_res->[0];
         my $headers = $psgi_res->[1];
-        my $is_json
-            = Plack::Util::header_get($headers, 'content-type') =~ m/json/i;
+        my $content_type = Plack::Util::header_get($headers, 'content-type');
+        my $is_json = $content_type && $content_type =~ m/json/i;
         if ( is_error($status_code) && !$is_json ) {
             my $plack_res = Plack::Response->new($status_code, $headers);
             error_as_json($plack_res, undef, status_message($status_code));

commit ecb7b2928f32b6cb845f3ad54e6f60f371e97220
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Wed Aug 3 17:37:25 2016 +0000

    ensure record _url property has API path e.g. /REST/2.0

diff --git a/lib/RT/Extension/REST2/Resource/Record.pm b/lib/RT/Extension/REST2/Resource/Record.pm
index 99a903c..99d7935 100644
--- a/lib/RT/Extension/REST2/Resource/Record.pm
+++ b/lib/RT/Extension/REST2/Resource/Record.pm
@@ -42,9 +42,9 @@ sub _build_record {
 
 sub base_uri {
     my $self = shift;
-    my $base = $self->request->base;
-    my $type = record_type($self);
-    return $base . lc $type;
+    my $base = RT::Extension::REST2->base_uri;
+    my $type = lc record_type($self);
+    return join '/', $base, $type;
 }
 
 sub resource_exists {

commit e94a59177e0201c69f982b5421d6baa319578148
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Wed Aug 3 21:39:23 2016 +0000

    make tickets searches without results return 200 with an empty result set instead of 404

diff --git a/lib/RT/Extension/REST2/Resource/Tickets.pm b/lib/RT/Extension/REST2/Resource/Tickets.pm
index afcb57b..f74860e 100644
--- a/lib/RT/Extension/REST2/Resource/Tickets.pm
+++ b/lib/RT/Extension/REST2/Resource/Tickets.pm
@@ -41,17 +41,9 @@ sub allowed_methods {
 
 sub limit_collection {
     my $self = shift;
-    my $collection = $self->collection;
-    my ($ok, $msg) = $collection->FromSQL( $self->query );
-    my $status_code;
-    if ($ok) {
-        unless ($collection->Count) {
-            ($status_code, $ok, $msg) = (\404, 0, 'No tickets found');
-        }
-    }
-    return error_as_json(
-        $self->response, $ok ? 1 : ($status_code // 0), $msg
-    );
+    my ($ok, $msg) = $self->collection->FromSQL( $self->query );
+    return error_as_json( $self->response, 0, $msg ) unless $ok;
+    return 1;
 }
 
 __PACKAGE__->meta->make_immutable;

commit f81d5ce58c114ad66beafa8d3de511206ec4f8ad
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Wed Aug 3 22:26:11 2016 +0000

    have collections results use expanded UID for items instead of full serialization

diff --git a/lib/RT/Extension/REST2/Resource/Collection.pm b/lib/RT/Extension/REST2/Resource/Collection.pm
index daf733e..7d61bbf 100644
--- a/lib/RT/Extension/REST2/Resource/Collection.pm
+++ b/lib/RT/Extension/REST2/Resource/Collection.pm
@@ -11,7 +11,7 @@ use Scalar::Util qw( blessed );
 use Web::Machine::Util qw( bind_path create_date );
 use Web::Machine::FSM::States qw( is_status_code );
 use Module::Runtime qw( require_module );
-use RT::Extension::REST2::Util qw( serialize_record );
+use RT::Extension::REST2::Util qw( serialize_record expand_uid );
 
 has 'collection_class' => (
     is          => 'ro',
@@ -67,7 +67,8 @@ sub serialize {
     my @results;
 
     while (my $item = $collection->Next) {
-        push @results, serialize_record($item);
+        # TODO: Allow selection of desired fields
+        push @results, expand_uid( $item->UID );
     }
     return {
         count       => scalar(@results)         + 0,

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list