onesignal-ruby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +57 -5
- data/.envrc +1 -0
- data/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/CODEOWNERS +1 -0
- data/README.md +12 -15
- data/fixtures/vcr_cassettes/os-csv-export.yml +135 -0
- data/fixtures/vcr_cassettes/os-fetch-notifications.yml +237 -0
- data/lib/onesignal.rb +32 -0
- data/lib/onesignal/buttons.rb +17 -0
- data/lib/onesignal/client.rb +14 -1
- data/lib/onesignal/commands/csv_export.rb +15 -0
- data/lib/onesignal/commands/fetch_notifications.rb +17 -0
- data/lib/onesignal/notification.rb +3 -1
- data/lib/onesignal/notification/contents.rb +1 -1
- data/lib/onesignal/notification/headings.rb +1 -1
- data/lib/onesignal/responses/base_response.rb +6 -1
- data/lib/onesignal/responses/csv_export.rb +18 -0
- data/lib/onesignal/segment.rb +1 -0
- data/lib/onesignal/version.rb +1 -1
- data/onesignal-ruby.gemspec +3 -3
- data/shell.nix +7 -0
- metadata +23 -15
- data/Gemfile.lock +0 -85
data/lib/onesignal.rb
CHANGED
@@ -27,6 +27,31 @@ module OneSignal
|
|
27
27
|
Responses::Notification.from_json fetched.body
|
28
28
|
end
|
29
29
|
|
30
|
+
def fetch_notifications(page_limit: 50, page_offset: 0, kind: nil)
|
31
|
+
return unless OneSignal.config.active
|
32
|
+
|
33
|
+
Enumerator.new() do |yielder|
|
34
|
+
limit = page_limit
|
35
|
+
offset = page_offset
|
36
|
+
|
37
|
+
fetched = Commands::FetchNotifications.call limit, offset, kind
|
38
|
+
parsed = JSON.parse(fetched.body)
|
39
|
+
|
40
|
+
total_count = parsed["total_count"]
|
41
|
+
max_pages = (total_count / limit.to_f).ceil
|
42
|
+
|
43
|
+
loop do
|
44
|
+
parsed['notifications'].each do |notification|
|
45
|
+
yielder << Responses::Notification.from_json(notification)
|
46
|
+
end
|
47
|
+
offset += 1
|
48
|
+
break if offset >= max_pages
|
49
|
+
fetched = Commands::FetchNotifications.call limit, offset*limit, kind
|
50
|
+
parsed = JSON.parse(fetched.body)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
30
55
|
def fetch_player player_id
|
31
56
|
return unless OneSignal.config.active
|
32
57
|
|
@@ -41,6 +66,13 @@ module OneSignal
|
|
41
66
|
JSON.parse(fetched.body)['players'].map { |player| Responses::Player.from_json player }
|
42
67
|
end
|
43
68
|
|
69
|
+
def csv_export params = {}
|
70
|
+
return unless OneSignal.config.active
|
71
|
+
|
72
|
+
fetched = Commands::CsvExport.call params
|
73
|
+
Responses::CsvExport.from_json fetched.body
|
74
|
+
end
|
75
|
+
|
44
76
|
def config
|
45
77
|
@config ||= Configuration.new
|
46
78
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
class Buttons
|
5
|
+
attr_reader :buttons
|
6
|
+
|
7
|
+
def initialize buttons: nil
|
8
|
+
@buttons = buttons
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json options = nil
|
12
|
+
{
|
13
|
+
'buttons' => @buttons.as_json(options),
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/onesignal/client.rb
CHANGED
@@ -27,6 +27,12 @@ module OneSignal
|
|
27
27
|
get "notifications/#{notification_id}"
|
28
28
|
end
|
29
29
|
|
30
|
+
def fetch_notifications page_limit: 50, page_offset: 0, kind: nil
|
31
|
+
url = "notifications?limit=#{page_limit}&offset=#{page_offset}"
|
32
|
+
url = kind ? "#{url}&kind=#{kind}" : url
|
33
|
+
get url
|
34
|
+
end
|
35
|
+
|
30
36
|
def fetch_players
|
31
37
|
get 'players'
|
32
38
|
end
|
@@ -35,10 +41,17 @@ module OneSignal
|
|
35
41
|
get "players/#{player_id}"
|
36
42
|
end
|
37
43
|
|
44
|
+
def csv_export extra_fields: nil, last_active_since: nil, segment_name: nil
|
45
|
+
post "players/csv_export?app_id=#{@app_id}",
|
46
|
+
extra_fields: extra_fields,
|
47
|
+
last_active_since: last_active_since&.to_i&.to_s,
|
48
|
+
segment_name: segment_name
|
49
|
+
end
|
50
|
+
|
38
51
|
private
|
39
52
|
|
40
53
|
def create_body payload
|
41
|
-
body = payload.as_json
|
54
|
+
body = payload.as_json.delete_if { |_, v| v.nil? }
|
42
55
|
body['app_id'] = @app_id
|
43
56
|
body
|
44
57
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
module Commands
|
5
|
+
class FetchNotifications < BaseCommand
|
6
|
+
def initialize page_limit, page_offset, kind
|
7
|
+
@page_limit = page_limit
|
8
|
+
@page_offset = page_offset
|
9
|
+
@kind = kind
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
client.fetch_notifications page_limit: @page_limit, page_offset: @page_offset, kind: @kind
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,7 +6,7 @@ require 'onesignal/notification/headings'
|
|
6
6
|
module OneSignal
|
7
7
|
class Notification
|
8
8
|
attr_reader :contents, :headings, :template_id, :included_segments, :excluded_segments,
|
9
|
-
:included_targets, :send_after, :attachments, :sounds
|
9
|
+
:included_targets, :send_after, :attachments, :sounds, :buttons
|
10
10
|
|
11
11
|
def initialize **params
|
12
12
|
unless params.include?(:contents) || params.include?(:template_id)
|
@@ -23,6 +23,7 @@ module OneSignal
|
|
23
23
|
@attachments = params[:attachments]
|
24
24
|
@filters = params[:filters]
|
25
25
|
@sounds = params[:sounds]
|
26
|
+
@buttons = params[:buttons]
|
26
27
|
end
|
27
28
|
|
28
29
|
def as_json options = {}
|
@@ -30,6 +31,7 @@ module OneSignal
|
|
30
31
|
.except('attachments', 'sounds', 'included_targets')
|
31
32
|
.merge(@attachments&.as_json(options) || {})
|
32
33
|
.merge(@sounds&.as_json(options) || {})
|
34
|
+
.merge(@buttons&.as_json(options) || {})
|
33
35
|
.merge(@included_targets&.as_json(options) || {})
|
34
36
|
.select { |_k, v| v.present? }
|
35
37
|
end
|
@@ -6,7 +6,12 @@ module OneSignal
|
|
6
6
|
def initialize attributes = {}
|
7
7
|
@attributes = attributes.deep_symbolize_keys
|
8
8
|
.keep_if { |k, _v| self.class::ATTRIBUTES_WHITELIST.include?(k.to_sym) }
|
9
|
-
|
9
|
+
|
10
|
+
self.class::ATTRIBUTES_WHITELIST.each do |attribute|
|
11
|
+
self.class.send(:define_method, attribute) do
|
12
|
+
@attributes[attribute]
|
13
|
+
end
|
14
|
+
end
|
10
15
|
end
|
11
16
|
end
|
12
17
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
module Responses
|
5
|
+
# Example JSON
|
6
|
+
# {
|
7
|
+
# "csv_file_url": "https://onesignal.s3.amazonaws.com/csv_exports/test/users_abc123.csv.gz"
|
8
|
+
# }
|
9
|
+
class CsvExport < BaseResponse
|
10
|
+
ATTRIBUTES_WHITELIST = %i[csv_file_url].freeze
|
11
|
+
|
12
|
+
def self.from_json json
|
13
|
+
body = json.is_a?(String) ? JSON.parse(json) : json
|
14
|
+
new(body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/onesignal/segment.rb
CHANGED
data/lib/onesignal/version.rb
CHANGED
data/onesignal-ruby.gemspec
CHANGED
@@ -33,16 +33,16 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
34
|
spec.require_paths = ['lib']
|
35
35
|
|
36
|
-
spec.add_development_dependency 'bundler', '~>
|
36
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
37
|
spec.add_development_dependency 'dotenv', '~> 2.5'
|
38
38
|
spec.add_development_dependency 'factory_bot', '~> 4.11'
|
39
|
-
spec.add_development_dependency 'rake', '~>
|
39
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
40
40
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
41
41
|
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
|
42
42
|
spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
|
43
43
|
spec.add_development_dependency 'webmock', '~> 3.4'
|
44
44
|
|
45
|
-
spec.add_runtime_dependency 'activesupport', '
|
45
|
+
spec.add_runtime_dependency 'activesupport', '>= 5.0.0', '< 7'
|
46
46
|
spec.add_runtime_dependency 'faraday', '~> 0.15', '>= 0.15.4'
|
47
47
|
spec.add_runtime_dependency 'simple_command', '~> 0', '>= 0.0.9'
|
48
48
|
end
|
data/shell.nix
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onesignal-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Joliveau
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dotenv
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,22 +132,22 @@ dependencies:
|
|
132
132
|
name: activesupport
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
|
-
- - "~>"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '5.0'
|
138
135
|
- - ">="
|
139
136
|
- !ruby/object:Gem::Version
|
140
137
|
version: 5.0.0
|
138
|
+
- - "<"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '7'
|
141
141
|
type: :runtime
|
142
142
|
prerelease: false
|
143
143
|
version_requirements: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- - "~>"
|
146
|
-
- !ruby/object:Gem::Version
|
147
|
-
version: '5.0'
|
148
145
|
- - ">="
|
149
146
|
- !ruby/object:Gem::Version
|
150
147
|
version: 5.0.0
|
148
|
+
- - "<"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '7'
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: faraday
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,18 +197,22 @@ extra_rdoc_files: []
|
|
197
197
|
files:
|
198
198
|
- ".circleci/config.yml"
|
199
199
|
- ".editorconfig"
|
200
|
+
- ".envrc"
|
200
201
|
- ".gitignore"
|
201
202
|
- ".rspec"
|
202
203
|
- ".rubocop.yml"
|
204
|
+
- ".ruby-version"
|
205
|
+
- CODEOWNERS
|
203
206
|
- CODE_OF_CONDUCT.md
|
204
207
|
- Gemfile
|
205
|
-
- Gemfile.lock
|
206
208
|
- LICENSE.txt
|
207
209
|
- README.md
|
208
210
|
- Rakefile
|
209
211
|
- bin/console
|
210
212
|
- bin/setup
|
213
|
+
- fixtures/vcr_cassettes/os-csv-export.yml
|
211
214
|
- fixtures/vcr_cassettes/os-fetch-noti.yml
|
215
|
+
- fixtures/vcr_cassettes/os-fetch-notifications.yml
|
212
216
|
- fixtures/vcr_cassettes/os-fetch-player.yml
|
213
217
|
- fixtures/vcr_cassettes/os-fetch-players.yml
|
214
218
|
- fixtures/vcr_cassettes/os-send-noti.yml
|
@@ -216,12 +220,15 @@ files:
|
|
216
220
|
- lib/onesignal/attachments.rb
|
217
221
|
- lib/onesignal/auto_map.rb
|
218
222
|
- lib/onesignal/autoloader.rb
|
223
|
+
- lib/onesignal/buttons.rb
|
219
224
|
- lib/onesignal/client.rb
|
220
225
|
- lib/onesignal/commands.rb
|
221
226
|
- lib/onesignal/commands/autoloader.rb
|
222
227
|
- lib/onesignal/commands/base_command.rb
|
223
228
|
- lib/onesignal/commands/create_notification.rb
|
229
|
+
- lib/onesignal/commands/csv_export.rb
|
224
230
|
- lib/onesignal/commands/fetch_notification.rb
|
231
|
+
- lib/onesignal/commands/fetch_notifications.rb
|
225
232
|
- lib/onesignal/commands/fetch_player.rb
|
226
233
|
- lib/onesignal/commands/fetch_players.rb
|
227
234
|
- lib/onesignal/configuration.rb
|
@@ -233,12 +240,14 @@ files:
|
|
233
240
|
- lib/onesignal/responses.rb
|
234
241
|
- lib/onesignal/responses/autoloader.rb
|
235
242
|
- lib/onesignal/responses/base_response.rb
|
243
|
+
- lib/onesignal/responses/csv_export.rb
|
236
244
|
- lib/onesignal/responses/notification.rb
|
237
245
|
- lib/onesignal/responses/player.rb
|
238
246
|
- lib/onesignal/segment.rb
|
239
247
|
- lib/onesignal/sounds.rb
|
240
248
|
- lib/onesignal/version.rb
|
241
249
|
- onesignal-ruby.gemspec
|
250
|
+
- shell.nix
|
242
251
|
homepage: https://github.com/mikamai/onesignal-ruby
|
243
252
|
licenses:
|
244
253
|
- MIT
|
@@ -259,8 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
268
|
- !ruby/object:Gem::Version
|
260
269
|
version: '0'
|
261
270
|
requirements: []
|
262
|
-
|
263
|
-
rubygems_version: 2.7.7
|
271
|
+
rubygems_version: 3.1.2
|
264
272
|
signing_key:
|
265
273
|
specification_version: 4
|
266
274
|
summary: Ruby wrapper to OneSignal API
|
data/Gemfile.lock
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: https://github.com/stympy/faker.git
|
3
|
-
revision: 14599cc0f7a8bdf7b842714f776477061abda6e4
|
4
|
-
branch: master
|
5
|
-
specs:
|
6
|
-
faker (1.9.1)
|
7
|
-
i18n (>= 0.7)
|
8
|
-
|
9
|
-
PATH
|
10
|
-
remote: .
|
11
|
-
specs:
|
12
|
-
onesignal-ruby (0.2.0)
|
13
|
-
activesupport (~> 5.0, >= 5.0.0)
|
14
|
-
faraday (~> 0.15, >= 0.15.4)
|
15
|
-
simple_command (~> 0, >= 0.0.9)
|
16
|
-
|
17
|
-
GEM
|
18
|
-
remote: https://rubygems.org/
|
19
|
-
specs:
|
20
|
-
activesupport (5.2.2)
|
21
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
|
-
i18n (>= 0.7, < 2)
|
23
|
-
minitest (~> 5.1)
|
24
|
-
tzinfo (~> 1.1)
|
25
|
-
addressable (2.5.2)
|
26
|
-
public_suffix (>= 2.0.2, < 4.0)
|
27
|
-
concurrent-ruby (1.1.4)
|
28
|
-
crack (0.4.3)
|
29
|
-
safe_yaml (~> 1.0.0)
|
30
|
-
diff-lcs (1.3)
|
31
|
-
dotenv (2.6.0)
|
32
|
-
factory_bot (4.11.1)
|
33
|
-
activesupport (>= 3.0.0)
|
34
|
-
faraday (0.15.4)
|
35
|
-
multipart-post (>= 1.2, < 3)
|
36
|
-
hashdiff (0.3.8)
|
37
|
-
i18n (1.5.1)
|
38
|
-
concurrent-ruby (~> 1.0)
|
39
|
-
minitest (5.11.3)
|
40
|
-
multipart-post (2.0.0)
|
41
|
-
public_suffix (3.0.3)
|
42
|
-
rake (10.5.0)
|
43
|
-
rspec (3.8.0)
|
44
|
-
rspec-core (~> 3.8.0)
|
45
|
-
rspec-expectations (~> 3.8.0)
|
46
|
-
rspec-mocks (~> 3.8.0)
|
47
|
-
rspec-core (3.8.0)
|
48
|
-
rspec-support (~> 3.8.0)
|
49
|
-
rspec-expectations (3.8.2)
|
50
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.8.0)
|
52
|
-
rspec-mocks (3.8.0)
|
53
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.8.0)
|
55
|
-
rspec-support (3.8.0)
|
56
|
-
rspec_junit_formatter (0.4.1)
|
57
|
-
rspec-core (>= 2, < 4, != 2.12.0)
|
58
|
-
safe_yaml (1.0.4)
|
59
|
-
simple_command (0.0.9)
|
60
|
-
thread_safe (0.3.6)
|
61
|
-
tzinfo (1.2.5)
|
62
|
-
thread_safe (~> 0.1)
|
63
|
-
vcr (4.0.0)
|
64
|
-
webmock (3.5.1)
|
65
|
-
addressable (>= 2.3.6)
|
66
|
-
crack (>= 0.3.2)
|
67
|
-
hashdiff
|
68
|
-
|
69
|
-
PLATFORMS
|
70
|
-
ruby
|
71
|
-
|
72
|
-
DEPENDENCIES
|
73
|
-
bundler (~> 1.16)
|
74
|
-
dotenv (~> 2.5)
|
75
|
-
factory_bot (~> 4.11)
|
76
|
-
faker!
|
77
|
-
onesignal-ruby!
|
78
|
-
rake (~> 10.0)
|
79
|
-
rspec (~> 3.0)
|
80
|
-
rspec_junit_formatter (~> 0.4)
|
81
|
-
vcr (~> 4.0, >= 4.0.0)
|
82
|
-
webmock (~> 3.4)
|
83
|
-
|
84
|
-
BUNDLED WITH
|
85
|
-
1.16.2
|