Created
September 4, 2016 05:54
-
-
Save kakijin/37a85b6f1cfd581e5f903863c43c30bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'time' | |
| require 'pp' | |
| require './google-api-calender.rb' | |
| include GoogleApi | |
| def event_cron | |
| google_client = GoogleApi.authorize | |
| service = google_client.initialize_api | |
| # 第2引数には取得するイベントの数を指定 | |
| response = google_client.fetch_calender(service, 6) | |
| locations = Array.new | |
| response.items.each do |event| | |
| # start = event.start.date || event.start.date_time | |
| start = event.start.date_time | |
| time_start = start.strftime('%Y-%m-%d %H:%M') | |
| # 終了時刻30分以内のイベントがあればそのイベントの場所を返す. | |
| locations.push(event.location) if (Time.now-1800 < Time.parse(time_start)) && (Time.parse(time_start) < Time.now) | |
| end | |
| pp locations | |
| end | |
| event_cron |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment