gcm-send-downstream 0.1.3 → 0.2.3

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 +62 -10
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca9e956cb171c2a20d4c88a8ea457cf37ba340c0
4
- data.tar.gz: 34d4b15ccb0144f80379b370d74404816880c7c8
3
+ metadata.gz: f8b18a22f13ca5106a3ae349a174f0445caa9cc9
4
+ data.tar.gz: 16932e81f52df1b55f3de19387c4482ab08ec31a
5
5
  SHA512:
6
- metadata.gz: da79ef181040cc5610bbbe645915abef72c5949e7a371eece75687f77421a0bf60ef9e035fa1436e9bb05a0989faba16651e7902cb864aab490a39644e4d8a89
7
- data.tar.gz: de4970e9e6e163d03db397626ca6838a2d41d8cc653b37fc7308fa615fbd46e5840d60bd78464a851099b2233108b003d1fa644165528e63845a2acdba12fef6
6
+ metadata.gz: 46e2c24b5c2030d70e4ead97e039b438e795b327398e338351bb99de17bf55e116dde18a6697de87f0881ebfee38a3cd44dfd0efb5698e120dfe8624f0c51230
7
+ data.tar.gz: 1f3e13b663c542ddb8dfe8bb65cd4b5e3e6b6cdcf16a121ab5d9034823a8f19ff647d89c58b4ab7af91eebdc3ae236cf855b2d2eddd779fe67ac32cb2148fcd6
@@ -1,7 +1,8 @@
1
1
  #
2
2
  # Push Message Send for Ruby (GCM 3.0)
3
3
  #
4
- # 2015. 12. 29
4
+ # last update 2016.01.20
5
+ #
5
6
  # hwj4477@gmail.com
6
7
  #
7
8
 
@@ -10,6 +11,9 @@ require 'json'
10
11
 
11
12
  class GcmSendDownstream
12
13
 
14
+ PLATFORM_IOS = "iOS"
15
+ PLATFORM_ANDROID = "Android"
16
+
13
17
  def initialize(auth_key, app_title)
14
18
 
15
19
  # GCM API KEY : https://developers.google.com/cloud-messaging/
@@ -18,31 +22,35 @@ class GcmSendDownstream
18
22
 
19
23
  end
20
24
 
21
- def send_message(registration_ids, message, silent = false, silent_data = nil)
25
+ def send_message(platform, registration_ids, message, data = nil)
26
+
27
+ params = nil
22
28
 
23
- unless silent
29
+ if platform == PLATFORM_IOS
24
30
 
25
31
  params = {
26
32
 
27
33
  'notification' => {'title' => @app_title,
28
- 'body' => message},
29
- 'data' => {'title' => @app_title,
30
- 'message' => message},
34
+ 'body' => message,
35
+ 'sound' => 'default'},
31
36
  'priority' => 'high',
32
37
  'registration_ids' => registration_ids
33
38
 
34
39
  }.to_json
35
40
 
41
+ params['data'] = data if data
42
+
36
43
  else
37
44
 
38
45
  params = {
39
-
40
- 'data' => silent_data,
41
- 'registration_ids' => registration_ids,
42
- 'content_available' => true
46
+ 'data' => {'title' => @app_title,
47
+ 'message' => message},
48
+ 'registration_ids' => registration_ids
43
49
 
44
50
  }.to_json
45
51
 
52
+ params['data'].merge(data) if data
53
+
46
54
  end
47
55
 
48
56
  uri = URI.parse("https://gcm-http.googleapis.com")
@@ -77,5 +85,49 @@ class GcmSendDownstream
77
85
  end
78
86
 
79
87
  end
88
+
89
+ def send_message_silent(platform, registration_ids, data = nil)
90
+
91
+ params = {
92
+
93
+ 'data' => data,
94
+ 'registration_ids' => registration_ids,
95
+ 'priority' => 5,
96
+ 'content_available' => true
97
+
98
+ }.to_json
99
+
100
+ uri = URI.parse("https://gcm-http.googleapis.com")
101
+ http = Net::HTTP.new(uri.host, uri.port)
102
+ http.use_ssl = true
103
+
104
+ request = Net::HTTP::Post.new("/gcm/send")
105
+ request.add_field("Authorization", "key=#{@auth_key}")
106
+ request.add_field("Content-Type", "application/json")
107
+ request.body = params
108
+ response= http.request(request)
109
+
110
+ # Json Parse
111
+ begin
112
+
113
+ results = JSON.parse(response.body)
114
+
115
+ rescue JSON::ParserError => e
116
+
117
+ str_error = "JSON Parse Error (#{e})"
118
+ yield false, str_error
119
+ return
120
+
121
+ end
122
+
123
+ gcm_results = results["results"]
124
+
125
+ gcm_results.each_with_index do |gcm_result, index|
126
+
127
+ yield true, gcm_result
128
+
129
+ end
130
+
131
+ end
80
132
 
81
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcm-send-downstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hwj4477
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Send Downstream Message For GCM 3.0
14
14
  email: hwj4477@gmail.com
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.4.6
40
+ rubygems_version: 2.4.8
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: GCM