Category Archives: News

Small Ember.js and SMS Example

There is a new small code example on github for how to use ember.js and the 42com REST API v3.
Ember.js is an open-source client-side JavaScript web application framework based on the model-view-controller (MVC) software architectural pattern. It allows developers to create scalable single-page applications[1] by incorporating common idioms and best practices into a framework that provides a rich object model, declarative two-way data binding, computed properties, automatically-updating templates powered by Handlebars.js, and a router for managing application state [Wikipedia].
See it in action at 42call.

Authentication Javascript

It is really simple to build a small website using our API.
We do not care about Same-Origin-Policy so you’re able to build web applications running on web servers, as APPs on mobile devices and as applications at the personal computer.

For this example we provide the code on guthub named 42call-sms.
You need to include some library’s to start over.

Start with the correct date format for the x-date header parameter.

var now = new Date();
date = new Date(now.getTime());
date = date.toISOString();

Then hash the users password with md5.

var passMd5 = CryptoJS.MD5($('#password').val());
passMd5 = passMd5.toString();

Combine the date and the md5 password with an line break and encode it with the md5 password.

var hash = CryptoJS.HmacSHA1(passMd5+"\n"+date, passMd5);
hash = hash.toString(CryptoJS.enc.Base64);

The preparation of the header is done. So fire the request to the api url like /api/rest/v2/?sms.

$.ajax({
    type:"POST",
    headers : {
        "x-date" : date,
        "x-authorization" : $('#inputUsername').val()+":"+hash,
}, 
    data: { act: "sendSms", phonenumbers : '123465798', message : 'hello world!'},
    url: "https://login.42call.com/api/rest/v2/?sms"
}).done(function(data) {
    alert(data);
    $.mobile.loading('hide');
});

Done.
More about SMS here.