Created
October 14, 2009 12:44
-
-
Save mattman/210028 to your computer and use it in GitHub Desktop.
This file contains 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
# This models purpose is to sit there and observe | |
# (by usinging the observable gem from James Golick) | |
# changes to the time of games and action as needed | |
class Contact | |
Contact::SMSACTIVE = true | |
observes :game, :invokes => :notify_players, :after => :update | |
def self.notify_players(game) | |
now = Time.now | |
# give me an integer respresentation (no decimal places) of the time between now and the match | |
timespan = (game.played_at - now).to_i | |
if timespan < 3.hours | |
# SMS the user | |
Contact.send_later(:send_change_notification_sms, game) # send a DJ worker the signal to queue this job up for sending | |
else | |
# email the user | |
Contact.send_later(:send_change_notification_email, game) # send a DJ worker the signal to queue this job up for sending | |
end | |
end | |
def self.send_change_notification_sms(game) | |
if SMSACTIVE | |
players = find_players(game) | |
players.each do |player| | |
SMS.send(game, player) | |
end | |
else | |
puts "SMS IS NOT CURRENTLY TURNED ON FOR #{RAILS_ENV} - you can update this in the resepective config/environment/#{RAILS_ENV.downcase}.rb file" | |
end | |
end | |
def self.send_change_notification_email(game) | |
players = find_players(game) | |
players.each do |player| | |
ChangeMailer.deliver_timechange_email(player, game) | |
end | |
end | |
def self.find_players(game) | |
[game.team_home.players, game.team_away.players].flatten! | |
end | |
end |
This file contains 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 'httparty' | |
class SMS | |
include HTTParty | |
def self.send(game, player) | |
if !player.mobile.nil? | |
message = "Hey #{player.name_first},\nYour game for today has changed! Details are\n Time: #{game.played_at.strftime("%H:%M")}\n Venue:#{game.venue.loc_name}" | |
message = CGI::escape(message) | |
url = "http://sms.didcoe.id.au/sendto/#{api}/#{player.mobile}/#{message}" | |
res = get(url) | |
res != "Fuck off :)" ? true : false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment