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
CrystalでTwitter botを作ってみた / Create a Twitter b...
Search
Mihyaeru
July 31, 2015
Programming
0
1.3k
CrystalでTwitter botを作ってみた / Create a Twitter bot in Crystal
東京 Crystal 勉強会 #1 in 五反田
Mihyaeru
July 31, 2015
Tweet
Share
More Decks by Mihyaeru
See All by Mihyaeru
会計 freee バックエンドの今後 / freee backend api
mihyaeru21
8
24k
Railsで実装されている機能のマイクロサービスへの切り離し / split to microservices from rails
mihyaeru21
1
750
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
260
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
630
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.6k
入門ReactiveX / about ReactiveX
mihyaeru21
3
420
RxSwiftと愉快な仲間たち / RxSwift with Units
mihyaeru21
4
2.7k
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
mihyaeru21
4
710
Gotanda.pm #1
mihyaeru21
1
150
Other Decks in Programming
See All in Programming
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Remix on Hono on Cloudflare Workers
yusukebe
1
300
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
970
C++でシェーダを書く
fadis
6
4.1k
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
cmp.Or に感動した
otakakot
3
200
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Become a Pro
speakerdeck
PRO
25
5k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
A Philosophy of Restraint
colly
203
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Being A Developer After 40
akosma
87
590k
How GitHub (no longer) Works
holman
310
140k
Transcript
CrystalͰTwitter botΛ࡞ͬͯΈͨ ౦ژ Crystal ษڧձ #1 in ޒా @mihyaeru21
© 2015 Mihyaeru ͓લͩΕΑ • ϛώϟΤϧ @mihyaeru21 • ࠷ۙSwiftͱPerlΛʑͰ •
ͨ·ʹPython • YAPCͰొஃ͢Δ͜ͱʹͳͬͯΨΫϒϧ 2
© 2015 Mihyaeru ࡞ͬͯΈͨܥLT • ܀΅ͬͱ https://twitter.com/crybot21 • https://github.com/mihyaeru21/crybot •
UserStreamʹܨ͍Ͱϝϯγϣϯͱಉ͡༰Λݴ ͍ฦ͚ͩ͢ • ϩʔΧϧͰಈ͔ͯ͠Δ͔Β͙͢ಈ͔ͳ͘ͳΔӡ໋ 3
© 2015 Mihyaeru ΊͬͪΌ͠ΐ΅͍σϞ 4
ݴ͍ฦ͚ͩ͢Ͱͨ͠
© 2015 Mihyaeru CrystalΛͬͯΈͨײ • ·ΔͰLLΛॻ͍͍ͯΔײ֮ • ๛ͳඪ४Ϟδϡʔϧ͕͋ͬͯศར • Streaming
APIॳΊ࣮͚ͯͨ͠ͲͳΜͱ͔ ͳͬͨ 6
© 2015 Mihyaeru CrystalΛͬͯΈͨײ • ϥΠτʹ͔͚Δ͚Ͳɺܕͷѻ͍ϥΠτͰ ͳ͔ͬͨ • ٽ͘ٽ͘Ϩϕϧͳͱ͜ΖΛॻ͍ͨ •
υΩϡϝϯτιʔείʔυ • RubyΛ͋·ΓΒͳ͔͔ͬͨΒײͨ͡͠͞ 7
© 2015 Mihyaeru ͬͨඪ४Ϟδϡʔϧ • cgi • env • http
• json • oauth • openssl • secure_random • socket • time 8
© 2015 Mihyaeru cgi • URLΤϯίʔυʹ༻ • cgiۭؒʹ͋ͬͨͷ͔ɻɻɻ • uriͱ͔httpͱ͔Λݟ͍ͯͨ
9
© 2015 Mihyaeru env • ڥมͷಡΈࠐΈ • access tokenͱ͔ͷಡΈࠐΈʹ༻ •
ී௨ʹHashͬΆ͑ͨ͘ 10
© 2015 Mihyaeru http (./client ./request) • ΧδϡΞϧʹ͑Δ • ௨৴ͷ్தͰίʔϧόοΫͱ͔ʹσʔλΛྲྀ
ͯ͘͠ΕΔ͕ͭ(ݟͨݶΓ)ແ͔ͬͨ • υΩϡϝϯτ͔ΒભҠ͢Διʔείʔυ͕Ϧ Ϧʔε൛ΑΓ৽ͯ͘͠ϋϚͬͨ 11
© 2015 Mihyaeru json • ͱΓ͋͑ͣ JSON.parse • σίʔυ݁Ռ͍͢͝ܕʹͳ͍ͬͯͯฦΓ ͷѻ͍͕ຯʹ͔ͬͨ͠
12
© 2015 Mihyaeru oauth • ௨৴·Ͱͬͯ͘ΕΔ͔ͱࢥ͚ͬͨͲҧͬͨ • ͬͨͷ OAuth::Signature •
໘ͳAuthϔομΛͺͬͱ࡞Ε͍͍ͯײ͡ • খճΓ͕ޮ͘ײ 13
© 2015 Mihyaeru openssl • OpenSSL::SSL::Socket • SSL༻ʹTCPSocketΛแΈࠐΜͰ͚͋͛ͨͩ 14
© 2015 Mihyaeru secure_random • nonceΛ࡞Δͷʹར༻ • SecureRandom.hex(32) ͰɺͱΓ͋͑ͣ32ܻ ͷ16ਐจࣈྻ͕ಘΒΕΔ
• nonceʹUUIDͷϋογϡΛ͓͏ͱࢥͬͯ ͚ͨͲUUIDϞδϡʔϧ͕ແ͔ͬͨ 15
© 2015 Mihyaeru socket • TCPSocket • ίωΫγϣϯΛுΓͬͺͳ͠ͰಡΈଓ͚Δ෦ Ͱ༻ •
ൺֱతϨϕϧͳ෦͚ͩͲ৮Γ͔ͬͨ͢ 16
© 2015 Mihyaeru time • Time.utc_now.to_i ͚͓͚֮ͩ͑ͯ ͻͱ·ͣੜ͖͍͚ͯͦ͏ • Time.now.to_i
ͬͯॻ͍ͯͯϋϚͬͨ 17
·ͱΊ • ඪ४ϥΠϒϥϦ͕ॆ࣮Ͱऔ͖͍ͬ͢ • ϥΠτͳॻ͖৺͕ྑ͍ײ͡ • ιʔεՇ