エンジニア戦記 〜小さなチーム、大きな未来〜

72
Copyright © Classmethod, Inc.

Upload: yuki-hirai

Post on 14-Jul-2015

20.536 views

Category:

Engineering


2 download

TRANSCRIPT

Copyright © Classmethod, Inc.

平井祐樹29

2011/2 Classmethod入社iOS 開発歴2年半

blog http://dev.classmethod.jp/author/hirai-yuki

Copyright © Classmethod, Inc.

って何の会社?クラスメソッド

Copyright © Classmethod, Inc.

Solutions

AWSコンサルティングAmazonクラウドに特化したサービス提供

iOSアプリ開発iOS/Android ネイティブアプリケーション開発

Copyright © Classmethod, Inc.

Developers.IO

Copyright © Classmethod, Inc.

Developers.IO

月間平均 80 万PV

Copyright © Classmethod, Inc.

こんな感じでしょ?

Copyright © Classmethod, Inc.

Copyright © Classmethod, Inc.

こんな感じです。

注:テーブルのお札はおもちゃです

Copyright © Classmethod, Inc.

プロジェクト登場人物

デザイナー

プロダクトオーナー

Web API担当者

iOS エンジニア

Copyright © Classmethod, Inc.

今日のお話

Web API担当者iOS エンジニア

Copyright © Classmethod, Inc.

今日のお話

Web API との付き合い方Web API 担当者ヲ攻略セヨ

Copyright © Classmethod, Inc.

突然ですが…

Copyright © Classmethod, Inc.

プロジェクトに参加してもらいます

Copyright © Classmethod, Inc.

イメージしてみてください

Copyright © Classmethod, Inc.

今あなたはとあるプロジェクトのiOSエンジニアとしてアサインされました。

その一方で、サーバーサイドエンジニアがWebAPIの実装をしています。

Copyright © Classmethod, Inc.

Web API 完成 ?

Copyright © Classmethod, Inc.

iOSの実装を進めていたあなたは

と、日頃の戦いに疲れきっているのにも関わらずちょっと元気がでます。

「よし!これで結合できるぞ!」

Copyright © Classmethod, Inc.

おもむろに仕様書に目を通すと

Copyright © Classmethod, Inc.

{ "header": { "status": "success", "message": "..." }, "response": { "topics": [{ "topic_id": 123, "topic_title": "...", "topic_content": "...", "category_id": 456, "category_name": "..." }] } }

Copyright © Classmethod, Inc.

あなたは気づいてしまいます。

Copyright © Classmethod, Inc.

{ "header": { "status": "success", "message": "..." }, "response": { "topics": [{ "topic_id": 123, "topic_title": "...", "topic_content": "...", "category_id": 456, "category_name": "..." }] } }

Copyright © Classmethod, Inc.

{ "header": { "status": "success", "message": "..." }, "response": { "topics": [{ "topic_id": 123, "topic_title": "...", "topic_content": "...", "category_id": 456, "category_name": "..." }] } }

HTTPステータスコードで表してくれればいいのに!

Copyright © Classmethod, Inc.

このままだと…

Copyright © Classmethod, Inc.

AFHTTPRequestOperationManager *manager;

[manager GET:@"http://xxx.com/possts" parameters:nil success:^(...) { // 成功時の処理 } failure:^(...) { // 失敗時の処理 }];

エラーが発生しても

こっち

Copyright © Classmethod, Inc.

さらに

Copyright © Classmethod, Inc.

{ "header": { "status": "success", "message": "..." }, "response": { "topics": [{ "topic_id": 123, "topic_title": "...", "topic_content": "...", "category_id": 456, "category_name": "..." }] } }

Copyright © Classmethod, Inc.

{ "header": { "status": "success", "message": "..." }, "response": { "topics": [{ "topic_id": 123, "topic_title": "...", "topic_content": "...", "category_id": 456, "category_name": "..." }] } }

いらないのに

Copyright © Classmethod, Inc.

@interface CLMTopic : NSObject

@property (nonatomic) NSInteger topicIdentifier; @property (nonatomic) NSString *topicTitle; @property (nonatomic) NSString *topicContent;

@end

格好悪いなぁ

Copyright © Classmethod, Inc.

あなたは Web API 担当者にこう提案します。

Copyright © Classmethod, Inc.

{ "topics": [{ "id": 123, "title": "...", "content": "...", "category_id": 456, "category_name": "..." }] }

Copyright © Classmethod, Inc.

Web API 担当者は内心こう思います。

Copyright © Classmethod, Inc.

(ったく、めんどくせぇな・・・)

Copyright © Classmethod, Inc.

そんな空気を感じてもあなたは動じず提案を続けました。

Copyright © Classmethod, Inc.

すると、新しいAPIを手に入れることができました!

これで実装への悪影響を回避することができますね。

Copyright © Classmethod, Inc.

一安心もつかの間・・・

Copyright © Classmethod, Inc.

おもむろに仕様書に目を通すと

Copyright © Classmethod, Inc.

{ "categories": [{ "id": 456, "name": "..." }] }

Copyright © Classmethod, Inc.

またあなたは気づいてしまいます。

Copyright © Classmethod, Inc.

{ "topics": [{ "id": 123, "title": "...", "content": "...", "category_id": 456, "category_name": "..." }] }

{ "categories": [{ "id": 456, "name": "..." }] }

Copyright © Classmethod, Inc.

このままだと…

Copyright © Classmethod, Inc.

@interface CLMTopic : NSObject

@property (nonatomic) NSInteger identifer; @property (nonatomic) NSString *title; @property (nonatomic) NSString *content; @property (nonatomic) NSInteger categoryIdentifier; @property (nonatomic) NSInteger categoryName;

@end

@interface CLMCategory : NSObject

@property (nonatomic) NSInteger identifier; @property (nonatomic) NSInteger name;

@end

しっくりこない・・・

Copyright © Classmethod, Inc.

あなたは Web API 担当者にこう提案します。

Copyright © Classmethod, Inc.

{ "topics": [{ "id": 123, "title": "...", "content": "...", "category": { "id": 456, "name": "..." } }] }

Copyright © Classmethod, Inc.

@interface CLMTopic : NSObject

@property (nonatomic) NSInteger identifer; @property (nonatomic) NSString *title; @property (nonatomic) NSString *content; @property (nonatomic) CLMCategory *category;

@end

@interface CLMCategory : NSObject

@property (nonatomic) NSInteger identifier; @property (nonatomic) NSInteger name;

@end

Copyright © Classmethod, Inc.

Web API 担当者は内心こう思います。

Copyright © Classmethod, Inc.

(ああーーあーあーー)

Copyright © Classmethod, Inc.

変な空気を感じながらもあなたは提案を続けました。

Copyright © Classmethod, Inc.

すると、また新しいAPIを手に入れることができました!

これでまた実装への悪影響を回避することができますね。

Copyright © Classmethod, Inc.

一安心もつかの間・・・

Copyright © Classmethod, Inc.

おもむろに仕様書に目を通すと

Copyright © Classmethod, Inc.

目的 エンドポイント

トピック一覧取得 https://api.xxx.com/v1/topics/

カテゴリー一覧取得 https://api.xxx.com/v1/categories/

おすすめ商品取得 https://api.xxx.com/v1/products/recommend

ユーザー情報取得 https://api.example.com/v1/user/

Copyright © Classmethod, Inc.

またまたあなたは気づいてしまいます。

Copyright © Classmethod, Inc.

ホーム画面

カテゴリー一覧取得API

おすすめ商品一覧API

ユーザー情報取得API

トピック一覧取得API

Copyright © Classmethod, Inc.

ホーム画面

カテゴリー一覧取得API

おすすめ商品一覧API

ユーザー情報取得API

トピック一覧取得API

1画面表示するのに何個API叩きゃいいんだ!?

Copyright © Classmethod, Inc.

あなたは Web API 担当者にこう提案します。

Copyright © Classmethod, Inc.

1 Screen, 1 API call

Copyright © Classmethod, Inc.

1 Screen, 1 API call

Copyright © Classmethod, Inc.

1 Screen, 1 API call

Copyright © Classmethod, Inc.

Web API 担当者は言いました。

Copyright © Classmethod, Inc.

「Ha?」

Copyright © Classmethod, Inc.

あなたは続けます

Copyright © Classmethod, Inc.

1画面を表示するのに、何度も異なるAPIにアクセスしなければならず、非効率ですし、画面を表示するまでに時間もかかってしまい、ユーザーを待たせてしまいます。これは良いユーザー体験とはいえません。何度もAPIへのアクセスを繰り返すことは、速度の問題だけでなく、データの一部だけが表示されてしまうといった問題を引き起こす可能性もあります。したがってとにかくホーム画面で表示する情報を1つに詰め込んだ "ホーム画面専用" APIを作成し、それに1回アクセスするだけですべての情報が取得できた方が確実に利便性が高いです。 詳しくは "Web API The Good Parts" をご覧ください。

Copyright © Classmethod, Inc.

「・・・なるほどですね」

Copyright © Classmethod, Inc.

なるほどですね!

Copyright © Classmethod, Inc.

その言葉を聞いてあなたは実装に戻りました。

Copyright © Classmethod, Inc.

すると、またまた新しいAPIを手に入れることができました!

これでまたまた実装への悪影響を回避することができますね。

Copyright © Classmethod, Inc.

こうして、プロジェクトは順調に進み無事納品することができたのでした。

Copyright © Classmethod, Inc.

Copyright © Classmethod, Inc.

まとめ

• Web API の知識は必須!

• Web API The Good Parts を読もう!

• 文句を言うのは簡単、改善案を提案できる力を!