Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ability to use multi-level hash in raw notification

  • Loading branch information...
commit 4c7e68b0ea90091fbde8c7ec18f28bb87f012d71 1 parent 5f289ce
@dmedvinsky dmedvinsky authored
Showing with 38 additions and 20 deletions.
  1. +7 −5 lib/ruby-mpns.rb
  2. +31 −15 test/test_ruby-mpns.rb
View
12 lib/ruby-mpns.rb
@@ -106,14 +106,16 @@ def toast_notification_with_options(options = {})
def raw_notification_with_options options = {}
xml = Builder::XmlMarkup.new
xml.instruct!
- xml.root do
- options.each do |k, v|
- xml.tag!(k.to_s) { xml.text!(v.to_s) }
- end
- end
+ xml.root { build_hash(xml, options) }
[xml.target!, '3']
end
+ def build_hash(xml, options)
+ options.each do |k, v|
+ xml.tag!(k.to_s) { v.is_a?(Hash) ? build_hash(xml, v) : xml.text!(v.to_s) }
+ end
+ end
+
def format_params params = {}
return '' if params.nil?
query = params.collect { |k, v| k.to_s + '=' + v.to_s } * '&'
View
46 test/test_ruby-mpns.rb
@@ -49,14 +49,14 @@ class TestRubyMpns < Test::Unit::TestCase
navigation_uri: 'uri' })
assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' +
'<wp:Notification xmlns:wp="WPNotification">' +
- '<wp:Tile Id="uri">' +
- '<wp:BackgroundImage>bg</wp:BackgroundImage>' +
- '<wp:Count>1337</wp:Count>' +
- '<wp:Title>title</wp:Title>' +
- '<wp:BackBackgroundImage>bkbg</wp:BackBackgroundImage>' +
- '<wp:BackTitle>bktitle</wp:BackTitle>' +
- '<wp:BackContent>bkcontent</wp:BackContent>' +
- '</wp:Tile>' +
+ '<wp:Tile Id="uri">' +
+ '<wp:BackgroundImage>bg</wp:BackgroundImage>' +
+ '<wp:Count>1337</wp:Count>' +
+ '<wp:Title>title</wp:Title>' +
+ '<wp:BackBackgroundImage>bkbg</wp:BackBackgroundImage>' +
+ '<wp:BackTitle>bktitle</wp:BackTitle>' +
+ '<wp:BackContent>bkcontent</wp:BackContent>' +
+ '</wp:Tile>' +
'</wp:Notification>'
end
@@ -66,11 +66,11 @@ class TestRubyMpns < Test::Unit::TestCase
{ title: 'title', content: 'content', params: {} })
assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' +
'<wp:Notification xmlns:wp="WPNotification">' +
- '<wp:Toast>' +
- '<wp:Text1>title</wp:Text1>' +
- '<wp:Text2>content</wp:Text2>' +
- '<wp:Param>?</wp:Param>' +
- '</wp:Toast>' +
+ '<wp:Toast>' +
+ '<wp:Text1>title</wp:Text1>' +
+ '<wp:Text2>content</wp:Text2>' +
+ '<wp:Param>?</wp:Param>' +
+ '</wp:Toast>' +
'</wp:Notification>'
end
@@ -80,8 +80,24 @@ class TestRubyMpns < Test::Unit::TestCase
{ key1: 'val1', key2: 'val2' })
assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' +
'<root>' +
- '<key1>val1</key1>' +
- '<key2>val2</key2>' +
+ '<key1>val1</key1>' +
+ '<key2>val2</key2>' +
+ '</root>'
+ end
+
+ should 'make raw XML with nested tags' do
+ mpns = Object.new.extend MicrosoftPushNotificationService
+ xml, _ = mpns.send(:raw_notification_with_options,
+ { key1: 'val1', key2: { subkey1: 'subval1', subkey2: { subsubkey1: 'subsubval1' } } })
+ assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' +
+ '<root>' +
+ '<key1>val1</key1>' +
+ '<key2>' +
+ '<subkey1>subval1</subkey1>' +
+ '<subkey2>' +
+ '<subsubkey1>subsubval1</subsubkey1>' +
+ '</subkey2>' +
+ '</key2>' +
'</root>'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.