This Sandbox documents and executes RESTful Network API calls. It can be used to test and does not involve a live network.
To use it, select a function to test from the buttons above. Then either execute the HTTP requests documented in the sections via your preferred coding tool (including browser or curl);
or download the jQuery plugin and jQuery to follow the jQuery examples.
For in-app billing direct from a browser, Web app or native app. Uses the jQuery
plugin to create the charge, and access the response transaction object to determine the transaction status.
var billableItem =
{"address":"acr:12345", // Mandatory, string - user MSISDN or ACR
"amount":"0.70",// Mandatory, currency - amount to charge
"referenceCode":"myRef",// Mandatory, string - your own transaction reference
"contentName":"Supergame level 2",//optional, string - readable title of content
"description":"New level",}// optional, string - readable description of content
Now you can charge the item to the user's bill:
var myCharge = new $.fn.oneapi.charge(billableItem);
...and you will have a handle on the transaction status and ID. That's it - done!
Query a user's location by passing their MSISDN or ACR, plus a name label, to the location function.
var userLoc = new $.fn.oneapi.location("12345", "Me");
Further users can be located the same way, make sure to give each a name:
var elvis = new $.fn.oneapi.location("23456", "Elvis");
var jerrylee = new $.fn.oneapi.location("34567", "Jerry Lee");
var johnny = new $.fn.oneapi.location("45678", "Johnny");
You now have a handle on each located user's name, longitude and latitude
via the object properties. For example, you can use these to initialise a Google Map showing the user's location
relative to other friends, and the pubs nearest to them all.The map is a good example of a Network APIs mashup with Web APIs - and if the service was launched from
a smartphone, the primary user's location could be obtained from device GPS.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Location test</title>
<!--
Place <a href="img/img.zip">these images for friends and pubs in an img folder relative to the HTML page.
You will also need a Google Maps API key, see code.google.com for details
-->
<meta charset="utf-8">
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript" src="jquery.oneapi.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_KEY&libraries=geometry,places&sensor=false"></script>
<script type="text/javascript">
// This block draws the Google Map
var map;
var service;
var latlng;
function initialize(lat,lng,name) {
// Create the initial map based on the initiator's location
latlng = new google.maps.LatLng(lat, lng);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
createMarker(latlng,name, "img/me.png");
setPubMarkers();
}
function setPubMarkers(){ // shows all the pubs near our friends
var request = {
location: latlng,
radius: '500',
types: ['bar']
};
service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var pubLoc = results[i].geometry.location;
var pubName = results[i].name;
createMarker(pubLoc, pubName, "img/pint.png"); // show a pint glass at each pub
}
}
}
function createMarker(location, name, image) {
marker = new google.maps.Marker({
position: location,
map: map,
title: name,
icon: image
});
}
</script>
</head>
<body>
<div id="map_canvas"></canvas>
<script type="text/javascript">
// This block locates a user and his friends, then initialises a Google map showing them all
$(document).ready(function(){
var primeUser = new $.fn.oneapi.location("12345", "Me");
var elvis = new $.fn.oneapi.location("23456", "Elvis");
var jerrylee = new $.fn.oneapi.location("34567", "Jerry Lee");
var johnny = new $.fn.oneapi.location("45678", "Johnny");
// create the map with the end user in the centre
initialize(primeUser.latitude,primeUser.longitude, primeUser.name);
var elvisLatLng = new google.maps.LatLng(elvis.latitude,elvis.longitude);
var jerryleeLatLng = new google.maps.LatLng(jerrylee.latitude,jerrylee.longitude);
var johnnyLatLng = new google.maps.LatLng(johnny.latitude,johnny.longitude);
createMarker(elvisLatLng, elvis.name, "img/friend.png");
createMarker(jerryleeLatLng, jerrylee.name, "img/friend.png");
createMarker(johnnyLatLng, johnny.name, "img/friend.png");
})
</script>
</body>
</html>
Other libraries need to bind to the following HTTP POST and JSON payload -
GET http://netapi.heroku.com/v2/location/queries/location?address=acr:12345&requestedAccuracy=10
...and get the following JSON. You can change the address (the phone number), but the location will always return as London for this sandbox.
Send an SMS from your web application to one or more end users.
var mySMS = $.fn.oneapi.sms('myphonenumber', 'targetphonenumber', 'Hello world');
The initial response will populate the messageURL value of the pointer. This allows you to query the SMS status:
var status = $.fn.oneapi.sms.status(mySMS.messageURL);/*
Status values returned will be one of:
DeliveredToTerminal
DeliveryUncertain
DeliveryImpossible (try again)
MessageWaiting (queued for delivery)
DeliveredToNetwork
*/
Other libraries need to bind to the following HTTP POST and JSON payload -
POST http://netapi.heroku.com/v2/smsmessaging/outbound/{ACR or MSISDN/requests
Accept: application/json
Host: netapi.heroku.com
Content-Type: application/x-www-form-urlencoded
address=tel%3A%2B13500000991&
address=tel%3A %2B13500000992&
senderAddress=tel:%2B12345678&
message=Hello%20World&
notifyURL=http://application.example.com/notifications/
DeliveryInfoNotification&
callbackData=some-data-useful-to-the-requester&
senderName=ACME%20Inc.
...and parse the following JSON response detailing the transaction.