際際滷

際際滷Share a Scribd company logo
5蛍でわかったつもりになる
Parse.com
Parse is the cloud app platform for
iOS, Android, JavaScript, Windows 8,
Windows Phone 8, and OS X.
Parse は BaaS ( Backend as a Service)
モバイルアプリ_kのサ`バサイド何蛍を主旗わ
りしてくれる
1.ユ`ザ砿尖字嬬
2.サ`バサイドg廾
3.サ`ドパ`ティとの銭亊
ユ`ザ砿尖字嬬
デ`タのread/writeがg
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]);
??}
}];
ブラウザからデ`タの_Jができる
-デ`タの弖紗、きQえも辛嬬
デ`タのread/writeがg
objectId	 	 	 	 	 	 	 :	 Re徨
cheatMode	 	 	 	 	 	 :	 弖紗したカラム
playerName	 	 	 	 	 :	 弖紗したカラム
score	 	 	 	 	 	 	 	 	 	 :	 弖紗したカラム
createdAt	 	 	 	 	 	 :	 オブジェクトの伏撹晩r(GMT)
updatedAt	 	 	 	 	 	 :	 オブジェクトの恷K筝晩r(GMT)
ACL	 	 	 	 	 	 	 	 	 	 	 	 :	 アクセスコントロ`ル
ユ`ザ鞠h?ログインがg
// 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.
????}
}];
Facebook/twitterB亊がg
// 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!");
????????}
????}];
}
アクセスコントロ`ルO協がg
{"userId":{"read":true,"write":true}}
すべてのオブジェクトにして、
user/roleごとにread/writeのアクセス慙泙O協できる
メ`ルJ^がg
Userテ`ブルのデフォルトカラム
objectId	 	 	 	 	 	 	 :	 Re徨
username	 	 	 	 	 	 	 :	 ユ`ザ兆(required)
password	 	 	 	 	 	 	 :	 パスワ`ド(required)
authData	 	 	 	 	 	 	 :	 Facebook/twitterのJ^秤
emailVerified	 	 :	 メ`ルJ^フラグ
email	 	 	 	 	 	 	 	 	 	 :	 メ`ルアドレス
createdAt	 	 	 	 	 	 :	 ユ`ザの伏撹晩r(GMT)
updatedAt	 	 	 	 	 	 :	 ユ`ザの恷K筝晩r(GMT)
ACL	 	 	 	 	 	 	 	 	 	 	 	 :	 アクセスコントロ`ル
O協鮫中から Verifying user emails を ON にするだけ
1.emailVeri?ed が false のユ`ザはログインできない
2.サインアップrにメ`ルが曙く
3.リンクをタップすると emailVeri?ed が true になる
プッシュ宥岑がg
// 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];
サ`バサイドg廾
サ`バサイドのv方g佩がg
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
サ`バサイドのv方g佩がg
// 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);
??????? }
??? }
});
デ`タきzみ念瘁のトリガ`g廾がg
Parse.Cloud.beforeSave("Review", function(request, response) {
if (request.object.get("stars") < 1 || request.object.get("stars") > 5) {
???? response.error();	 //	 きzみI尖がg佩されない
?? }
?? var comment = request.object.get("comment");
?? if (comment.length > 140) {
???? request.object.set("comment", comment.substring(0, 137) + "...");
??}
?? response.success();?
});
timeout は 3 seconds
デ`タきzみ念瘁のトリガ`g廾がg
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 はO薦聞わない圭がいい
サ`ドパ`ティとの銭亊
Parse + Twilioがg
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サ`ビス
Parse + Mailgunがg
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");
?? }
});
+ CrowdFlower Real Time Foto Moderator
- 鮫颯愁螢紿`ション(ランキング、カテゴライズ、コンテン
ツO、など)
- https://crowd?ower.com
+ Moment
- 晩原I尖のJSライブラリ
- http://momentjs.com
+ Stripe
- モバイルクレカQgAPI
- https://stripe.com
+ Underscore
- ユ`ティリティライブラリ
- http://underscorejs.org
児云涙創

More Related Content

5蛍でわかったつもりになる永温姻壊艶.界看馨

  • 1. 5蛍でわかったつもりになる Parse.com Parse is the cloud app platform for iOS, Android, JavaScript, Windows 8, Windows Phone 8, and OS X.
  • 2. Parse は BaaS ( Backend as a Service) モバイルアプリ_kのサ`バサイド何蛍を主旗わ りしてくれる 1.ユ`ザ砿尖字嬬 2.サ`バサイドg廾 3.サ`ドパ`ティとの銭亊
  • 4. デ`タのread/writeがg 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. ブラウザからデ`タの_Jができる -デ`タの弖紗、きQえも辛嬬 デ`タのread/writeがg objectId : Re徨 cheatMode : 弖紗したカラム playerName : 弖紗したカラム score : 弖紗したカラム createdAt : オブジェクトの伏撹晩r(GMT) updatedAt : オブジェクトの恷K筝晩r(GMT) ACL : アクセスコントロ`ル
  • 6. ユ`ザ鞠h?ログインがg // 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. Facebook/twitterB亊がg // 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!"); ????????} ????}]; }
  • 9. メ`ルJ^がg Userテ`ブルのデフォルトカラム objectId : Re徨 username : ユ`ザ兆(required) password : パスワ`ド(required) authData : Facebook/twitterのJ^秤 emailVerified : メ`ルJ^フラグ email : メ`ルアドレス createdAt : ユ`ザの伏撹晩r(GMT) updatedAt : ユ`ザの恷K筝晩r(GMT) ACL : アクセスコントロ`ル O協鮫中から Verifying user emails を ON にするだけ 1.emailVeri?ed が false のユ`ザはログインできない 2.サインアップrにメ`ルが曙く 3.リンクをタップすると emailVeri?ed が true になる
  • 10. プッシュ宥岑がg // 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];
  • 12. サ`バサイドのv方g佩がg 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. サ`バサイドのv方g佩がg // 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. デ`タきzみ念瘁のトリガ`g廾がg Parse.Cloud.beforeSave("Review", function(request, response) { if (request.object.get("stars") < 1 || request.object.get("stars") > 5) { ???? response.error(); // きzみI尖がg佩されない ?? } ?? var comment = request.object.get("comment"); ?? if (comment.length > 140) { ???? request.object.set("comment", comment.substring(0, 137) + "..."); ??} ?? response.success();? }); timeout は 3 seconds
  • 15. デ`タきzみ念瘁のトリガ`g廾がg 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 はO薦聞わない圭がいい
  • 17. Parse + Twilioがg 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. Parse + Mailgunがg 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. + CrowdFlower Real Time Foto Moderator - 鮫颯愁螢紿`ション(ランキング、カテゴライズ、コンテン ツO、など) - https://crowd?ower.com + Moment - 晩原I尖のJSライブラリ - http://momentjs.com + Stripe - モバイルクレカQgAPI - https://stripe.com + Underscore - ユ`ティリティライブラリ - http://underscorejs.org