Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
KotlinでRetrofitを使いやすくするちょっとした工夫
Search
Shinya Kumagai
February 26, 2016
Programming
2
540
KotlinでRetrofitを使いやすくするちょっとした工夫
2016/02/26 Kotlin Birthday Party #jkug
Shinya Kumagai
February 26, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
rails new flags - `rails new` のフラグから Rails を構成するコンポーネントの変遷をザックリ眺める
snaka
0
1.8k
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
310
CSC509 Lecture 11
javiergs
PRO
0
180
Quine, Polyglot, 良いコード
qnighy
4
650
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
4
2.4k
Jakarta EE meets AI
ivargrimstad
0
770
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Navigating Team Friction
lara
183
14k
A Modern Web Designer's Workflow
chriscoyier
693
190k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Building Applications with DynamoDB
mza
90
6.1k
How STYLIGHT went responsive
nonsquared
95
5.2k
Unsuck your backbone
ammeep
668
57k
Become a Pro
speakerdeck
PRO
25
5k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
KotlinͰRetrofitΛ ͍͘͢͢Δ ͪΐͬͱͨ͠ 2015/02/26 Shinya Kumagai(@droibit)
About Me • Shinya Kumagai (۽୩ ৻) 25ࡀ • Twitter,
GitHub - @droibit • λΦιϑτΣΞגࣜձࣾ
Happy Birthday Kotlin!! (ɾ8ɾ)
֓ཁ • connpass API ༻ͷRetrofit ServiceΛର - JavaͰఆٛ͞ΕͨService - KotlinͰServiceΛఆٛ
KotlinͰ͏ͱ͖ͷͪΐͬͱͨ͠ IUUQTRVBSFHJUIVCJPSFUSPpU
Connpass API • ݕࡧΫΤϦ - keyword … Ωʔϫʔυ - order
… ݁Ռͷදࣔॱ (1:ߋ৽ॱ, 2…) - ymd … Πϕϯτ։࠵ (yyyymmdd) • ϨεϙϯεJSON ?keyword=kotlin&order=1&ymd=20150226 IUUQDPOOQBTTDPNBCPVUBQJ
JavaͰఆٛ͞ΕͨService public interface ConnpassService { // ※ @Get, @Query লུ
Response searchEvent(@NonNull String keyword, @Nullable Integer order, @Nullable String ymd); } // શΫΤϦΛࢦఆ service.searchEvent(“kotlin”, 1, "20160226"); // ΩʔϫʔυͷΈͷ߹ service.searchEvent("kotlin", null, null);
// ֦ுؔΛఆٛ + σϑΥϧτҾ fun ConnpassService.searchEventExt( keyword: String, order: Order?
= null, ymd: String? = null ) = searchEvent(keyword, order?.index, ymd) // ݕࡧ݁Ռͷදࣔॱͷྻڍମ enum class Order(val index: Int) { UPDATE(1), EVENT(2), NEW(3); override fun toString() = "$index" } // ΩʔϫʔυҎ֎ඞཁͳΫΤϦͷΈ service.searchEventExt("kotlin", order = Order.UPDATE) KotlinͰվળ
KotlinͰServiceΛఆٛ interface ConnpassService { // ※ @Get,@Query লུ fun searchEvent(keyword:
String, order: Order? = null, ymd: String? = null): Response } // ΩʔϫʔυҎ֎ඞཁͳΫΤϦͷΈ service.searchEvent(“kotlin”, order = Order.UPDATE)
// ༻్ʹ߹Θ֦ͤͨுؔΛఆٛ fun ConnpassService.searchEvent( keyword: String, order: Order? = null,
ymd: Date? = null ) = searchEvent(keyword, order, format(ymd)) // DateΛ yyyymmdd ϑΥʔϚοτͷStringʹม fun format(date: Date?): String? = … // ։࠵ʹDateΦϒδΣΫτΛࢦఆ service.searchEvent(“kotlin", ymd = dateFromTimesSquare) վળྫ
·ͱΊ • ൚༻తͳΠϯλʔϑΣʔεʹͳΔ͍͋ɺ σϑΥϧτҾɺ֦ுؔͰγϯϓϧͳ Service fabricͷΑ͏ʹͳΒͳ͍Α͏ʹؾΛ͚ͭ·͠ΐ͏
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠