agilibox 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9afd5fa0b38899ffcac6b91b77a4f3b1809d00e11826ea887bdc9ee40cb73c27
4
- data.tar.gz: 4f5cc4e36f0c50fbead856f2bbeba35db23bba0952a2ea4fa1c6c5a3dec2f3a7
3
+ metadata.gz: cd2407ff1f5524e74f7fc5bf7e52c83d4be361331191066ca426e2ae3a6bc56e
4
+ data.tar.gz: 84485258fee15107d33af7ec443b7055b8d7498fe94a7924ac72ae7a78284b09
5
5
  SHA512:
6
- metadata.gz: e5aba37b08a4fe936afee156cd1138a7881a468d7210498482e5b662ab57db3d93c7421486f5e5261a65afe54953c2ec85ba4fd1af27e4ec2034923130125118
7
- data.tar.gz: 3d889541d3fc5f8167618db3d75c5344a737b1813de715f7118e7c7448e620648a2e125fa2e25639a81d7d9216e690f173880a27059dc3b9591ff0573ba6c54d
6
+ metadata.gz: 5011a1818ddd1524ebb4f37dc3a5743988649f84e08815a33c45b2c74376fec9c07f593dd7709e847927efbbbe116aa67980a760ab33c554a526b8bd153e521a
7
+ data.tar.gz: 5d37cd97225e112e9e91df02a9280cdb78105ed1031f27c85b9b4004f9bc3a5d73a26e6c45e7d71d85e06ff203902166eec5f79321440c9cda28fef337ea55d2
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3
4
+
5
+ - Add FCM
6
+
3
7
  ## 1.2.2
4
8
 
5
9
  - Add CollectionUpdate
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Agilibox
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
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.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-05-12 00:00:00.000000000 Z
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