Method: Unipush::WinPhone_push#send_tile

Defined in:
lib/unipush.rb

#send_tile(device_urls, title, bg_image, count, back_title = nil, back_text = nil, back_bg_image = nil) ⇒ Object

send_tile()



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/unipush.rb', line 362

def send_tile(device_urls, title,  bg_image, count, back_title=nil, back_text=nil, back_bg_image=nil)
  if device_urls && title
    builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
      xml['wp'].Notification('xmlns:wp'=>'WPNotification') do
        xml['wp'].Tile{
          xml['wp'].BackgroundImage{
            xml.text bg_image
          }
          xml['wp'].Title{
            xml.text title
          }
          xml['wp'].Count{
            xml.text count.to_s
          }

          if back_title
            xml['wp'].BackTitle{
              xml.text back_title
            }
          end

          if back_text
            xml['wp'].BackContent{
              xml.text back_text
            }
          end

          if back_bg_image
            xml['wp'].BackBackgroundImage{
              xml.text back_bg_image
            }
          end
        }
      end
    end

    content =  builder.to_xml
    puts content

    headers = {
        'X-WindowsPhone-Target' => 'token',
        'Content-Type' => 'text/xml',
        'X-NotificationClass' => '1',
        'Content-Length' => content.bytesize.to_s
    }

    send_message(headers, content, device_urls)
  else
    @last_error.push('no data')
    false
  end
end