Created
October 2, 2011 14:55
-
-
Save kylewelsby/1257517 to your computer and use it in GitHub Desktop.
How TxtVia Pushes
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
class Device < ActiveRecord::Base | |
... | |
def push_message(message) | |
case device_type | |
when "android" | |
notification = { :registration_id => registration_id, | |
:data => { | |
:message_body => message.body, | |
:message_recipient => message.recipient | |
} | |
} | |
android_push.send_notification(notification) | |
when "iphone" | |
# coming soon | |
when "hashblue" | |
hb = user.providers.find_by_provider('hash_blue') | |
HashBlueSR.send_message(message.recipient, | |
message.body, | |
hb.get_token) | |
when "api" | |
# ['exendex','other sms sercices'] | |
else | |
# This will push to all clients regardless of the message defined client. | |
# Beaconpush.user_message(user.authentication_token, :message => message.to_json) | |
Pusher["txtvia_#{user.authentication_token}"].trigger('message', message.to_json(:methods => [:messaged_at])) | |
end | |
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
class Message < ActiveRecord::Base | |
belongs_to :device, :conditions => "device_type != 'client'" | |
belongs_to :client, :class_name => "Device", :foreign_key => "client_id", :conditions => "device_type = 'client'" | |
after_create :push_to_device, :if => Proc.new { |message| !message.sent_at.nil? } | |
after_create :push_to_client, :if => Proc.new { |message| !message.received_at.nil? } | |
... | |
def push_to_client | |
device.user.clients.each do |client| | |
client.push_message(self) | |
end | |
end | |
def push_to_device#(device = self.device) | |
device.push_message(self) | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment