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
570
KotlinでRetrofitを使いやすくするちょっとした工夫
2016/02/26 Kotlin Birthday Party #jkug
Shinya Kumagai
February 26, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
RailsGirls IZUMO スポンサーLT
16bitidol
0
190
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
Code as Context 〜 1にコードで 2にリンタ 34がなくて 5にルール? 〜
yodakeisuke
0
130
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
160
MDN Web Docs に日本語翻訳でコントリビュートしたくなる
ohmori_yusuke
1
120
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
760
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
120
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
170
Discover Metal 4
rei315
2
140
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
140
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
450
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.5k
Featured
See All Featured
Building Applications with DynamoDB
mza
95
6.5k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Practical Orchestrator
shlominoach
189
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Thoughts on Productivity
jonyablonski
69
4.7k
Balancing Empowerment & Direction
lara
1
430
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
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ͷΑ͏ʹͳΒͳ͍Α͏ʹؾΛ͚ͭ·͠ΐ͏
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠