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
760
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
260
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
640
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
720
Gotanda.pm #1
mihyaeru21
1
160
Other Decks in Programming
See All in Programming
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
120
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
CSC305 Lecture 26
javiergs
PRO
0
140
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
Go の GC の不得意な部分を克服したい
taiyow
2
770
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
150
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
快速入門可觀測性
blueswen
0
340
Featured
See All Featured
Scaling GitHub
holman
458
140k
Documentation Writing (for coders)
carmenintech
66
4.5k
Become a Pro
speakerdeck
PRO
26
5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Building Adaptive Systems
keathley
38
2.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Optimizing for Happiness
mojombo
376
70k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
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
·ͱΊ • ඪ४ϥΠϒϥϦ͕ॆ࣮Ͱऔ͖͍ͬ͢ • ϥΠτͳॻ͖৺͕ྑ͍ײ͡ • ιʔεՇ