How to write Cloud Functions and libraries

cloud functions documentation and libraries

In our last blog post, we told you about the late nights spent developing our Cloud Functions.

Today, we are proud (albeit sleep-deprived) to announce another significant update.

The revised documentation section covering everything Cloud Function now includes the basics of writing Cloud Functions, predefined methods to make tasks easier and partners integration.

While reading the documentation you will discover a few new things about Cloud Functions. For example, as part of the standard library of methods, you will now have the ability to “include” Cloud Functions from each other. Why does this matter? It means you can move all common business logic (used throughout your Cloud Functions) into a separate Cloud Function in the form of PHP function declarations.

Boom! You’ve effectively created a Library Cloud Function. Once your library is ready you can include it from other functions using our include_cloudfunction() method.

For example imagine declaring a Cloud Function called “my-app-library”

A second Cloud Function, called directly by the app, can gain access to the methods declared in our first library simply by including it.

We have created a few more standard methods to give you access to the user and device information for example. With your feedback and ideas we hope to keep building this library of standard methods available to Cloud Functions.

Posted in Announcements, Development | Tagged , , , , , , , | Leave a comment

Track your Cloud Functions over time

Cloud Functions change. Which is why we have Cloud Functions on cloudbase.io in the first place. With all your business logic outside of the application and in the cloud, updating and re-publishing your app is a far less frequent chore.

We’ve fine-tuned, redesigned and optimized our Cloud Functions to make execution considerably faster, so that’s what’s going on in case you noticed, we have also fiddled with the user interface in the management console.

The page to create Cloud Functions has changed slightly… Now, cloudbase.io will automatically keep track of changes you have made to Cloud Functions over time. Plus, a new history page shows you the full source and differences between the various revisions of your function. So you can rollback to an older version at any point!

cloud functions history rollback

If cloudbase.io has multiple versions for one of your Cloud Functions a new button will appear alongside the “save” button to access the history page.

This is just the first of a number of improvements we’ll be rolling out in the next few weeks.

As always, we welcome your feedback and suggestions. Get in touch and help create a cloudbase.io platform that works for you.

Posted in Announcements, Development | Tagged , , , , , , , | Leave a comment

Real time Cloud Database with PubNub

We have strengthened the integration between our Cloud Database functionality and the real time messaging system built by our friends at PubNub.

Now, cloudbase.io can automatically push a message to a PubNub channel whenever a new document is inserted, or an existing document is updated in a collection in your Cloud Database.

Enable this functionality by saving your PubNub Publish and Subscription keys in the Other APIs page of the application settings in the management console.

Once you have saved these details you will be able to enable PubNub notifications on each collection in your Cloud Database individually. Messages for each collection can be pushed to a different channel. The field is provided in the collection settings of the management console.

cloud database collection pubnub settings

The notification message pushed to the channel will have the following structure.

To push more complex messages or perform a custom action you can always use a Cloud Function as a trigger on your Cloud Database.

The same data sent automatically to the PubNub channel is also available in the $params variable to Cloud Functions executed as trigger. We published a blog post explaining how to use the PubNub PHP library from your Cloud Functions a while ago. Putting the two together allows for notifications to different channels or custom business logic before pushing the message out.

Posted in Announcements, Development | Tagged , , , , , , , , , | 6 Comments

Is Java the king of mobile?

Cloudbase.io Java Client LibraryNot too long ago Andrew Binstock published an interesting article on Dr. Dobbs – If Java Is Dying, It Sure Looks Awfully Healthy.

Despite all of the rumours surrounding the decline of the language the Java eco system is growing from strength to strength. As Android’s popularity grows so does Java’s, it’s native development language. Android is only the tip of the iceberg. According to Java’s website 31 times more Java phones ship every year than Apple and Android combined.

The good health of the ecosystem is even more evident if we look at the JVM. This, too, has continued to advance with each major release of the language. The addition of the new bytecodes, including invokedynamic, in Java 7 demonstrated how well the JVM works. When the JVM implementation of Ruby, JRuby, added native support for this instruction, its performance zoomed past the C-based Ruby VM, which for years has been the Ruby reference platform

We have released on our GitHub account a Java client library for cloudbase.io. Based on a fork of the Android client library this helper class is meant to be used with both servers products and embedded devices. All of the API methods match the Android implementation. The only difference between the two classes is the initialization code.

The Java client library expects a CBDeviceInfo object populated with the device information. By default this object will read the language and country from the default Locale of the system and use the MAC address of the local network card as a unique identifier.

Follow the Android documentation to start using the Cloud Database, Cloud Functions and all the other cloudbase.io functionality.

Posted in Announcements, Development | Tagged , , , , , , , , , | Leave a comment

Multithreading with Xamarin

Xamarin support for cloudbase.ioThe Xamarin client library – like all other cloudbase.io helper classes – executes HTTP calls to the REST API in the background, on a separate thread, then calls back the application using a delegate.

The delegate is executed on the new thread started for the HTTP call, because of this it won’t be able to make changes to the application UI directly. This is because you may need to perform some additional operations on the data returned by the API call without blocking the app’s main thread.

Xamarin provides a simple method to execute code on the main UI thread, effectively returning from the HTTP thread. From an iOS application the NSObject class contains a method called InvokeOnMainThread, which receives a delegate and can be used to make changes to the UI; in Android the Activity class contains a similar RunOnUiThread method.

To get started simply register for a cloudbase.io account and download our client library from GitHub or the Xamarin component store.

Posted in Development, Tutorial | Tagged , , , , , , , | 2 Comments

Cloudbase.io at IP EXPO in London

Cloudbase.io will be at IP Expo in London with IBMOn the 16th and 17th of this month we will be at IP EXPO, at Earls Court in London as an IBM MSP.

IP EXPO is the UK’s Number ONE Enterprise IT event, bringing you everything you need to know about IT under one roof. This year’s sponsors include Amazon AWS, Cisco, Citrix, HP, IBM, Oracle, Microsoft and many others. Get in touch to discover our enterprise solutions and see where our mobile backend as a service solution is heading.

The Mobile Apps that have the most business benefit are those that have full integration with key applications and databases.While you build your Apps, cloudbase.io becomes your backend team.

You can launch apps in minutes without ever worrying about server management. We maintain and scale your backend infrastructure including push notifications, database management and analytics. you can choose to use our private cloud or Enterprise version which sits behind your own firewall.

Our collection of open source client libraries allow your new app to integrate with our backend and middleware solutions with just a few lines of code.

Posted in Announcements, Events | Tagged , , , , , | Leave a comment

Free text search in aggregation commands

cloud database free text searchA question we get asked a lot is how to use the match aggregation command to perform text searches on a collection. As you can see from our REST API documentation, you can use regular expressions when searching your collections. You can do exactly the same with the match aggregation command.

To use the same example we have in the iOS documentation, assume we have a collection containing prices for a number of stocks and we want to extract the average price for all symbols beginning with “A”.

Using a regular expression in searches and aggregation matches is exactly the same as Equal string search. The value you are searching for will have to be contained within the standard regex container: /value/. To search for all stocks beginning with “A” we will use /A.*/. You regular expression will be processed by a PCRE (Perl compatible regular expression) engine.

/ Open regular expression
A Literal letter A
. Followed by any character
* Repeated any number of times
/ Close regular expression

The source code for our aggregation in Objective C would look like this

You will also notice we have put the match condition as the first element in the array of aggregate commands. This is because putting the search condition first will allow the cloud database to use the indexes in your collections, making the execution of your command considerably faster.

Aggregation commands are executed in a pipeline each processing the output of the previous command. Once the first command is executed the system will start working with a virtual, temporary output, therefore indexes will no longer be available to the following commands.

Posted in Development, Tutorial | Tagged , , , , , , | Leave a comment

Building mobile apps with Xamarin? We are working for you

Xamarin support for cloudbase.ioRecently we have done quite a bit of work with C# and Mono. Just last week we released the first version of our client library for Unity 3d. The next obvious step was to work on Xamarin support.

We have published the Xamarin client library on GitHub under the Apache 2 license.

While the structure of the library is fundamentally the same as the Unity and Windows Phone ones there is a difference in how we gather device information to register the client with the cloudbase.io API. The CBHelper solution contains three projects:

  • CBHelper-Xamarin: The actual client library.
  • CBHelper-Xamarin-Android: An Android specific library.
  • CBHelper-Xamarin-iOS: An iOS specific library.

The main CBHelper project defines a class called CBDeviceInfo. This is an empty container declaring the variables necessary for the device to be registered with cloudbase.io. The Android and iOS projects contain only one class, an implementation of the CBDeviceInfo class called AndroidDeviceInfo and iOSDeviceInfo. These two projects use the platform specific classes to extract information about the manufacturer, versions and IDs through the MonoTouch and Android frameworks for Mono.

The client library works in exactly the same way as the Windows Phone client library. The only difference is in the constructor of the CBHelper object which expects an additional parameter in the form of a CBDeviceInfo object.

The Xamarin developer’s community is growing very fast and we have received numerous requests to add Xamarin support to our extensive collection of client libraries. We look forward to your feedback as we keep developing the system and extending our support for the Xamarin SDK.

Posted in Announcements, Development | Tagged , , , , , , | 1 Comment

The Cloud Database for Unity 3d

The Cloud Database for Unity 3dRecently we have received a lot of requests for features and support from game developers. We now have hundreds of mobile games using our platform to store and retrieve savegames, top scores and in-game items. Our Cloud Database is the right tool for the job. Alongside our partners at PubNub we are the complete cloud solution for your mobile game.

Today we are taking one more step in supporting game developers by introducing the cloudbase.io client library for Unity 3d. Like all other client libraries it is an open source project, released un the Apache 2 license, available on our GitHub account.

The C# Mono class is a port of the existing Windows Phone client library and uses the Unity 3d WWW and WWWForm objects to call our REST APIs. To serialize objects and parse json responses we have used the port to Unity of the JsonFX library by Aron Granberg.

The solution compiles to a DLL that can be included in any Unity 3d project. The CBHelper project requires a reference to the UnityEngine.dll library. This can be found under your Unity installation folder.

To utilize the StartCoroutine method of MonoBehaviour for asynchronous HTTP calls the library uses a Dispatcher singleton class implementing MonoBehaviour attached to an empty GameObject.

All of the API calls are available exactly as described in the Windows Phone Documentation pages. Getting started and making the first API calls after you have registered and created an application is incredibly simple.

 

Posted in Announcements, Development | Tagged , , , , , , , , , , , | 1 Comment

Using Cloud Functions to send Push Notifications

php cloud function push notificationsCloudbase.io can send push notifications to all of the major mobile platforms. iOS, Android, Windows Phone 8, Windows 8 and BlackBerry 10. Each client library includes a method to send a push notification to its network.

Cloud Functions are at the core of most of the mobile apps on cloudbase.io – sometimes they are used as triggers on a collection in the Cloud Database, scheduled to perform some maintenance tasks or called directly from the mobile app to manipulate data before it is saved or returned.

Given the pivotal role Cloud Functions play in most apps it is important to be able to send Push Notifications to your app’s client devices during the execution.

From a Cloud Function you have access to the PHP CBHelper library – This allows a function to call the Push Notification API at any moment.

You could, for example, use the Cloud Database to track the last login of a user in you application. Then schedule a Cloud Function that looks up the data of the last login and sends a notification to the user if they haven’t logged in for longer than 24 hours.

Here’s a simple example.

Push Notifications are a fantastic tool to engage your users and remind them of your application. Hopefully this example was helpful. Get coding.

Posted in Development, Tutorial | Tagged , , , , , , , , , , | Leave a comment