More Related Content
Similar to 5分でわかったつもりになるParse.com
Similar to 5分でわかったつもりになるParse.com (20)
5分でわかったつもりになるParse.com
- 2. Parse は BaaS ( Backend as a Service)
モバイルアプリ開発のサーバサイド部分を肩代わ
りしてくれる
1.ユーザ管理機能
2.サーバサイド実装
3.サードパーティとの連携
- 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]);
}
}];
- 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. 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!");
}
}];
}
- 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. プッシュ通知が簡単
// 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. サーバサイドの関数実行が簡単
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. サーバサイドの関数実行が簡単
// 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);
}
}
});
- 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 は極力使わない方がいい
- 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. 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. + CrowdFlower Real Time Foto Moderator
- 画像ソリューション(ランキング、カテゴライズ、コンテン
ツ監視、など)
- https://crowdflower.com
+ Moment
- 日付処理のJSライブラリ
- http://momentjs.com
+ Stripe
- モバイルクレカ決済API
- https://stripe.com
+ Underscore
- ユーティリティライブラリ
- http://underscorejs.org