1

私はファラデーに .rb ファイルから Google Calander への POST リクエストをさせることができました。アプリでこの機能を使用して、ユーザーが日付を選択した後、利用可能な時間帯のリストをユーザーに表示する前に、カレンダーの空き時間情報を確認したいと考えています。

response = Faraday.post do |req|
req.url 'https://www.googleapis.com/calendar/v3/freeBusy?key=myapikey'
req.headers['Content-Type'] = 'application/json'
req.body = '{ "items": [ { "id": mycalendar } ], "timeMin": "2011-02-14T00:09:35Z", "timeMax": "2011-02-14T00:09:40Z" }'
end

関数を予定モデルに配置し、ユーザーが日付を選択したときに AJAX 呼び出しを行うのが最善ですか? それとも、すべてをローカルテーブルに事前にキャッシュする方がよいでしょうか?

助けてくれてありがとう!

4

1 に答える 1

1

最初の試み:

require 'faraday'

class Booking < ActiveRecord::Base

def checktime(calid)

  response = Faraday.post do |req|
    req.url 'https://www.googleapis.com/calendar/v3/freeBusy?key=AIzaSyBsObpXXF6DQoZWj2U9QxoEQ4vdZ6GvNfI'
    req.headers['Content-Type'] = 'application/json'
    req.body = "{ 'items': [ { 'id': '#{calid}' } ], 'timeMin': '2012-02-19T19:35:00Z', 'timeMax': '2012-02-19T19:40:00Z' }"
  end

response_json = JSON.parse response.body

if response_json["calendars"]["busy"] == nil 
  return true
else
  return false
end

end
于 2012-02-19T23:12:36.220 に答える