2014-02-06 28 views
2

我已經在Github上使用Google API Ruby客戶端example repo作爲我的日曆應用程序的起點。Google API ruby​​客戶端顯然不能獲取所有事件

它運作良好,通常沒有問題。然而,最近我注意到我製作的應用程序不能獲取所有事件。在通過ruby客戶端請求幾個日曆之後,我在表格中呈現事件。在我最初的通話中,只有我使用我的應用程序生成的日期,根本沒有從日曆中獲取數據。在第二次請求時,某些日曆將返回數據並重新加載該應用幾次,所有日曆都將返回事件。

對我來說,似乎有一些緩存正在進行。如果數據沒有足夠快地返回,空的響應會被髮回給我。請求再次發送一些數據,並且我請求返回的數據越多。

也許有什麼毛病我的設置這是不完美,但我認爲:

get '/' do 
    #fetch all calendars 
    result = api_client.execute(:api_method => calendar_api.calendar_list.list, 
           :authorization => user_credentials) 
    cals = result.data.items.map do |i| 
    #skip id calendar does not belong to owner or is the "private" primary one 
    next if i.primary || i.accessRole != "owner" 
    i.summary 
    end 
    cals.compact! 
    #save all users mentioned in calendars in a set 
    events_list = result.data.items.map do |i| 
    #skip calendar if primary or not owned by user (cannot be changed anyway) 
    next if i.primary || i.accessRole != "owner" 
    r = api_client.execute(:api_method => calendar_api.events.list, 
          :parameters => {'calendarId' => i.id}, 
          :timeMax => DateTime.now.next_month, 
          :timeMin => DateTime.now.beginning_of_month) 
    #capture all calendars and their events and map it to an Array 
    r.data.items.delete_if { |item| item.status == "cancelled" } 
    end 
    #remove skipped entries (=nil) 
    events_list.compact! 
    slim :home, :locals => { :title => Konfig::TITLE, :events_list => events_list, :cals => cals} 
end 

BTW:timeMax和:時間min不按預期工作要麼但是這是一個不同的問題,我想。

回答

2

代碼在這裏似乎不是問題。

我猜下面的一個正在發生的事情

  1. 您正在率有限? (不太可能通過smaple應用程序達到極限,但易於檢查響應代碼)
  2. 加載時間超過2秒(默認網絡http響應超時爲2秒,默認法拉第設置爲網絡:http)

我會在這種情況下做什麼。我就決定之前,以下下一步計劃

  1. 打印從它的響應對象的API客戶端寶石響應對象錯誤代碼和HTTP標頭。我會尋找什麼樣的緩存標題作爲迴應,以及狀態碼是什麼。

  2. 如果您的生產機器上有ngrep,只需讓它打印並顯示整個http請求響應,而不是將其打印到gem中。

  3. 如果響應時間超過2秒,請增加net :: http的超時設置並檢查。

+0

非常感謝。不能真正複製我自己的錯誤,但你的答案對我來說很有意義,所以我想我會獎勵你50分:) – three

相關問題