I was very impressed to see Mobile Vikings (see earlier post) released an API that allows us to get hold of our account data. I've spent an hour or two working on an ActionScript 3.0 implementation that you can use in your AIR applications. Right now they've provided three API calls: retrieve your SIM balance, see your call history and see your topup history.

Here's how you set it up:

var api:MobileVikings = new MobileVikings("username","password");

 
Get your SIM balance

public function init():void
{
  var api:MobileVikings = new MobileVikings("username","password");
  api.getSimBalance();
  api.addEventListener(MobileVikings.SIM_BALANCE_LOADED, balanceLoaded);
  api.addEventListener(MobileVikings.SIM_BALANCE_FAILED, balanceFailed);
}
private function balanceLoaded(evt:SimBalanceEvent):void
{
  trace(evt.credits);
}

private function balanceFailed(evt:Event):void
{
  trace("fail");
}

When the SIM balance is loaded successfully you get access to credits, validity, SMS and data remaining etc.

 
Get your call history

public function init():void
{
  var api:MobileVikings = new MobileVikings("username","password");
  api.getCallHistory();
  api.addEventListener(MobileVikings.CALL_HISTORY_LOADED, callHistoryLoaded);
  api.addEventListener(MobileVikings.CALL_HISTORY_FAILED, callHistoryFailed);
}
private function callHistoryLoaded(evt:CallHistoryEvent):void
{
  trace(evt.callHistory);
}

private function callHistoryFailed(evt:Event):void
{
  trace("fail");
}

The call history API call allows you to optionally set a start and end date, page number and number of items on the page.

 
Get your topup history

public function init():void
{
  var api:MobileVikings = new MobileVikings("username","password");
  api.getTopupHistory();
  api.addEventListener(MobileVikings.TOPUP_HISTORY_LOADED, topupLoaded);
  api.addEventListener(MobileVikings.TOPUP_HISTORY_FAILED, topupFailed);
}
private function topupLoaded(evt:TopupHistoryEvent):void
{
  trace(evt.topupHistory);
}

private function topupFailed(evt:Event):void
{
  trace("fail");
}

The topup history API call allows you to optionally set a start and end date, page number and number of items on the page.

 
This is still an early version and not extensively tested yet but from what I can see it behaves quite well. For some reason specifying the from date for the history API calls takes a really long time to get results back, which I believe is a problem at their end.

Download the source files or the SWC here.

 
Hope you enjoy, let me know if you run into any issues!
 

Posted
AuthorPeter
CategoriesActionScript