2019-12-21 コードリーディング 1st Faraday
参加者: ..., yebis0942.iconluccafort.icon
https://tech.toreta.in/entry/2019/12/03/172047
examples/specを読んで
https://github.com/lostisland/faraday/blob/master/examples/client_spec.rb
sushiとは
Faraday::Adapter::Test::Stubs便利そう
この知らなくてなるほど、こんなのあるんだ!ってなったluccafort.icon
テストの書き方という感じなのでここだけ見てもあまり意味なさそう
Faraday.new
https://github.com/lostisland/faraday/blob/073bc25cd464b6785f2069f8e30949f47731e0b4/lib/faraday.rb#L82-L85
Faraday::Connectionのインスタンスを返している
Connection
HogeOptionsが頻出
Optionsの子クラス
OptionsはStructを継承している
initialize
default_pararrel_managerとpararrel_manager
initialize_proxy
ProxyOptions
https://github.com/lostisland/faraday/blob/master/lib/faraday/options/proxy_options.rb
Forwardableとdef_delegator
Forwardableは標準ライブラリ
https://ruby-doc.org/stdlib-2.6.5/libdoc/forwardable/rdoc/Forwardable.html
メソッドの実体はないけどRDocはある
https://github.com/lostisland/faraday/blob/073bc25cd464b6785f2069f8e30949f47731e0b4/lib/faraday/connection.rb#L127-L147
IDEにやさしそう
Faraday::Request
Authorization
https://github.com/lostisland/faraday/blob/master/lib/faraday/request/authorization.rb
RDocで型情報が明示されていて便利
Instrumentation
instrumentとは…?
https://github.com/lostisland/faraday/blob/master/lib/faraday/request/instrumentation.rb
ActiveSupport::Notificationsでリクエストの送信をフックできるっぽい
yebis0942.icon optionは全ミドルウェアで共通っぽいけど、nameというオプションのキーって他と衝突しやすそう
TokenAuthentication
分け方こまかい
分けた方がよさそうな気もするけど理由を論理的に説明できなさそう
これはAuthorizationとは別で扱っていたけどそれをする理由がどこにあるのかドキュメント読まないとわからなそうな雰囲気でしたねluccafort.icon
middlewareの例みたいですね
https://github.com/lostisland/faraday_middleware
JSONとかXMLとかYAMLとかをパースしてくれるmiddleware
ちなみに会話でトレタのブログ呼んでmiddlewareの存在知ったというのは↓です
FaradayのClientErrorに苦しんだ話
yebis0942.iconさんがすごいいっぱい書いてくれて後から見返すときにめちゃくちゃ良かった。ありがとうございます!luccafort.icon