class Ruboty::Sanfrecce::Client
Public Class Methods
new()
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 9 def initialize load_env @client = Google::APIClient.new(:application_name => '') @client.authorization = Signet::OAuth2::Client.new( :token_credential_uri => 'https://accounts.google.com/o/oauth2/token', :audience => 'https://accounts.google.com/o/oauth2/token', :scope => 'https://www.googleapis.com/auth/calendar.readonly', :issuer => ENV['ISSUER'], :signing_key => key) @client.authorization.fetch_access_token! end
Public Instance Methods
last_game()
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 27 def last_game items = request(DateTime.now - 365, DateTime.now) return get_game(items.last) end
next_game()
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 22 def next_game items = request(DateTime.now, DateTime.now + 365) return get_game(items.first) end
Private Instance Methods
get_game(item)
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 57 def get_game(item) title = item.summary time = item.start.date unless time time = item.start.dateTime.strftime("%Y/%m/%d %H:%M") end return "#{title}, #{time} KICK OFF" end
key()
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 34 def key Google::APIClient::KeyUtils.load_from_pkcs12(ENV['FILE_NAME'], ENV['SECRET_KEY']) end
load_env()
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 53 def load_env Dotenv.load end
request(min, max)
click to toggle source
# File lib/ruboty/sanfrecce/client.rb, line 38 def request(min, max) # イベント取得 cal = @client.discovered_api('calendar', 'v3') params = {'calendarId' => ENV['CALENDAR_ID'], 'orderBy' => 'startTime', 'timeMax' => max, 'timeMin' => min, 'singleEvents' => 'True'} result = @client.execute(:api_method => cal.events.list, :parameters => params) return result.data.items end