notify_fcm 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/notify_fcm.rb +30 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 885382826b2ac52f658988a86f5aef9d17933e8e
|
|
4
|
+
data.tar.gz: 511b3807c550f4783426ba2242f40fb2826e8052
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58171aa048377edf01f7976ffb987bb5be4376fd8d0d6b06f9e5901622e59fb1f98055d758e1e03de65a9e251bee3876079693881ad7701e85716ae020c2dddc
|
|
7
|
+
data.tar.gz: ee9250641f70932a247db26ad722a8cf647b39c7b3e4f16f1bf9503a077836fddaf5ca691b8b2ba0a9ef036130639ba3071a8a593792f683b9efe9fb0ede08aa
|
data/lib/notify_fcm.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'httparty'
|
|
2
2
|
require 'uri'
|
|
3
3
|
require 'json'
|
|
4
|
+
require 'cgi'
|
|
4
5
|
|
|
5
6
|
class NOTIFY_FCM
|
|
6
7
|
include HTTParty
|
|
@@ -18,7 +19,8 @@ class NOTIFY_FCM
|
|
|
18
19
|
|
|
19
20
|
raise ArgumentError, 'Api Key not Found' unless !@api_key.nil?
|
|
20
21
|
raise ArgumentError, 'Body is missing' unless !body.nil?
|
|
21
|
-
|
|
22
|
+
raise ArgumentError, 'DeviceToken not Found' unless !registration_ids.empty?
|
|
23
|
+
|
|
22
24
|
message = message_body()
|
|
23
25
|
body = build_body(registration_ids, message)
|
|
24
26
|
params = {
|
|
@@ -30,8 +32,7 @@ class NOTIFY_FCM
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
response = self.class.post('/send', params.merge(@options))
|
|
33
|
-
|
|
34
|
-
# build_response(response, registration_ids)
|
|
35
|
+
response_builder(response)
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
alias send send_notification
|
|
@@ -44,6 +45,32 @@ class NOTIFY_FCM
|
|
|
44
45
|
{notification: { body: body, title: title}}
|
|
45
46
|
end
|
|
46
47
|
|
|
48
|
+
def response_builder(response)
|
|
49
|
+
parse_response(response)
|
|
50
|
+
end
|
|
47
51
|
|
|
52
|
+
def parse_response(response_body)
|
|
53
|
+
response_data = {}
|
|
54
|
+
res_body = response_body.body || {}
|
|
55
|
+
case response_body.code
|
|
56
|
+
when 200
|
|
57
|
+
body = JSON.parse(res_body) unless res_body.empty?
|
|
58
|
+
response_data[:status] = 'success'
|
|
59
|
+
response_data[:response] = body || {}
|
|
60
|
+
when 400
|
|
61
|
+
response_data[:status] = 'failed'
|
|
62
|
+
response_data[:response] = 'Json Fields are invalid'
|
|
63
|
+
when 401
|
|
64
|
+
response_data[:status] = 'failed'
|
|
65
|
+
response_data[:response] = 'Authentication Error!'
|
|
66
|
+
when 503
|
|
67
|
+
response_data[:status] = 'failed'
|
|
68
|
+
response_data[:response] = 'Server is temporarily unavailable.'
|
|
69
|
+
when 500..599
|
|
70
|
+
response_data[:status] = 'failed'
|
|
71
|
+
response_data[:response] = 'FCM internal server error!'
|
|
72
|
+
end
|
|
73
|
+
response_data
|
|
74
|
+
end
|
|
48
75
|
|
|
49
76
|
end
|