eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / UI / REST.pm
1 package FS::UI::REST;
2 use base qw( Exporter );
3
4 use strict;
5 use vars qw( @EXPORT_OK );
6 use Cpanel::JSON::XS;
7 use FS::UID qw( adminsuidsetup );
8 use FS::Conf;
9
10 @EXPORT_OK = qw( rest_auth rest_uri_remain encode_rest );
11
12 sub rest_auth {
13   my $cgi = shift;
14   adminsuidsetup('fs_api');
15   my $conf = new FS::Conf;
16   die 'Incorrect shared secret'
17     unless $cgi->param('secret') eq $conf->config('api_shared_secret');
18 }
19
20 sub rest_uri_remain {
21   my($r, $m) = @_;
22
23   #wacky way to get this... surely there must be a better way
24
25   my $path = $m->request_comp->path;
26
27   $r->uri =~ /\Q$path\E\/?(.*)$/ or die "$path not in ". $r->uri;
28
29   $1;
30
31 }
32
33 sub encode_rest {
34   #XXX HTTP Accept header to send other formats besides JSON
35   encode_json(shift);
36 }
37
38 1;