Launch and Iterate: Parse Data Migrations

Every developer knows: Shipping is just the start. After your app has launched, you’ll still have new features you want to add. Sometimes making these updates requires updating or transforming existing data stored in the cloud. For example, you may have read Brad’s excellent post about how to make your text searchable and asked yourself, “How do I update all of my existing data?”.

You’ve always been able to do so with our powerful REST API. But we’ve recently launched a couple of features that will make it even easier to process your data, using JavaScript running in Node.js. The Parse JavaScript SDK is available through npm, so getting started is as easy as running:

npm install parse

Remember, there are active clients out there constantly creating new data. So before you start updating existing data, you’ll probably want to add a beforeSave handler to process the new data as it comes in. Since this is all JavaScript, you can use the same code for your beforeSave handler that you do in your data migration script.

Then, you will need to iterate over all of the existing objects in your collection to update them. The new each method on Parse.Query objects allows you to do just that. Even if you have tens of thousands of objects or more in a collection, it will return each one of them, giving you an opportunity to modify them as you see fit.

We’ve also added the Parse.Cloud.useMasterKey() method to our node module. By supplying your master key and calling this method, you can transform objects belonging to all of your users without ever compromising their ACL-based security.

For example, if you have Event objects and want to transform their city field into a searchable text field called cityTokens, you could run the following node script:

var _ = require("underscore");
var Parse = require("parse").Parse;

Parse.initialize("YOUR APP ID", "YOUR JAVASCRIPT KEY", "YOUR MASTER KEY");

Parse.Cloud.useMasterKey();

var tokenize = function(str) {
  var words = str.toLowerCase().split(/\b/);
  words = _.filter(words, function(w) { return w.match(/^\w+$/); });
  return words;
};

var query = new Parse.Query("Event");
query.doesNotExist("cityTokens");

return query.each(function(event) {
  console.log("Updating object: " + event.id);
  event.set("cityTokens", tokenize(event.get("city")));
  return event.save();
});

Then just run this script on your machine with node:

$ node migrate.js 
Updating object: 4JsHZTwVBS
Updating object: MnZ4TzBDFT
Updating object: OPndkI2iRk
Updating object: WBuxcx3fHM
Updating object: duyWWKKxu3
Updating object: jPGxPhjjvg
...

At Parse, we love seeing all of the great new features our developers are adding to their apps. These new additions to our API should help you launch them even faster!

Bryan Klimt
May 13, 2013

New Features in the Data Browser

Parse users love to store rich relational data on our backend. Today, we are releasing a number of features that will delight our users who make use of the relations.

The first change is that you can now create, update and delete relations in the data browser. For example, to model the “Like” relationship between “Comment” and “User”, developers can create a relation called “Likes” on the “Comment” class, and add the users that like the comment to the relation, all within the data browser.

relations

Second, one-to-many relationships are now links in the data browser, and clicking on the links will take you to the objects they point to. For example, you can click on the “author” link in the Post class to find out who wrote the post:

Screen Shot 2013-04-26 at 1.48.27 PM

The third feature allows you to delete the data in a field. In the past, to indicate that the data has been removed, developers have been making their fields null or empty, but what they really want is to completely delete the data. Now, this can be done. All you need to do is to right click on the data you would like to modify, and choose ‘delete value’ on the dropdown.

Screen Shot 2013-04-26 at 12.34.59 PM

We hope you like this set of features!

Andrew Wang
April 26, 2013

AnyYolk: A Parse-Powered HTML5 Game

It’s been truly amazing to see the tremendous breadth of apps that have been built on Parse. These talented developers have used our platform for everything from utility apps, to social networks, to games. But creating great apps is not without its trials. It requires weeks of research, hard work, and constant learning. At Parse we strive to make this process as easy as possible, not only with our powerful platform but also with in-depth sample apps and tutorials.

Today we are releasing AnyYolk, the newest member of our sample app family. AnyYolk is a web based game built using cutting edge HTML5 technologies. It’s built on top of Backbone.js, the same framework behind the Parse JavaScript SDK, does all of its animations using CSS3, and has a Parse powered backend to manage highscores.

We’ll keep updating AnyYolk with a bunch of cool gaming related features, so keep an eye out for future updates! You can find the source code on GitHub and play with a live version of the game at www.anyyolk.com (or right below).

We hosted a live tutorial on how to build AnyYolk using Parse, Backbone.js, and HTML5, which you can find the full re-cap for here.

Mattieu Gamache-Asselin
April 25, 2013

Rapid Cloud Code Development with Parse Develop

In the past month, we’ve made several improvements to the parse command line tool to speed up the Cloud Code development process.

The biggest improvement is the new develop command that will monitor your project for any changes and automatically upload them to the Parse Cloud. The develop command will also stream log messages to the console as they show up in the Parse log. Running develop is as simple as:

$ parse develop MyDevelopmentApp
E2013-03-19:20:17:01.423Z] beforeSave handler in release 'v1' ran for GameScore with the input:
  {"original": null, "update":{"score": 1337}}
 and failed validation with Each GameScore must have a playerName
New release is named v58
I2013-03-19T20:17:10.343Z] Deployed v58 with triggers:
  GameScore:
    before_save

Many developers have one Parse app they use for developing new code and one Parse app to run their production code. To avoid accidentally running develop on a production app, the command line tool requires the app to be explicitly passed as an argument for develop.

We also improved deploys for projects with many cloud code files or people developing on slow connections by only uploading diffs.

And finally, we added a -f option to the tail command. This will stream log messages to your console as they appear in the Parse log, much like develop does.

With these improvements, Cloud Code development should be faster and more fun! For more information on develop, read the Development vs. Production section of the Cloud Code Guide.

Shyam Jayaraman
April 15, 2013

Register for the Webcast: Building Games with the Parse JavaScript SDK

Parse JavaScript SDK

A few weeks ago, we attended both GDC and HTML5 Developer Conference. After hanging out with a great group of game developers at GDC, Mattieu Gamache-Asselin gave an amazing talk and live demo at HTML5 Developer Conference about how to build web games with the Parse JavaScript SDK.

We’re excited to invite you to a webcast with Parse Software Engineer, Mattieu Gamache-Asselin, covering the following topics:

  • How to create web apps with Backbone.js
  • Best practices of Backbone.js
  • How the Parse SDK works with Backbone.js
  • Live example of adding a highscore to a Backbone.js game
  • How you can use Cloud Code to add server-side functionality to your Parse app

 

Find the re-cap of “Building Games with the Parse JavaScript SDK” from May 1, 2013 here.

Ashley Smith
April 11, 2013

Webcast Recap: All About Parse Push Notifications

Thanks to everyone who attended today’s webcast, “All About Parse Push Notifications,” with Scott Smith, Senior Account Executive at Parse, and Héctor Ramos, Solutions Architect at Parse. For anyone who would like a second look or just in case you missed it, the full video is below. We’ve also uploaded the slides to Slideshare.

Webcast Agenda:

  • What are push notifications?
  • What are some interesting ways successful applications are using push notifications?
  • Demo: Parse Push Console
  • Demo: Parse Analytics
  • Live Code Demo: Integrating push notifications into your iOS app

Watch the recording:

Ashley Smith
April 10, 2013

Six Creative Ways to Use Push Notification Marketing in Your Mobile App

Parse Push

Push notifications are quickly becoming one of the top ways to keep users engaged with mobile applications. Some research has shown that the average lifespan of an app can be as short as 30 days, and push notifications are one tool to help developers extend that expiration date and keep their users coming back for more.

We’ve already given you some tips on how to use push notifications effectively but with the launch of our awesome Push Analytics tool, we wanted to give you even more ideas on how to implement Push into your app effectively if you haven’t already, or if you’re looking for a fresh way to incorporate notifications.


Reminders

It never hurts to remind your users why they downloaded your app in the first place. Some apps are even designed specifically to provide reminders, which is a perfect application of push notifications.

  • App-Specific Reminders. If a user hasn’t completed an expected action yet, the app can send a welcome reminder to complete it. An example of this might be a food diary app that sends push reminders to users who haven’t tracked an expected meal yet that they need to do so for the day.

  • Event Reminders. Parse-powered app Applauze enables users to sign up for both free and paid events in their area. The app then sends users push notifications to remind them of the events that they have registered for.

  • Play Reminders. Games, such as MyDinos, send reminders to come back to the game when it hasn’t been opened in a while. Social games also send notifications when it’s a user’s turn in the game.

  • IRL Reminders. Professional sports apps can send a notification every time a game is about to end. This allows a fan of the winning/losing team to catch the end of the game if she or he wasn’t already aware it was happening.

  • Prescription/Appointment Reminders. The Walgreens app sends prescription alerts to remind users that it’s time to re-order, or to notify users that prescriptions set up on auto-refill are ready to be picked up.

 

TOMS App

Traffic Drivers

One of the biggest reasons that developers add Push to their apps is to drive traffic to, or back to, the app. Some inspiration of innovative ways to drive traffic to your app include: 

  • Sweepstakes or Contest Pushes. The Parse-powered TOMS shoes app recently did a contest connected to their charitable endeavors. Not only does this promote one aspect of their mission, it also drives users to visit the app, which incorporates the opportunity to purchase shoes and thus drive business.

  • Cross-Promote Your Apps. If you create apps with similar themes or purposes, games for example, sending push notifications that send users from an app they’ve already downloaded to a similar app is a great way to drive existing users to new apps.

  • Apps IRL. The Green Bay Packers app incorporates geo-locating for bars that are playing the current game in the customer’s area. For products or businesses that have a “real-life” component, push notifications can lead users to the brick-and-mortar presence of the brand.

  • Flash or Last-Minute Sales. The Southwest Airlines app sends “Ding Alerts,” which are push notifications for last minute flight deals.  This not only drives users to the app, it can also drive sales!

 

Emergency Alerts

More and more apps are emerging related to sensitive material, from email and banking all the way to new home security and garage system apps. It’s important for these apps to get a user’s attention quickly in case of an emergency, and Push notifications are a great way to do that.

  • Safety IRL Alerts. Garage door and alarm system apps can send users push notifications for doors and windows that are being opened when the system is alarmed, or notify the user of existing open windows and doors when remotely arming the system.

  • Suspicious Activity Alerts. Banking and email apps can send users a push notification to alert them of suspicious activity occurring on their accounts.

  • Natural Disaster Alerts. The Parse-powered QuakeList app uses geo locational push notifications to alert users of events in their area or in their selected areas that they request notifications about.

  • Public Transportation Alerts. The Embark apps notify users if a train is running late and of delays they should be aware of during their trip or commute.

 

GymPact

App Functionality

Some apps rely on push notifications to support the app’s main functionality, whether for a messaging system or a picture feed. Being notified of new content is a crucial part of why users download the app in the first place, and push notifications are a key way to get their attention.

  • Critical Reminders. GymPact, wherein users agree to be charged if they haven’t completed a certain number of workouts each week, reminds users if they haven’t done their workout and and are about to be charged.

  • Message Notifications. Many apps, including Parse-powered InstaDM and Applauze send messages to their users when another user sends them a message or comments on their event or image.

 

App Updates

Keeping an app updated with fresh content is a great way to keep the app relevant to the user and extend that shelf-life even further. Some updates may be free, but others might require the user to purchase the new content or features. Push notifications are a great way to market updates, both those that are free-but-exciting as well as those that require a little more investment from the user.

  • Opt Customers into New Features. Retail apps can send push notifications to opt in customers to the brands they are interested in, or to notify them of sales on their preferred brands.

  • Paid Feature or Update Notifications. When an app releases a new paid feature or update, a push notification is one way to notify existing users of the opportunity to purchase. This is also great for games that release new packs.

 

Innovations

As push notifications become more commonplace, finding fresh ways to implement them will become more an more important. Here are some innovative ideas for using Push in your apps that might make your app stand out from the crowd.

  • App Refresh. You can program your app to send a push notification with no text, which will have the app refresh itself without the user necessarily noticing that it’s happening.

  • Automated Segmented Push. You can use Parse’s Cloud Code to set up automated segmented push notifications to target just specific portions of your audience based on demographics or interests.

  • Geolocational Push. Apps for brick-and-mortar retailers and restaurants can program apps to send push notifications to users that are in the area and notify them of specials, coupons, or just that they’re within reach of something tasty or interesting.

  • Push Analytics. You can use Parse’s Push Analytics feature to monitor app opens, push campaign effectiveness, and more.

PushGraphSample

 

Courtney
April 9, 2013

HTML5 vs. Native When Using a Backend as a Service

Earlier this month, Parse sponsored and presented two talks at HTML5 Developer Conference in San Francisco at The Palace Hotel. We really enjoyed interacting with a few thousand members of the HTML5 community and were proud that both of our talks were positively received. One of these talks, by Parse engineer Bryan Klimt, took an in-depth look at the benefits and challenges of HTML5 versus Native when using a backend as a service, like Parse.

See the full video below or take a look at a PDF of the slides and script.

 

On Wednesday, May 1st we’ll be giving a live screencast of Parse engineer Mattieu Gamache-Asselin’s talk from HTML5 Developer Conference. Register here to see how easy it is to build a desktop game with the Parse JavaScript SDK.

Ashley Smith
April 8, 2013

Sending Bytes from Cloud Code

Many of you asked for a way to make HTTP requests from Cloud Code that send/receive raw bytes instead of just text-based data. For example, you might want to generate some binary data in Cloud Code, and then send that to a third-party web API. We’ve just implemented this functionality in the Cloud Code HTTP API.

To send raw bytes, you simply set the httpRequest body to a Buffer object containing the bytes, and set the Content-Type header to whatever your bytes represent. To receive raw bytes, you can access the Buffer object at httpResponse.buffer when the HTTP request succeeds.

In this blog post, I’ll show two examples: one for sending bytes, and one for receiving bytes.

First, let’s try sending some bytes. I’ll create a Buffer object containing the UTF-8 bytes for the smiley character. Then, I will make a Parse File from this Buffer object by sending the raw bytes to the Parse REST API.

var Buffer = require('buffer').Buffer;
Parse.Cloud.define("smileyFile", function(request, response) {
  var contentBuffer = new Buffer([226, 152, 186]); // UTF-8 bytes for smiley
  Parse.Cloud.httpRequest({
    url: 'https://api.parse.com/1/files/smiley.txt',
    method: 'POST',
    headers: {
      'X-Parse-Application-Id': '<YOUR_APPLICATION_ID>',
      'X-Parse-REST-API-Key': '<YOUR_REST_API_KEY>',
      'Content-Type': 'text/html; charset=utf-8'
    },
    body: contentBuffer,
    success: function(httpResponse) {
      response.success(httpResponse.data); // Return Parse File info
    },
    error: function(httpResponse) {
      response.error('Failed with: ' + httpResponse.status);
    }
  });
});

Calling the above Cloud Function will produce the following JSON:

{ 
  "result": { 
    "url": "http://files.parse.com/<SOME_HASH>/<SOME_OTHER_HASH>-smiley.txt"
    "name": "<SOME_OTHER_HASH>-smiley.txt" 
  }
}

Since Parse Files can contain any data, you are not limited to text content. You could easily modify the above code to create a Parse File containing an image created in Cloud Code.

In the second example, let’s try receiving some raw bytes. I will download an image from somewhere on the web, and return its corresponding Base64 string from the Cloud Function. The code looks like:

// Call this function with JSON input: { "url": "<IMAGE_URL>" }
Parse.Cloud.define('base64EncodeImage', function(request, response) {
  Parse.Cloud.httpRequest({
    url: request.params.url,
    method: 'GET',
    success: function(httpResponse) {
      var imageBuffer = httpResponse.buffer;
      response.success(imageBuffer.toString('base64'));
    },
    error: function(httpResponse) {
      response.error('Error getting image');
    }
  });
});

Calling this Cloud Function with an image URL will produce the following JSON:

{ "result": "<BASE64_ENCODED_STRING_OF_IMAGE>" }

Try it out and let us know what you think!

Stanley Wang
April 4, 2013

Stay Classy, Objective-C: Introducing Native Subclasses for Parse Objects

Thank you Developer! But our Business Logic is in Another Class

You wake up in a strange land. Somebody has stolen the princess and the town is looking to you to save her. Why don’t the townsfolk build their own army and fight the wizard themselves? Apparently they’re busy. For years, these townsfolk have perfected the art of Business Objects. They create two classes for every concept: one class contains business logic and the other is a SAX parser or some other delegate to manage storage and retrieval. These townsfolk aren’t warriors, they’re artisans. Each project requires new brilliant innovations in data mappings, and this has left them too busy to save the beloved princess.

“I need a weapon,” you say to yourself. Luckily, Parse has just the tool for you.

It’s Dangerous To Go Alone! Take This

Objective-C is a dynamic language, and dynamic languages offer interesting possibilities. Today we are releasing support for native subclasses in Objective-C. With proper subclassing, your PFObjects are your business objects. Your subclasses can have the properties and methods that are unique to a particular business function. Your code becomes terser, easier to read, and supports autocomplete in Xcode. Imagine turning the following code:

PFObject *shield = [PFObject objectWithClassName:@"Armor"];
[shield setObject:@"Wooden Shield" forKey:@"displayName"];
[shield setObject:[NSNumber numberWithBool:NO] forKey:@"fireproof"];
[object setObject:[NSNumber numberWithInt:50] forKey:@"rupees"];

into this:

Armor *shield = [Armor object];
shield.displayName = @"Wooden Shield";
shield.fireproof = NO;
shield.rupees = 50;

It’s Super Effective!

It’s easy to set up PFObject subclasses, and it greatly simplifies app development. There are built-in helpers for creating and querying for objects. You can better encapsulate logic for a particular class by adding custom properties and methods. Consider the complete implementation of the armor class:

Armor.h

@interface Armor : PFObject<PFSubclassing>
+ (NSString *)parseClassName;
@property (retain) NSString *displayName;
@property int rupees;
@property BOOL fireproof;
@end

Armor.m

#import "Armor.h"
#import <Parse/PFObject+Subclass.h>

@implementation Armor 
@dynamic displayName;
@dynamic rupees;
@dynamic fireproof;
+ (NSString *)parseClassName {
  return @"Armor";
}
@end

We can now create objects using [Armor object] and query for Armor objects with [Armor query]. The definition of parseClassName ensures that [PFObject objectWithClassName:@"Armor"] will create an Armor object. PFObject supports dynamic synthesizers; anArmor.displayName is now equivalent to [anArmor objectForKey:@"displayName"] but is terser, supports code complete, and is a compiler error when mistyped. As an NSString, we can even declare displayName to be a copy property as well.

The rupees and fireproof properties here are extra special: PFObjects require object members, but the rupees property is an int and fireproof is a BOOL. PFObject properties support unboxing. [anArmor objectForKey:@"fireproof"] returns an NSNumber with a boolValue, but setting the fireproof property automatically wraps the BOOL in an NSNumber, and getting the fireproof property automatically extracts the boolValue from the NSNumber.

(Nearly) All Your Implementation Are Belong To Base Class

This change is made possible through great new features in PFObject which enable subclassing. To keep code clean, the methods which only make sense in subclasses (e.g. initializers without a class name) are exposed in the new PFSubclassing protocol. Everything but the name of the class you want to implement are already implemented in the PFObject Subclass category, so setup is simple. Read more about our setup in the iOS/OS X guide.

Good luck saving the princess!

Thomas Bouldin
March 22, 2013