unipush 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/unipush.rb +106 -1
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmUyZDE1OGVlMDQ2NTZlMTE0MTBiOTFjY2EyNzExYWU1NzdkNWYzMA==
4
+ ZjMxOWZhZTA5MWY1MzAwOGFhOGUxZWE3ZDhkYTc0ZmQ0NDFjOWVlZA==
5
5
  data.tar.gz: !binary |-
6
- ZDcxM2QzMTUxYTY5ZmFiODg1YzNlM2UxMDYxNjk2MWQ2NTI4NmEyZA==
6
+ Y2ZiZTY0MDhiYzhiNzkwNWIwNzhlYzFjNjgzNmI4ZGQxY2VjYzY3MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDg5Mzg5ZTU5Y2QwOWQxYTg3ZGNmYmQyOGZiYjdlMjQxYjZjMDVmMDg2NWU3
10
- ODU0N2UxMjkwZDU2YTdiMThmYzFhZGEyYTgxOGYwYzMyMGQxZjQ1MjM2ZDUy
11
- Mzg2MDEyODVmYjk4MjBkYTFlMTUwMzZiYWIzOTE2MzVkYjQ5YjA=
9
+ YjhjZThmMTBjNTMzZDBlMTZmODc2OTNkYzQ0YTZlMzM1NzAyZTRjNTk4Y2Q3
10
+ M2YxNjI1NDM4NGZhYjZiNzM2NWEyYWE3NzE3MmZjNjUxMmNkNzBhODM1YzNh
11
+ MmMwMDVjOGNhZDU5YTA3OTdjY2RmOWM2MWJmY2M1MjI4NGFmY2M=
12
12
  data.tar.gz: !binary |-
13
- YjFiYTVjMDRjMDhkYjEzMmU4M2FlNDAzYjBkNTM5OGQxZGQ2ZWMyNzI5YmVh
14
- Y2Q4OThlZDU3M2ZkMzdkMTM4NzhhYWZmOWM1Nzk5YWM4NTAwMTZhZTY0NDUx
15
- M2FiNDhjMWZlMzBjOGNkZDc0NDM4NzhkNmE4OTFhNWY1MGVkYzQ=
13
+ MWRmMzI5NDBlNDJmZWEwZGE2Y2Q5MmJhOWNiY2U3ZDcwMGI5NTNlZTE5Mzg5
14
+ ZDJmNTE2NzBlM2E3ZTQ3YjM5ZWJjZmI3NjRiNjdlMTQwMDQ2N2MwZDYxNTk3
15
+ NDRhNjE2Njg5Nzg5MmQxZTNlMGE4ZmUwMmE2YmU4MzllZDBmNDM=
data/lib/unipush.rb CHANGED
@@ -3,7 +3,7 @@ require 'socket'
3
3
  require 'active_support/core_ext'
4
4
  require 'net/http'
5
5
  require 'net/https'
6
- require 'nokogiri'
6
+ #require 'nokogiri'
7
7
 
8
8
  module Unipush
9
9
  ## APNS
@@ -480,4 +480,109 @@ module Unipush
480
480
  end
481
481
 
482
482
  end
483
+
484
+
485
+
486
+
487
+ class Win_push
488
+ def initialize(client_id, client_secret)
489
+ @client_id = client_id
490
+ @client_secret = client_secret
491
+
492
+ @auth_token_url = 'https://login.live.com/accesstoken.srf'
493
+ @access_token = nil
494
+
495
+ @last_error = []
496
+ end
497
+
498
+
499
+ def send_toast(text, uris)
500
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
501
+ xml.toast{
502
+ xml.visual{
503
+ xml.binding('template'=>'toastText01') do
504
+ xml.text_('id'=>'1') do
505
+ xml.text text
506
+ end
507
+ end
508
+ }
509
+ }
510
+ end
511
+
512
+ content = builder.to_xml
513
+
514
+ headers = {
515
+ 'X-WNS-Type' => 'wns/toast',
516
+ 'Content-Type' => 'text/xml',
517
+ 'Content-Length' => content.bytesize.to_s,
518
+ 'X-WNS-RequestForStatus' => 'true'
519
+ }
520
+
521
+ send_messages(headers, content, uris)
522
+ end
523
+
524
+
525
+ def send_tile(content, uris)
526
+ headers = {
527
+ 'X-WNS-Type' => 'wns/tile',
528
+ 'Content-Type' => 'text/xml',
529
+ 'Content-Length' => content.bytesize.to_s,
530
+ 'X-WNS-RequestForStatus' => 'true'
531
+ }
532
+
533
+ send_messages(headers, content, uris)
534
+ end
535
+
536
+
537
+ private
538
+
539
+ def send_messages(headers, content, device_uris)
540
+ get_access_token unless @access_token
541
+
542
+ ret = []
543
+ threads = []
544
+ Thread.abort_on_exception = false
545
+ device_uris.each do |du|
546
+ threads << Thread.new do
547
+ uri = URI.parse(du)
548
+ http = Net::HTTP.new(uri.host, uri.port)
549
+
550
+ headers['Authorization'] = "Bearer #{@access_token}"
551
+ headers['Host'] = uri.host
552
+
553
+ http.use_ssl = true
554
+
555
+ response = http.post(du, content, headers)
556
+
557
+ puts uri.path, response.code
558
+
559
+ if response.code == '401'
560
+ get_access_token
561
+ end
562
+
563
+ ret.push(response)
564
+ end
565
+ end
566
+ threads.each {|thr| thr.join}
567
+ ret
568
+ end
569
+
570
+ def get_access_token
571
+ uri = URI.parse(@auth_token_url)
572
+ http = Net::HTTP.new(uri.host, uri.port)
573
+ http.use_ssl = true
574
+ body = "grant_type=client_credentials&client_id=#{@client_id}&client_secret=#{@client_secret}&scope=notify.windows.com"
575
+ headers = {
576
+ 'Content-Type' => 'application/x-www-form-urlencoded',
577
+ 'Host' => 'login.live.com',
578
+ 'Content-Length' => body.bytesize.to_s
579
+ }
580
+
581
+ response = http.post(uri.path, body, headers)
582
+ if response.code == '200'
583
+ resp = JSON.parse(response.body)
584
+ @access_token = resp['access_token']
585
+ end
586
+ end
587
+ end
483
588
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unipush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Kirov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2014-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple push notification sender for iOS, Android and Windows phone
14
14
  email: alexey.s.kirov@gmail.com