Parse

 Parse

An overview on how to use Parse to build your mobile app's backend.

700c1db9f2cce6b3cd626c0eb9fc9b34?s=128

Gustavo Barbosa

April 17, 2013
Tweet

Transcript

  1. 1.
  2. 2.
  3. 5.
  4. 7.
  5. 12.

    // Cria um post ParseObject myPost = new ParseObject("Post"); myPost.put("title",

    "Estou com fome!"); myPost.put("content", "Vamos almoçar aonde?"); // Cria um comentário ParseObject myComment = new ParseObject("Comment"); myComment.put("content", "Vamos no Estação."); myComment.put("parent", myPost); myComment.saveInBackground(); objetos com relacionamento
  6. 13.

    ParseQuery query = new ParseQuery("Profile"); query.whereEqualTo("age", 45); query.findInBackground(new FindCallback() {

    public void done(List<ParseObject> profileList, ParseException e) { if (e == null) { Log.d("profile", "Retrieved " + profileList.size() + " profiles"); } else { Log.d("profile", "Error: " + e.getMessage()); } } }); int age = profile.getInt("age"); String name = profile.getString("name"); buscando objetos
  7. 14.

    ParseObject profile = new ParseObject("Profile"); profile.put("age", 27); profile.put("name", "Mary Moe");

    profile.saveEventually(); Salve quando puder! profile.increment("age"); profile.saveInBackground(); profile.deleteInBackground(); profile.remove("name"); profile.saveInBackground(); outras funções úteis
  8. 19.

    // Salva a instalação no Parse. ParseInstallation.getCurrentInstallation().saveInBackground(); // Adiciona o

    usuário no canal “Giants”. PushService.subscribe(context, "Giants", YourActivity.class); adicionando a um canal de envio
  9. 20.
  10. 21.

    ParsePush push = new ParsePush(); push.setChannel("Giants"); push.setMessage("Touchdown para os Giants!

    O time vira contra os Mets."); push.sendInBackground(); via código
  11. 24.
  12. 26.

    ParseFacebookUtils.initialize("ID DA APP DO FACEBOOK"); @Override protected void onActivityResult(int requestCode,

    int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data); } facebook connect
  13. 27.

    ParseFacebookUtils.logIn(this, new LogInCallback() { @Override public void done(ParseUser user, ParseException

    err) { if (user == null) { Log.d("MeuApp", "Ops. O usuário cancelou o login do Facebook."); } else if (user.isNew()) { Log.d("MeuApp", "Usuário criado e logado via Facebook!"); } else { Log.d("MeuApp", "Usuário logado via Facebook!"); } } }); if (!ParseFacebookUtils.isLinked(user)) { ParseFacebookUtils.link(user, this, new SaveCallback() { @Override public void done(ParseException ex) { if (ParseFacebookUtils.isLinked(user)) { Log.d("MeuApp", "Boa! Usuário conectou sua conta do Facebook!"); } } }); } SSO LINK
  14. 29.

    ParseTwitterUtils.logIn(this, new LogInCallback() { @Override public void done(ParseUser user, ParseException

    err) { if (user == null) { Log.d("MeuApp", "Ops. O usuário cancelou o login do Twitter."); } else if (user.isNew()) { Log.d("MeuApp", "Usuário criado e logado via Twitter!"); } else { Log.d("MeuApp", "Usuário logado via Twitter!"); } } }); if (!ParseTwitterUtils.isLinked(user)) { ParseTwitterUtils.link(user, this, new SaveCallback() { @Override public void done(ParseException ex) { if (ParseTwitterUtils.isLinked(user)) { Log.d("MeuApp", "Boa! Usuário conectou sua conta do Twitter!"); } } }); } SSO LINK
  15. 31.
  16. 32.

    $ curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash $ parse new

    LightningTalkCloudCode Email: gustavocsb@gmail.com Password: 1:Foliao 2:Lightning Talk Select an App: 2 $ cd LightningTalkCloudCode command line tool
  17. 34.

    $ parse deploy New release is named v1 $ curl

    -X POST \ -H "X-Parse-Application-Id: <INSERIR PARSE APP ID>" \ -H "X-Parse-REST-API-Key: <INSERIR PARSE REST API KEY>" \ -H "Content-Type: application/json" \ -d '{}' \ https://api.parse.com/1/functions/hello { "result": "Hello world!" } deploy
  18. 35.

    cloud functions Parse.Cloud.define("averageStars", function(request, response) { var query = new

    Parse.Query("Review"); query.equalTo("movie", request.params.movie); query.find({ success: function(results) { var sum = 0; for (var i = 0; i < results.length; ++i) { sum += results[i].get("stars"); } response.success(sum / results.length); }, error: function() { response.error("movie lookup failed"); } }); });
  19. 36.

    cloud functions - validations Parse.Cloud.beforeSave("Review", function(request, response) { if (request.object.get("stars")

    < 1) { response.error("you cannot give less than one star"); } else if (request.object.get("stars") > 5) { response.error("you cannot give more than five stars"); } else { response.success(); } });
  20. 38.

    networking Parse.Cloud.httpRequest({ method: 'GET’, url: 'http://www.parse.com/', success: function(httpResponse) { console.log(httpResponse.text);

    }, error: function(httpResponse) { console.error('Request failed with response code ' + httpResponse.status); } });