agilibox 1.2.2 → 1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/app/libs/agilibox/fcm/notifier.rb +27 -0
- data/app/libs/agilibox/fcm/request.rb +45 -0
- data/lib/agilibox/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd2407ff1f5524e74f7fc5bf7e52c83d4be361331191066ca426e2ae3a6bc56e
|
4
|
+
data.tar.gz: 84485258fee15107d33af7ec443b7055b8d7498fe94a7924ac72ae7a78284b09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5011a1818ddd1524ebb4f37dc3a5743988649f84e08815a33c45b2c74376fec9c07f593dd7709e847927efbbbe116aa67980a760ab33c554a526b8bd153e521a
|
7
|
+
data.tar.gz: 5d37cd97225e112e9e91df02a9280cdb78105ed1031f27c85b9b4004f9bc3a5d73a26e6c45e7d71d85e06ff203902166eec5f79321440c9cda28fef337ea55d2
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
class Agilibox::FCM::Notifier < Agilibox::Service
|
2
|
+
attr_reader :to, :title, :body, :badge, :sound, :data
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/ParameterLists
|
5
|
+
def initialize(to:, title: nil, body:, badge: 0, sound: "default", data: {})
|
6
|
+
@to = to
|
7
|
+
@title = title
|
8
|
+
@body = body
|
9
|
+
@badge = badge
|
10
|
+
@sound = sound
|
11
|
+
@data = data
|
12
|
+
end
|
13
|
+
# rubocop:enable Metrics/ParameterLists
|
14
|
+
|
15
|
+
def call
|
16
|
+
Agilibox::FCM::Request.call(
|
17
|
+
:to => to,
|
18
|
+
:notification => {
|
19
|
+
:title => title,
|
20
|
+
:body => body,
|
21
|
+
:badge => badge,
|
22
|
+
:sound => sound,
|
23
|
+
},
|
24
|
+
:data => data,
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Agilibox::FCM::Request < Agilibox::Service
|
2
|
+
URL = "https://fcm.googleapis.com/fcm/send"
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_writer :api_key
|
6
|
+
|
7
|
+
def api_key
|
8
|
+
@api_key ||= ENV["FCM_API_KEY"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
initialize_with :request_body
|
13
|
+
|
14
|
+
attr_reader :response_json
|
15
|
+
|
16
|
+
def call
|
17
|
+
response_body = HTTParty.post(URL,
|
18
|
+
:body => request_body.to_json,
|
19
|
+
:headers => {
|
20
|
+
"Content-Type" => "application/json",
|
21
|
+
"Authorization" => "key=#{self.class.api_key}",
|
22
|
+
},
|
23
|
+
).body
|
24
|
+
|
25
|
+
@response_json = JSON.parse(response_body).deep_symbolize_keys
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def ok?
|
31
|
+
response_json[:success] > 0 && response_json[:failure].zero?
|
32
|
+
end
|
33
|
+
|
34
|
+
def error?
|
35
|
+
!ok?
|
36
|
+
end
|
37
|
+
|
38
|
+
def errors
|
39
|
+
response_json[:results].map { |r| r[:error] }.compact
|
40
|
+
end
|
41
|
+
|
42
|
+
def invalid_token?
|
43
|
+
errors.include?("NotRegistered") || errors.include?("InvalidRegistration")
|
44
|
+
end
|
45
|
+
end
|
data/lib/agilibox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agilibox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agilidée
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails-i18n
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- app/helpers/agilibox/text_helper.rb
|
110
110
|
- app/helpers/h.rb
|
111
111
|
- app/libs/agilibox/collection_update.rb
|
112
|
+
- app/libs/agilibox/fcm/notifier.rb
|
113
|
+
- app/libs/agilibox/fcm/request.rb
|
112
114
|
- app/libs/agilibox/initialize_with.rb
|
113
115
|
- app/libs/agilibox/mini_model_serializer/serialize.rb
|
114
116
|
- app/libs/agilibox/mini_model_serializer/serializer.rb
|