gcm-send-downstream 0.1.0 → 0.1.1

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 +4 -4
  2. data/lib/gcm-send-downstream.rb +75 -2
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 048767515de5c63785918e27b29e4e8dcc387fcd
4
- data.tar.gz: 46d99e08f8b99ff0fcde280b957d9676c88eadc6
3
+ metadata.gz: a15aee428e54f3e68f7728a9bbae95f5d84a8b42
4
+ data.tar.gz: e08aaed444b714fb6c7b7c73232470a74a063dd5
5
5
  SHA512:
6
- metadata.gz: e0ae8a640c0a7fad7eca363fb6d821fc795733b18e5d4c07be766fe023b78c659f42845a6d09fed08602c0b5afbdf29f4a8b80245c8ea0b30430475ccbad3d75
7
- data.tar.gz: 7f0ab7182f045b5868495ee13588bead5c79e97e04c74ec841a35bed398609cbc209e1816e2e9b46c3979e9704d5b7e0e5a7e6c19bb49d685be85e5156c7d344
6
+ metadata.gz: 330945c6cb6b069a09ae4a419b683acd7ddddf4355707e3b7c43cff7c6f4c3edd24e8ac8876ba2992ba3ab52d82cab609b6c0a0ebebe8bec69892b6bff6f5f91
7
+ data.tar.gz: 8a2073d10a2929e6720e4d3bfaa0249720e8cfc768486473117a57fb139113e6ac4d51de0f7905a0f9f4f445ce008e79366a7fb73608f7c99cf9a399a079c52c
@@ -1,7 +1,80 @@
1
+ #
2
+ # Send Downstream Message For GCM 3.0
3
+ #
4
+ # 2015. 12. 29
5
+ # hwj4477@gmail.com
6
+ #
7
+
8
+ require 'net/http'
9
+ require 'json'
10
+
1
11
  class GcmSendDownstream
2
12
 
3
- def initialize
4
- puts "test"
13
+ def initialize(auth_key, app_title)
14
+
15
+ # GCM API KEY : https://developers.google.com/cloud-messaging/
16
+ @auth_key = auth_key
17
+ @app_title = app_title
18
+
19
+ end
20
+
21
+ def send_message(registration_ids, message, silent = false, silent_data = nil)
22
+
23
+ unless silent
24
+
25
+ params = {
26
+
27
+ 'notification' => {'title' => @app_title,
28
+ 'body' => message},
29
+ 'data' => {'title' => @app_title,
30
+ 'message' => message},
31
+ 'registration_ids' => registration_ids
32
+
33
+ }.to_json
34
+
35
+ else
36
+
37
+ params = {
38
+
39
+ 'data' => silent_data,
40
+ 'registration_ids' => registration_ids,
41
+ 'content_available' => true
42
+
43
+ }.to_json
44
+
45
+ end
46
+
47
+ uri = URI.parse("https://gcm-http.googleapis.com")
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ http.use_ssl = true
50
+
51
+ request = Net::HTTP::Post.new("/gcm/send")
52
+ request.add_field("Authorization", "key=#{@auth_key}")
53
+ request.add_field("Content-Type", "application/json")
54
+ request.body = params
55
+ response= http.request(request)
56
+
57
+ # Json Parse
58
+ begin
59
+
60
+ results = JSON.parse(response.body)
61
+
62
+ rescue JSON::ParserError => e
63
+
64
+ str_error = "JSON Parse Error (#{e})"
65
+ yield false, str_error
66
+ return
67
+
68
+ end
69
+
70
+ gcm_results = results["results"]
71
+
72
+ gcm_results.each_with_index do |gcm_result, index|
73
+
74
+ yield true, gcm_result
75
+
76
+ end
77
+
5
78
  end
6
79
 
7
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcm-send-downstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - wjhong
@@ -17,9 +17,9 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/gcm-send-downstream.rb
20
- homepage: http://rubygems.org/gems/gcm-send-downstream
20
+ homepage: http://github.com/hwj4477/gcm-send-downstream
21
21
  licenses:
22
- - hwj4477@gmail.com
22
+ - wjhong
23
23
  metadata: {}
24
24
  post_install_message:
25
25
  rdoc_options: []