Module: MicrosoftPushNotificationService
- Defined in:
- lib/ruby-mpns.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.extended(base) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ruby-mpns.rb', line 7 def self.extended(base) unless base.respond_to?(:device_uri) base.class.class_eval do attr_accessor :device_uri end end end |
.send_notification(uri, type, options = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ruby-mpns.rb', line 15 def self.send_notification(uri, type, = {}) device = Object.new device.extend MicrosoftPushNotificationService device.device_uri = uri device.send_notification type, end |
Instance Method Details
#send_notification(type, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby-mpns.rb', line 22 def send_notification(type, = {}) type = safe_type_to_sym(type) notification, notification_class = build_notification(type, ) uri = URI.parse(self.device_uri) request = Net::HTTP::Post.new(uri.request_uri) request.content_type = 'text/xml' request['X-WindowsPhone-Target'] = windowsphone_target_header_for_type(type) request['X-NotificationClass'] = notification_class request.body = notification request.content_length = notification.length Net::HTTP.start(uri.host, uri.port) { |http| http.request request } end |