Slide 1

Slide 1 text

͓͏ͪʹAPIΛੜ΍͓͢࿩ 2018/08/03 Kyoto.LT #21 γʔαʔגࣜձࣾ Itsuki AOYAGI (@yagi2)

Slide 2

Slide 2 text

ࣗݾ঺հ • ੨༄ थʢItsuki AOYAGI) • ΍͗ʹ͍ʢ@yagi2, @yaginierʣ • γʔαʔגࣜձࣾ • AndroidΞϓϦΤϯδχΞ • ͓͏͕ͪେ޷͖

Slide 3

Slide 3 text

ࣗݾ঺հ • ੨༄ थʢItsuki AOYAGI) • ΍͗ʹ͍ʢ@yagi2, @yaginierʣ • γʔαʔגࣜձࣾ • AndroidΞϓϦΤϯδχΞ • ͓͏͕ͪେ޷͖

Slide 4

Slide 4 text

࠷ۙ͸؆୯ʹ͓͏ͪͱITΛܨ͛ΒΕΔ ɾGoogle Home ɾAmazon Alexa ɾHomePod ……

Slide 5

Slide 5 text

࠷ۙ͸؆୯ʹ͓͏ͪͱITΛܨ͛ΒΕΔ ɾGoogle Home ɾAmazon Alexa ɾHomePod …… ͕ɺҙ֎ͱͰ͖Δ͜ͱ͸ݶΒΕ͍ͯΔ……

Slide 6

Slide 6 text

σϑΥϧτͰແ͍ػೳΛ΍Δʹ͸ • ࣗ෼ͰΞΫγϣϯ΍εΩϧΛ࢖͏ • ൺֱత؆୯ʹ௥ՃͰ͖Δ͕ॊೈੑ͸ऑ͍ • IFTTTΛ࢖ͬͯWebhook͍ͯ͠Ζ͍Ζ΍Δ • Webhook͢ΔͷͰՄೳੑ͸ແݶେ͕ͩ༻ҙ͢Δ΋ͷ΋ଟ͍

Slide 7

Slide 7 text

σϑΥϧτͰແ͍ػೳΛ΍Δʹ͸ • ࣗ෼ͰΞΫγϣϯ΍εΩϧΛ࢖͏ • ൺֱత؆୯ʹ௥ՃͰ͖Δ͕ॊೈੑ͸ऑ͍ • IFTTTΛ࢖ͬͯWebhook͍ͯ͠Ζ͍Ζ΍Δ • Webhook͢ΔͷͰՄೳੑ͸ແݶେ͕ͩ༻ҙ͢Δ΋ͷ΋ଟ͍

Slide 8

Slide 8 text

͓͏ͪAPI

Slide 9

Slide 9 text

APIʢAPlication Interfaceʣ ஌ͬͯΔਓ

Slide 10

Slide 10 text

API࢖ͬͨ͜ͱ͋Δਓ

Slide 11

Slide 11 text

API࡞ͬͨ͜ͱ͋Δਓ

Slide 12

Slide 12 text

ࣗ୐ʹAPIαʔό͕͋Δਓ

Slide 13

Slide 13 text

͓͏ͪAPI • ࣗ୐ͷ͋Ε͜ΕΛHTTP(S)ܦ༝Ͱ͋Ε͜ΕͰ͖ ΔΑ͏ʹ͢Δ΍ͭ • ͓͏ͪͷঢ়ଶʢGETʣ • Ոిͷૢ࡞ʢPOSTʣ

Slide 14

Slide 14 text

ԿΛ࣮ݱ͍͔ͨ͠ • PCͷిݯΛೖΕ͍ͨʢWake on LANʣ • ΠϯλʔωοτϥδΦͷૢ࡞Λ͍ͨ͠ • ΤΞίϯ౳ͷՈిͷૢ࡞Λ͍ͨ͠ • ෦԰ͷԹ౓ͱ͔औΓ͍ͨ

Slide 15

Slide 15 text

ࠓճ͸ेീ൪ͷKotlinͰAPIΛ࡞Δ

Slide 16

Slide 16 text

KotlinͰͷAPI • બ୒ࢶ͸͍Ζ͍Ζ͋ΔʢͳʹͤJavaͷࢿ࢈͕࢖͑ΔͷͰʣ • SpringBootવΓ…… • KotlinͱSpring BootΛ࢖ͬͯαΫοͱୟ͚ΔAPIΛ࡞Δ • ͔͠͠KotlinͰ΍Γ͍ͨ • ͷͰKtorͱ͍͏ϑϨʔϜϫʔΫΛ࢖͏

Slide 17

Slide 17 text

Ktor • ΊͬͪΌബ͍WebΞϓϦͷϑϨʔϜϫʔΫ ( https://github.com/ktorio/ktor ) • ඇಉظॲཧ΋͍͍ײ͡ʹͳ͍ͬͯΔ • KotlinͷCoroutinesͱ͍͏ػೳ fun main(args: Array) { embeddedServer(Netty, 8080) { routing { get("/") { call.respondText("Hello, world!", ContentType.Text.Html) } } }.start(wait = true) }

Slide 18

Slide 18 text

KtorͰͷAPI • https://github.com/yagi2/Kaya • Private Repository • ͱ͸͍࣮͑૷͸ࠓճͷຊ࣭తͳ෦෼Ͱ͸ͳ͍ͷͰলུ • KtorͰ͓͏ͪAPIΛϦϓϨʔεͨ͠࿩ - Speaker Deck

Slide 19

Slide 19 text

ͯ͞API͸׬੒ͨ͠

Slide 20

Slide 20 text

ͳͥAPIΛ࡞ͬͨͷ͔ • Application Interface • ͭ·ΓAPIΛ༻ҙ͢Ε͹͍ΖΜͳͱ͜Ζ͔Β࢖͑Δ • Web,εϚϗ,HomeܥσόΠε

Slide 21

Slide 21 text

ࠓճͷߏ੒ • API • Kotlin+KtorΛRaspberryPi্Ͱಈ͔͢ʢࣗ୐಺ʣ • ΫϥΠΞϯτ • Webϒϥ΢βʢૉHTMLʣ • AndroidΞϓϦʢेീ൪ʣ • Google Home miniʢࣗ୐಺ʣ ※DDNSΛ࢖ͬͯࣗ୐֎͔Β΋APIʹΞΫηεՄೳ

Slide 22

Slide 22 text

ྑ͍఺ • ͓͏ͪͷ͋Ε͜Εʹର͢ΔೖྗͷΠϯλʔϑΣʔε͕૿͑ͨ • εϚϗࣾձͳݱ୅ʹͽͬͨΓ • ೖྗΠϯλʔϑΣʔε͕ଟ͍ʹӽͨ͜͠ͱ͸ͳ͍࠷ߴ • ͳΜͳΒcurlͰՈిૢ࡞Ͱ͖Δ • ͓͏ͪͷ͋Ε͜ΕΛҰݩ؅ཧͰ͖Δͷ͸ྑ͍ • APIΛ࡞Δೳྗ͸ؒҧ͍ͳ্͕͘Δ

Slide 23

Slide 23 text

ྑ͘ͳ͍఺ • ͳΜ͔RasPi͕ࢮΜͩΓϓϩηε͕ࢮΜͩΓ͢Δ • MackerelͰࢮ׆؂ࢹ͍ͯ͠Δ • ঢ়ଶΛRasPiʹ΋ͨͤ͗͢Δͱࠓ౓͸ਖ਼نͷϦϞίϯ͔Βૢ࡞ Λͨ͘͠ͳ͘ͳΔ • APIΛհ͞ͳ͍ͷͰঢ়ଶ؅ཧ͕໘౗ʹͳΔ

Slide 24

Slide 24 text

ࠓޙ΍Γ͍ͨ͜ͱ • ࠓ͸RESTfulAPIͳͷͰGraphQLʹͨ͠Γ͍ͨ͠ɻ • WebUI࡞Γ͍ͨ • Թ౓ͱ͔֎෦ͷՈిૢ࡞ɺऔಘʹ͍ΖΜͳόΠφϦ͕ґଘͯ͠ ΔͷͰDockerͱ͔ͰυΧυΧ͍ͨ͠

Slide 25

Slide 25 text

࣮ࡍʹى͖ͨා͍࿩

Slide 26

Slide 26 text

ͦͷ̍ ͳΜ͔͍Ζ͍Ζ഑ઢͯͨ͠ΒLED͕ ম͖͖Εͨ

Slide 27

Slide 27 text

ిؾͷษڧΛ͔ͬ͠Γ͠·͠ΐ͏

Slide 28

Slide 28 text

ͦͷ̎ ͳΜ͔উखʹPC͕෇͍ͨΓϥδΦ ͕෇͍ͨΓ͢Δոحݱ৅

Slide 29

Slide 29 text

https://twitter.com/rombulow/status/990684453734203392

Slide 30

Slide 30 text

Կ͕ى͖ͨͷ͔ • GETͰτάϧͳϦΫΤετΛ࣮૷͢Δ • ςϨϏʹGET → ిݯONͳΒOFF OFFͳΒON • Chromeͷ৽نλϒ։͍ͨͱ͖ͷ࠷ۙ։͍ͨϖʔδʹAPI࢖ ͏ϖʔδ͕͋ΔͱGET͕ϦΫΤετ͞ΕΔ

Slide 31

Slide 31 text

HTTPΛཧղͤΑ HTTPͷGET͸ႈ౳ʹ͢Δ΂͖Ͱ ͋ͬͯɺ෭࡞༻Λ΋ͨͤΔͱ Googleͱ͔ͷBOTͱ͔ͷΫϩʔϥ ͕͓Ոʹ৵ೖͯ͘͠Δ

Slide 32

Slide 32 text

ͱ͸͍͑ΊͪΌΜ͜ศརͩ͠ ݱ୅Google Homeͱ͔͋ΔͷͰ ΈΜͳ΍Ζ͏ ͓ΘΓ