Category Article

Easily integrating your Mojolicious app with Facebook.

Facebook has recently released a new Graph API. It’s a simple RESTish API, and uses the newly released OAuth2 spec for authorization. This makes it a great match for Mojolicious, and using my new OAuth2 plugin (Also coming to a CPAN mirror near you), it’s absolutely trivial.

Here is a simple Lite example. Just register an app with facebook to get the key and secret.

   use Mojolicious::Lite;
   # configure the plugin
   plugin 'oauth2', facebook => {
       key => 'my-key',
       secret => 'my-secret' };

   get 'hello' => sub { 
      My $self=shift;
      #redirects the gets the token asynchronous   
   $self->get_token('facebook', callback => sub {
      my $token=shift;
      my $me=$self->client->get(
        'https://graph.facebook.com/me?access_token='.$token)->res->json;
          $self->render( text =>
            "Hello ".$me->{name} );
    });

As you can see, the plugin handles the request flow automatically. We then use the built in JSON parsing in the Mojolicious Client to turn the API data into structures we can work with in our application.

Updating facebook data is just as trivial, you just use post requests with the data you need to update. See http://graph.facebook.com/ for more info on that.

If you plan to run your app through a standalone daemon such as Hypnotoad (I really think you should :) It could be worth it to rewrite the last section of your app to take advantage of async operations like this:

  $self->client->async->get(        'https://graph.facebook.com/me?access_token='.$token, sub {
  my $me=shift->res->json;
  $self->render( text=>"Hello ".$me->{name} );
})->start;

The async plugin itself also supports an optional async=>1 setting to enable async fetching of the token.

iPad as a writer’ s tool

I believe I have found my ideal writing tool. For the last couple of months, I have been drafting text using iA Writer on the iPad. While the softward keyboard is cumbersome to use, I find the focus the combination gives very inspiring. Nothing but me and the text, no IMs or emails to disturb me. I have turned off notifications on the iPad, so not even a ongoing game of Words With Friends can spoil my productivity.

Today I was out shopping on Oxford street, and on a whim I picked up the iPad keyboard dock. This thing is awesome! It has the required special keys to interact with the iPad’s functionality, but otherwise it feels just like Apple’s other excellent keyboards. It holds the iPad vertically in just the right angle, and plugs into a power source, as well as external speakers if I need music while I work. In short, I am in love.

I expect this to be my primary writing tool for the near future. If I’m going to nitpick, the only thing I am hoping for is higher DPI on the next generation of iPads so that iA Writer can fit a bit more text per line. One final trick; The keyboard lets you switch between languages with cmd-space. Exactly the same combination I use to switch between norwegian and english keyboard layouts on the mac. Pretty awesome.

My first Mojolicious Plugin – Proxy

A few days ago I uploaded my first Mojolicious plugin to CPAN, Mojolicious::Plugin::Proxy. My use case was that I am writing a simple single-file html5/javascript app, which needed to access a remote JSON feed. When running on a device with file:/// URLs, cross-site scripting is not an issue, but when running on a web-server, my appis unable to reach that remote JSON feed, so I wrote this plugin to allow me to simply proxy JSON requests from the local server to the remote one. This is how it works

    plugin 'proxy';
   get 'ws' => sub { shift->proxy_to('http://remote_url', with_query_params=>1);

The fact that Mojolicious includes a full async http client made this plugin trivial to implement. The unit tests is almost more code than the module itself.

Mozilla Javascript documentation

JavaScript JS Documentation: JS String match, JavaScript String match, JS String .match, JavaScript String .match

3 reasons for the lack of updates here lately

Dark Nebula Episode 2

dark_nebula_ep2.jpg

Gravity Hook

gravity_hook.jpg

Van Helsing

van_helsing.jpg

i use this, now 50% more social.

We’ve just pushed a major update to iusethis, adding several social features and updating the commenting system with support for replies. To improve performance, we’ve also added a new caching system, to allow us to cache more data for logged-in users.

Find your friends

Looking up your contacts in GMail is a feature that we’ve wanted for a long time, but we did not want to compromise users by asking for their passwords. Now that Google supports OAuth we were able to implement it the way we wanted. In order to use it, go to your profile and click the ‘more’ link on the ‘friends’ sidebar:

i_use_this_mac_os_x_software__applications_used_by_marcus-20100622-095254.png

Once There, click on this sidebar:

i_use_this_mac_os_x_software__friends_of_marcus-20100622-094917.png

The system asks you to grant iusethis permission to access your address book data, choose the google account you use:

Google_Accounts-20100622-102953.png

Then we will present you with a list of contacts who have accounts on iusethis. Just press the ‘follow’ link to add them.

Messaging

You can now contact users on iusethis directly. To do this, go to the user’s profile, and click the contact link:

i_use_this_mac_os_x_software__Recent_comments_by_rob-20100622-103404.png

Then just write your message and click ‘Send’. Just like everywhere else on iusethis, you can use textile formatting in your message. The message will be delivered to the user as a normal email, with your registered email address as the ‘From’ address, so that he can easily respond to your message.

i_use_this_mac_os_x_software__software_for_the_osx_population-20100622-103530.png

If you do not want to accept messages from users, you can disable it from preference.

 

i_use_this_mac_os_x_software__software_for_the_osx_population-20100622-114940.png

We also added app owners to the app page, in case you want to contact them:

YoruFukurou_-_i_use_this_on_mac_os_x-20100622-143625.png

Replies

@username replies has been a defacto convention on iusethis for a long time, and we’ve already been doing things like linking to users automatically, but now we actually support links back to the comment you’re responding to. This also means that each comment has it’s own permanent page:

i_use_this_mac_os_x_software__comment_left_by_marcus_on_Steam_at_2010-06-16T08_43_38-20100622-130535.png

For consistency we are now using relative timestamps for dates everywhere, and the dates act as permalinks. By default, we will assume you are responding to the latest comment by this user on the app you’re commenting on, but if you want to reply to a specific comment, you can use the ‘reply to comment’ link on the comment permalink page. We also took the opportunity to streamline the user comments page to be more like the main recent comments list:

i_use_this_mac_os_x_software__Recent_comments_by_brh-20100622-142656.png

Hope these changes are useful to you. If you have feedback, please respond to out twitter account, @iut.

Turn your iPad into a mifi

Note: I do not recommend doing this. There are easier ways. But still, an awesome hack.

DBIx-Class about to switch to git

12:27 <ribasushi> a call to all git-heads

12:28 <ribasushi> recently haarg did a seemingly perfect conversion of dbic from svn to git (a non-trivial feat)

12:28 <ribasushi> I am calling for people who actually know git to randomly poke at the new history and notufy me of whatever problems they see

12:28 <ribasushi> http://github.com/haarg/DBIx-Class

12:29 <ribasushi> (also you can ascertain the quality of the conversion, and potentially draft haarg to do a catalyst conversion as well – it took him a couple of freaking hours to do dbic)

12:32 <marcus> awesome

12:32 <marcus> haarg++

12:33 <marcus> it looks freaking good

12:33 <ribasushi> marcus: please spread the word to get more eyeballs on this, if nothing pops up in the next day and a half we’ll be  switching dbic over

Consider this me having spread the word to you ;-)

Top 10 useless professions

  • Healer
  • Astrologer
  • Homeopath
  • Social Media Expert
  • Politician
  • Search Engine Optimization specialist
  • Patent Lawyer
  • Life Coach
  • Personal Shopper
  • Human Resources Manager

Did I miss any important ones? Help out by posting on twitter with the #uselessprofessions tag.

Slides from my Mojolicious presentation

I recently held a introduction to the Mojolicious web framework for Oslo.pm. Here are the slides:

Copyright © marcus ramberg
nordaaker

Built on Notes Blog Core
Powered by WordPress