Successfully reported this slideshow.
Your SlideShare is downloading. ×

5分でわかったつもりになるParse.com

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
fluentd
fluentd
Loading in …3
×

Check these out next

1 of 20 Ad

More Related Content

Slideshows for you (18)

Similar to 5分でわかったつもりになるParse.com (20)

Advertisement

Recently uploaded (20)

5分でわかったつもりになるParse.com

  1. 1. 5分でわかったつもりになる Parse.com Parse is the cloud app platform for iOS, Android, JavaScript, Windows 8, Windows Phone 8, and OS X.
  2. 2. Parse は BaaS ( Backend as a Service) モバイルアプリ開発のサーバサイド部分を肩代わ りしてくれる 1.ユーザ管理機能 2.サーバサイド実装 3.サードパーティとの連携
  3. 3. ユーザ管理機能
  4. 4. データのread/writeが簡単 String, Number, Boolean, Date, File, GeoPoint, Array, Object, Pointer, Relation が保存できる // Saving Object PFObject *gameScore = [PFObject objectWithClassName:@"GameScore"]; [gameScore setObject:[NSNumber numberWithInt:1337] forKey:@"score"]; [gameScore setObject:@"Kenta TSUJI" forKey:@"playerName"]; [gameScore setObject:[NSNumber numberWithBool:NO] forKey:@"cheatMode"]; [gameScore saveInBackground]; // Query PFQuery *query = [PFQuery queryWithClassName:@"GameScore"]; [query whereKey:@"playerName" equalTo:@"Kenta TSUJI"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {    if (!error) {      NSLog(@"Successfully retrieved %d scores.", objects.count);    } else {      NSLog(@"Error: %@ %@", error, [error userInfo]);   } }];
  5. 5. ブラウザからデータの確認ができる -データの追加、書き換えも可能 データのread/writeが簡単 objectId : 識別子 cheatMode : 追加したカラム playerName : 追加したカラム score : 追加したカラム createdAt : オブジェクトの生成日時(GMT) updatedAt : オブジェクトの最終変更日時(GMT) ACL : アクセスコントロール
  6. 6. ユーザ登録・ログインが簡単 // Signing up PFUser *user = [PFUser user]; user.username = @"username"; // required user.password = @"password"; // required user.email = @"email@example.com"; // optional [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (!error) { // success     } }]; // Logging in [PFUser logInWithUsernameInBackground:@"username" password:@"password"   block:^(PFUser *user, NSError *error) {     if (user) { // Do stuff after successful login.     } }];
  7. 7. Facebook/twitter連携が簡単 // Linking if (![PFFacebookUtils isLinkedWithUser:user]) {     [PFFacebookUtils linkUser:user permissions:nil block:^(BOOL succeeded, NSError *error) {         if (succeeded) {             NSLog(@"Woohoo, user logged in with Facebook!");         }     }]; } // Linking if (![PFTwitterUtils isLinkedWithUser:user]) {     [PFTwitterUtils linkUser:user block:^(BOOL succeeded, NSError *error) {         if ([PFTwitterUtils isLinkedWithUser:user]) {             NSLog(@"Woohoo, user logged in with Twitter!");         }     }]; }
  8. 8. アクセスコントロール設定が簡単 {"userId":{"read":true,"write":true}} すべてのオブジェクトに対して、 user/roleごとにread/writeのアクセス権限が設定できる
  9. 9. メール認証が簡単 Userテーブルのデフォルトカラム objectId : 識別子 username : ユーザ名(required) password : パスワード(required) authData : Facebook/twitterの認証情報 emailVerified : メール認証フラグ email : メールアドレス createdAt : ユーザの生成日時(GMT) updatedAt : ユーザの最終変更日時(GMT) ACL : アクセスコントロール 設定画面から Verifying user emails を ON にするだけ 1.emailVerified が false のユーザはログインできない 2.サインアップ時にメールが届く 3.リンクをタップすると emailVerified が true になる
  10. 10. プッシュ通知が簡単 // Find devices associated with these users PFQuery *pushQuery = [PFInstallation query]; [pushQuery whereKey:@"user" matchesQuery:userQuery];   // Send push notification to query PFPush *push = [[PFPush alloc] init]; [push setQuery:pushQuery]; // Set our Installation query [push setMessage:@"Free hotdogs at the Parse concession stand!"]; [push sendPushInBackground]; PFInstallation *installation = [PFInstallation currentInstallation]; [installation setObject:[PFUser currentUser] forKey:@"owner"]; [installation saveInBackground];
  11. 11. サーバサイド実装
  12. 12. サーバサイドの関数実行が簡単 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");      }    }); }); timeout は 15 seconds
  13. 13. サーバサイドの関数実行が簡単 // iOS [PFCloud callFunctionInBackground:@"averageStars"                    withParameters:@{@"movie": @"The Matrix"}                             block:^(NSNumber *ratings, NSError *error) {    if (!error) { NSLog(@"%@", ratings);   } }]; // Android HashMap<String, Object> params = new HashMap<String, Object>(); params.put("movie", "The Matrix"); ParseCloud.callFunctionInBackground( "averageStars", params, new FunctionCallback<Float>() {     void done(Float ratings, ParseException e) {         if (e == null) {          Log.d(ratings);         }     } });
  14. 14. データ書き込み前後のトリガー実装が簡単 Parse.Cloud.beforeSave("Review", function(request, response) { if (request.object.get("stars") < 1 || request.object.get("stars") > 5) {      response.error(); // 書き込み処理が実行されない    }    var comment = request.object.get("comment");    if (comment.length > 140) {      request.object.set("comment", comment.substring(0, 137) + "...");   }    response.success();  }); timeout は 3 seconds
  15. 15. データ書き込み前後のトリガー実装が簡単 Parse.Cloud.afterSave("Comment", function(request) {    query = new Parse.Query("Post");    query.get(request.object.get("post").id, {      success: function(post) {        post.increment("comments");       post.save();      },     error: function(error) {        throw "Got an error " + error.code + " : " + error.message;     }    }); }); timeout は 3 seconds タイムアウトするとデータの不整合が起こる可能性があ るので afterSave は極力使わない方がいい
  16. 16. サードパーティとの連携
  17. 17. Parse + Twilioが簡単 var Twilio = require('twilio'); Twilio.initialize('myAccountSid', 'myAuthToken'); //twilio.comで取得 Twilio.sendSMS({    From: "+14155551212",    To: "+14155552121",    Body: "Hello from Cloud Code!" }, {   success: function(httpResponse) {      response.success("SMS sent!");    },    error: function(httpResponse) {      response.error("Uh oh, something went wrong");    } }); Twilioとは、WebAPIを通して通話やSMS送信が可能な クラウド電話APIサービス
  18. 18. Parse + Mailgunが簡単 Mailgunとは、メール送信APIサービス var Mailgun = require('mailgun'); Mailgun.initialize('myDomainName', 'myAPIKey'); //mailgun.comで取得 Mailgun.sendEmail({    to: "email@example.com",    from: "Mailgun@CloudCode.com",    subject: "Hello from Cloud Code!",    text: "Using Parse and Mailgun is great!" }, {   success: function(httpResponse) {     console.log(httpResponse);      response.success("Email sent!");    },    error: function(httpResponse) {      console.error(httpResponse);      response.error("Uh oh, something went wrong");    } });
  19. 19. + CrowdFlower Real Time Foto Moderator - 画像ソリューション(ランキング、カテゴライズ、コンテン ツ監視、など) - https://crowdflower.com + Moment - 日付処理のJSライブラリ - http://momentjs.com + Stripe - モバイルクレカ決済API - https://stripe.com + Underscore - ユーティリティライブラリ - http://underscorejs.org
  20. 20. 基本無料

×