onesignal-ruby 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +14 -0
  3. data/.gitignore +17 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +182 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +12 -0
  8. data/Gemfile.lock +82 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +179 -0
  11. data/Rakefile +8 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/fixtures/vcr_cassettes/os-fetch-noti.yml +76 -0
  15. data/fixtures/vcr_cassettes/os-fetch-player.yml +72 -0
  16. data/fixtures/vcr_cassettes/os-fetch-players.yml +72 -0
  17. data/fixtures/vcr_cassettes/os-send-noti.yml +145 -0
  18. data/lib/onesignal.rb +49 -0
  19. data/lib/onesignal/attachments.rb +27 -0
  20. data/lib/onesignal/auto_map.rb +13 -0
  21. data/lib/onesignal/autoloader.rb +7 -0
  22. data/lib/onesignal/client.rb +61 -0
  23. data/lib/onesignal/commands.rb +7 -0
  24. data/lib/onesignal/commands/autoloader.rb +7 -0
  25. data/lib/onesignal/commands/base_command.rb +23 -0
  26. data/lib/onesignal/commands/create_notification.rb +15 -0
  27. data/lib/onesignal/commands/fetch_notification.rb +15 -0
  28. data/lib/onesignal/commands/fetch_player.rb +15 -0
  29. data/lib/onesignal/commands/fetch_players.rb +11 -0
  30. data/lib/onesignal/configuration.rb +14 -0
  31. data/lib/onesignal/filter.rb +132 -0
  32. data/lib/onesignal/notification.rb +35 -0
  33. data/lib/onesignal/notification/contents.rb +17 -0
  34. data/lib/onesignal/notification/headings.rb +17 -0
  35. data/lib/onesignal/responses.rb +7 -0
  36. data/lib/onesignal/responses/autoloader.rb +7 -0
  37. data/lib/onesignal/responses/base_response.rb +13 -0
  38. data/lib/onesignal/responses/notification.rb +45 -0
  39. data/lib/onesignal/responses/player.rb +21 -0
  40. data/lib/onesignal/segment.rb +22 -0
  41. data/lib/onesignal/sounds.rb +39 -0
  42. data/lib/onesignal/version.rb +6 -0
  43. data/onesignal-ruby.gemspec +47 -0
  44. metadata +251 -0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ module Responses
5
+ require 'onesignal/responses/autoloader'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir["#{File.expand_path(__dir__)}/*.rb"].each do |file|
4
+ filename = File.basename file
5
+ classname = filename.split('.rb').first.camelize
6
+ OneSignal::Responses.autoload classname, File.expand_path("../#{filename}", __FILE__)
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ module Responses
5
+ class BaseResponse
6
+ def initialize attributes = {}
7
+ @attributes = attributes.deep_symbolize_keys
8
+ .keep_if { |k, _v| self.class::ATTRIBUTES_WHITELIST.include?(k.to_sym) }
9
+ self.class.attr_reader(*self.class::ATTRIBUTES_WHITELIST)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ module Responses
5
+ # Example JSON
6
+ # {
7
+ # "id": '481a2734-6b7d-11e4-a6ea-4b53294fa671',
8
+ # "successful": 15,
9
+ # "failed": 1,
10
+ # "converted": 3,
11
+ # "remaining": 0,
12
+ # "queued_at": 1_415_914_655,
13
+ # "send_after": 1_415_914_655,
14
+ # "completed_at": 1_415_914_656,
15
+ # "url": 'https://yourWebsiteToOpen.com',
16
+ # "data": {
17
+ # "foo": 'bar',
18
+ # "your": 'custom metadata'
19
+ # },
20
+ # "canceled": false,
21
+ # "headings": {
22
+ # "en": 'English and default language heading',
23
+ # "es": 'Spanish language heading'
24
+ # },
25
+ # "contents": {
26
+ # "en": 'English language content',
27
+ # "es": 'Hola'
28
+ # }
29
+ # }
30
+ class Notification < BaseResponse
31
+ ATTRIBUTES_WHITELIST = %i[id successful failed converted remaining
32
+ queued_at send_after completed_at url data
33
+ canceled headings contents].freeze
34
+
35
+ def canceled?
36
+ canceled
37
+ end
38
+
39
+ def self.from_json json
40
+ body = json.is_a?(String) ? JSON.parse(json) : json
41
+ new(body)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ module Responses
5
+ class Player < BaseResponse
6
+ ATTRIBUTES_WHITELIST = %i[id identifier session_count language timezone
7
+ game_version device_os device_type device_model tags
8
+ ad_id last_active playtime amount_spent created_at
9
+ invalid_identifier badge_count sdk test_type ip].freeze
10
+
11
+ def invalid_identifier?
12
+ invalid_identifier
13
+ end
14
+
15
+ def self.from_json json
16
+ body = json.is_a?(String) ? JSON.parse(json) : json
17
+ new(body)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ class Segment
5
+ ALL_USERS = 'All'
6
+ ACTIVE_USERS = 'Active Users'
7
+ ENGAGED_USERS = 'Engaged Users'
8
+ INACTIVE_USERS = 'Inactive Users'
9
+
10
+ def initialize name:
11
+ @name = name
12
+ end
13
+
14
+ def as_json _options = nil
15
+ @name.to_s
16
+ end
17
+
18
+ def to_s
19
+ @name.to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ class Sounds
5
+ attr_reader :ios, :android, :amazon, :windows
6
+
7
+ def initialize ios: nil, android: nil, amazon: nil, windows: nil
8
+ validate ios: ios, windows: windows
9
+
10
+ @ios = ios
11
+ @android = android
12
+ @amazon = amazon
13
+ @windows = windows
14
+ end
15
+
16
+ def as_json options = nil
17
+ {
18
+ 'ios_sound' => @ios.as_json(options),
19
+ 'android_sound' => @android.as_json(options),
20
+ 'adm_sound' => @amazon.as_json(options),
21
+ 'wp_wns_sound' => @windows.as_json(options)
22
+ }
23
+ end
24
+
25
+ private
26
+
27
+ REGEX = /.*.\.\w*/
28
+
29
+ def validate ios: nil, windows: nil
30
+ ios_valid = !ios.nil? && (REGEX =~ ios).nil?
31
+ windows_valid = !windows.nil? && (REGEX =~ windows).nil?
32
+ raise InvalidError, "provide file extension for iOS: #{ios}" if ios_valid
33
+ raise InvalidError, "provide file extension for windows: #{ios}" if windows_valid
34
+ end
35
+ end
36
+
37
+ class InvalidError < StandardError
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneSignal
4
+ VERSION = '0.2.0'
5
+ API_VERSION = 'v1'
6
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'onesignal/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'onesignal-ruby'
9
+ spec.version = OneSignal::VERSION
10
+ spec.authors = ['Matteo Joliveau']
11
+ spec.email = ['matteo.joliveau@mikamai.com']
12
+
13
+ spec.summary = 'Ruby wrapper to OneSignal API'
14
+ spec.description = 'Ruby wrapper to OneSignal API, mapping to Plain Old Ruby Objects'
15
+ spec.homepage = 'https://github.com/mikamai/onesignal-ruby'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.16'
37
+ spec.add_development_dependency 'dotenv', '~> 2.5'
38
+ spec.add_development_dependency 'factory_bot', '~> 4.11'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
42
+ spec.add_development_dependency 'webmock', '~> 3.4'
43
+
44
+ spec.add_runtime_dependency 'activesupport', '~> 5.2', '>= 5.2.2'
45
+ spec.add_runtime_dependency 'faraday', '~> 0.15', '>= 0.15.4'
46
+ spec.add_runtime_dependency 'simple_command', '~> 0', '>= 0.0.9'
47
+ end
metadata ADDED
@@ -0,0 +1,251 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onesignal-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Matteo Joliveau
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_bot
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.0.0
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '4.0'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 4.0.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: webmock
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.4'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.4'
117
+ - !ruby/object:Gem::Dependency
118
+ name: activesupport
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '5.2'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 5.2.2
127
+ type: :runtime
128
+ prerelease: false
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '5.2'
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 5.2.2
137
+ - !ruby/object:Gem::Dependency
138
+ name: faraday
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '0.15'
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 0.15.4
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.15'
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 0.15.4
157
+ - !ruby/object:Gem::Dependency
158
+ name: simple_command
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "~>"
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 0.0.9
167
+ type: :runtime
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: 0.0.9
177
+ description: Ruby wrapper to OneSignal API, mapping to Plain Old Ruby Objects
178
+ email:
179
+ - matteo.joliveau@mikamai.com
180
+ executables: []
181
+ extensions: []
182
+ extra_rdoc_files: []
183
+ files:
184
+ - ".editorconfig"
185
+ - ".gitignore"
186
+ - ".rspec"
187
+ - ".rubocop.yml"
188
+ - CODE_OF_CONDUCT.md
189
+ - Gemfile
190
+ - Gemfile.lock
191
+ - LICENSE.txt
192
+ - README.md
193
+ - Rakefile
194
+ - bin/console
195
+ - bin/setup
196
+ - fixtures/vcr_cassettes/os-fetch-noti.yml
197
+ - fixtures/vcr_cassettes/os-fetch-player.yml
198
+ - fixtures/vcr_cassettes/os-fetch-players.yml
199
+ - fixtures/vcr_cassettes/os-send-noti.yml
200
+ - lib/onesignal.rb
201
+ - lib/onesignal/attachments.rb
202
+ - lib/onesignal/auto_map.rb
203
+ - lib/onesignal/autoloader.rb
204
+ - lib/onesignal/client.rb
205
+ - lib/onesignal/commands.rb
206
+ - lib/onesignal/commands/autoloader.rb
207
+ - lib/onesignal/commands/base_command.rb
208
+ - lib/onesignal/commands/create_notification.rb
209
+ - lib/onesignal/commands/fetch_notification.rb
210
+ - lib/onesignal/commands/fetch_player.rb
211
+ - lib/onesignal/commands/fetch_players.rb
212
+ - lib/onesignal/configuration.rb
213
+ - lib/onesignal/filter.rb
214
+ - lib/onesignal/notification.rb
215
+ - lib/onesignal/notification/contents.rb
216
+ - lib/onesignal/notification/headings.rb
217
+ - lib/onesignal/responses.rb
218
+ - lib/onesignal/responses/autoloader.rb
219
+ - lib/onesignal/responses/base_response.rb
220
+ - lib/onesignal/responses/notification.rb
221
+ - lib/onesignal/responses/player.rb
222
+ - lib/onesignal/segment.rb
223
+ - lib/onesignal/sounds.rb
224
+ - lib/onesignal/version.rb
225
+ - onesignal-ruby.gemspec
226
+ homepage: https://github.com/mikamai/onesignal-ruby
227
+ licenses:
228
+ - MIT
229
+ metadata:
230
+ allowed_push_host: https://rubygems.org
231
+ post_install_message:
232
+ rdoc_options: []
233
+ require_paths:
234
+ - lib
235
+ required_ruby_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ requirements: []
246
+ rubyforge_project:
247
+ rubygems_version: 2.7.7
248
+ signing_key:
249
+ specification_version: 4
250
+ summary: Ruby wrapper to OneSignal API
251
+ test_files: []