Firebase with perl

I was looking at ways to add instant notifications for a social feature that we are working on for the new version of Brainturk.com, I came across Firebase which is a scalable real-time backend database that makes it easy to build real time apps.

I wanted to use this from my server as well as from Javascript and looking at their libraries for custom generators they have libraries for ( php, python, ruby, node, java , .net ) but no perl library was available.

I looked at the python source and came up with a perl version to generate tokens, I am able to use to use this module to authenticate and add/delete data from perl .

To get the data

    my $tk="SECRET"; 
    my $custom_data = {'auth_data' => 'foo1',
               'other_auth_data'=> 'bar1'};
    my $options = {'admin' => 'true'};

    my $firebase = Firebase::Auth->new ( token =>$tk);
     my $token = 
     $firebase->create_token ( $custom_data, $options );

    my $ua = Mojo::UserAgent->new;

    my $tx2 = $ua->get(
         "https://yourfirebase.firebaseio.com/.json" =>  form 
          => {auth =>  $token}  )->res->body;

To post data

   my $tk="SECRET";
   my $custom_data = {'auth_data' => 'foo1', 
                              'other_auth_data'=> 'bar1'};
   my $options = {'admin' => 'true'};

   my $firebase = Firebase::Auth->new ( token =>$tk);
   my $token = 
     $firebase->create_token ( $custom_data, $options );

   my $ua = Mojo::UserAgent->new;
   my $tx2 = $ua->put(
                     "https://yourfirebase.firebaseio.com/.json?auth=$token" 
            => {DNT => 1} => json => $custom_data )->res->body;

3 Comments

Yeah, I don't think anyone bothers writing official libraries / API wrappers for Perl anymore, so not a surprise.

Thanks for this. Giving it a try now.

You can actually get access to the interface I wrote at the following URL https://github.com/plainblack/Lacuna-Server-Open/tree/master/lib/WWW/Firebase

I will do a bit of work when I get time and release to a separate git repository and onto CPAN

Leave a comment

About Kiran

user-pic I blog about Perl.