Ruby の Twitter gem で DM を取得するときの注意点 (REST API)

結論

初回は @client.direct_messages_events(count: 1) で取得し、その戻り値から next_cursor を得て、それを用いて次回は @client.direct_messages_events(count: 1, cursor: next_cursor) で取得します。

next_cursornil が返ってきたら取得完了です。

普通に取得すると(なぜか)いきなり Rate limits に達して 15分間 身動きが取れなくなります。理由は次のとおりです。

github.com

material-table を使う際に検索欄やページングカーソル欄に se や fir などのアルファベットが表示される場合の対処法

material-table とは

github.com

現象

こういう感じになる現象です。

gyazo.com

結論

fonts.googleapis.com から Material Icons をインポートしましょう。

<head></head> 内に以下を書き加えます*1

    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/icon?family=Material+Icons"
    />

修正結果

上記のインポートの結果、以下のようになりました。

gyazo.com

補足

Issue にも上がっていました。

github.com

*1:大抵の場合は public/index.html に書くことになると思います

Ruby で Google API を google-api-ruby-client を使って操作する際に Google::Apis::TransmissionError が出る場合の対応

結論

リトライをする(こちらのせいではない)*1

具体的方法

以下にリトライをするための方法が書いてあります。

github.com

client.request_options.retries = 3

*1:ただし、アルゴリズムが悪いことなどが原因のことはある

GitHub Actions で RSpec (Capybara) を実行するための driven_by の options 引数の設定

現象

次のようなエラーが出る場合の対処法です。

            Selenium::WebDriver::Error::UnknownError:
              unknown error: Chrome failed to start: exited abnormally.
                (unknown error: DevToolsActivePort file doesn't exist)
                (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

結論

options 引数に以下の2つを追加します。

  • --disable-dev-sim-usage
  • --no-sandbox

具体的には、spec/rails_helper.rb に以下のように記述することになるでしょう。なお、options 引数の追加においては、以下のようにブロックで追加しないと deprecated と怒られます。

RSpec.configure do |config|
(省略)
  config.before(:each, type: :system) do |example|
    driven_by :selenium, screen_size: [1400, 1400], using: :headless_chrome do |options|
      options.add_argument('--disable-dev-sim-usage')
      options.add_argument('--no-sandbox')
    end
  end
(省略)
end

GitHub Actions でアーティファクトを保存するときには with: name: をアルファベットにしないと "Computed hash does not match with url signature" になる

結論

以下のように書くと、アーティファクトのリンクをクリックした先で Computed hash does not match with url signature というエラーが出ます*1

(省略)
    - name: アーティファクトの保存を行う
      if: failure()
      uses: actions/upload-artifact@v1
      with:
        name: テストのエラー画像
        path: tmp/screenshots
(省略)

日本語を使わないで以下のように書くと OK です。

(省略)
    - name: アーティファクトの保存を行う
      if: failure()
      uses: actions/upload-artifact@v1
      with:
        name: Error screenshots
        path: tmp/screenshots
(省略)

*1:アーティファクトの step 自体は正しく終了し、リンク先も生成される

Powered by はてなブログ