summaryrefslogtreecommitdiff
path: root/FS/FS/UI
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-07-16 06:17:05 -0700
committerIvan Kohler <ivan@freeside.biz>2014-07-16 06:17:05 -0700
commit5f8111de04a4a914c72a1642722476db4728339c (patch)
treeb7ae766bcb35d53828a1690ae78d9bff179dcbab /FS/FS/UI
parentc7cc0522832d0e1c056f9bce46dd1b4b5551e612 (diff)
REST API, RT#28181
Diffstat (limited to 'FS/FS/UI')
-rw-r--r--FS/FS/UI/REST.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/FS/FS/UI/REST.pm b/FS/FS/UI/REST.pm
new file mode 100644
index 0000000..b6503ba
--- /dev/null
+++ b/FS/FS/UI/REST.pm
@@ -0,0 +1,38 @@
+package FS::UI::REST;
+use base qw( Exporter );
+
+use strict;
+use vars qw( @EXPORT_OK );
+use JSON::XS;
+use FS::UID qw( adminsuidsetup );
+use FS::Conf;
+
+@EXPORT_OK = qw( rest_auth rest_uri_remain encode_rest );
+
+sub rest_auth {
+ my $cgi = shift;
+ adminsuidsetup('fs_api');
+ my $conf = new FS::Conf;
+ die 'Incorrect shared secret'
+ unless $cgi->param('secret') eq $conf->config('api_shared_secret');
+}
+
+sub rest_uri_remain {
+ my($r, $m) = @_;
+
+ #wacky way to get this... surely there must be a better way
+
+ my $path = $m->request_comp->path;
+
+ $r->uri =~ /\Q$path\E\/?(.*)$/ or die "$path not in ". $r->uri;
+
+ $1;
+
+}
+
+sub encode_rest {
+ #XXX HTTP Accept header to send other formats besides JSON
+ encode_json(shift);
+}
+
+1;