Ruby でODBC 経由でStreak に接続して、モダンなクラウド連携アプリを開発。
CData ODBC Driver for Streak を使うと、簡単にRuby アプリケーションにリアルタイムStreak データを連携・統合できます。 Tこの記事では、Streak] データにリアルタイムに連携するRuby アプリケーションを構築して、クエリを実行し、結果を表示してみます。
Streak データのODBC 接続を設定
通常はCData ODBC Driver のインストール後にODBC DSN 接続ウィザードが立ち上がり、設定を行うことができます。 もしODBC DSN 接続が未済の場合には、Microsoft ODBC データソースアドミニストレータでODBC DSN を作成および設定することができます。
Use the following steps to generate a new API key for authenticating to Streak.
- Navigate to Gmail
- Click on the Streak dropdown to the right of the search bar
- Select the Integrations button. This will open a window where you can view existing integrations and create new API keys.
- Under the Streak API section of integrations, click the button to Create New Key.
Ruby および必要なGem のインストール
If you do not have Ruby installed, refer to the Ruby インストールページ. Ruby をインストールしたら、次にruby-dbi、dbd-odbc、ruby-odbc gems をインストールします:
gem install dbi
gem install dbd-odbc
gem install ruby-odbc
Streak データに連携するRuby アプリケーションの作成
Ruby ファイル (例: StreakSelect.rb) を作成し、テキストエディタで開きます。ファイルに次のコードをコピーします:
#connect to the DSN
require 'DBI'
cnxn = DBI.connect('DBI:ODBC:CData Streak Source','','')
#execute a SELECT query and store the result set
resultSet = cnxn.execute("SELECT UserKey, Email FROM Users WHERE Email = 'user@domain.com'")
#display the names of the columns
resultSet.column_names.each do |name|
print name, "\t"
end
puts
#display the results
while row = resultSet.fetch do
(0..resultSet.column_names.size - 1).each do |n|
print row[n], "\t"
end
puts
end
resultSet.finish
#close the connection
cnxn.disconnect if cnxn
これで、Ruby で Streak データが接続できるようになります。簡単にコマンドラインからファイルを叩いて接続を確認してみましょう。:
ruby StreakSelect.rb
Streak へのSQL-92 企画のSQL を使って、Ruby に簡単にStreak を連携できます。是非、トライアルで試してみてください。