onesignal-ruby 0.2.0 → 0.3.0
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/.circleci/config.yml +42 -0
- data/Gemfile.lock +5 -2
- data/README.md +48 -2
- data/fixtures/vcr_cassettes/os-fetch-noti.yml +2 -2
- data/fixtures/vcr_cassettes/os-fetch-player.yml +2 -2
- data/fixtures/vcr_cassettes/os-fetch-players.yml +2 -2
- data/fixtures/vcr_cassettes/os-send-noti.yml +2 -2
- data/lib/onesignal.rb +4 -0
- data/lib/onesignal/client.rb +15 -2
- data/lib/onesignal/configuration.rb +6 -1
- data/lib/onesignal/filter.rb +26 -18
- data/lib/onesignal/included_targets.rb +47 -0
- data/lib/onesignal/notification.rb +11 -9
- data/lib/onesignal/sounds.rb +1 -1
- data/lib/onesignal/version.rb +1 -1
- data/onesignal-ruby.gemspec +2 -1
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d55ff42325f9b7c7c83a398d598df848053b95e98cb715e79b6d38355357b223
|
4
|
+
data.tar.gz: bdb457ba65dbd59d238bf2776167eb392f3b6deadda5d504155f17e5206cf839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c65cbfe1f08e453c4c23785d4fc394e51c377ba2f79b459caeed982c67720fe45fa34c435a16ca89d919e6ae82ee763b135b49227262c217cc8eac735fe0a9e
|
7
|
+
data.tar.gz: 4064fefacbfe49bde9f22ba865697e8b039e9b068bc474ace1d74310bceb3131a672300c22e7f9affc0552b68b6a55ab956d9872718bbba43ce47babebb15f16
|
@@ -0,0 +1,42 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.5.1
|
6
|
+
environment:
|
7
|
+
working_directory: ~/repo
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
- restore_cache:
|
12
|
+
name: Restore Bundle cache
|
13
|
+
keys:
|
14
|
+
- bundle-{{ checksum "Gemfile.lock" }}
|
15
|
+
- bundle-
|
16
|
+
- run:
|
17
|
+
name: Install dependencies
|
18
|
+
command: |
|
19
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
20
|
+
- save_cache:
|
21
|
+
name: Save Bundle cache
|
22
|
+
paths:
|
23
|
+
- ./vendor/bundle
|
24
|
+
key: bundle-{{ checksum "Gemfile.lock" }}
|
25
|
+
|
26
|
+
- run:
|
27
|
+
name: Run tests
|
28
|
+
command: |
|
29
|
+
mkdir /tmp/test-results
|
30
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
31
|
+
|
32
|
+
bundle exec rspec --format progress \
|
33
|
+
--format RspecJunitFormatter \
|
34
|
+
--out /tmp/test-results/rspec.xml \
|
35
|
+
--format progress \
|
36
|
+
$TEST_FILES
|
37
|
+
|
38
|
+
- store_test_results:
|
39
|
+
path: /tmp/test-results
|
40
|
+
- store_artifacts:
|
41
|
+
path: /tmp/test-results
|
42
|
+
destination: test-results
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/stympy/faker.git
|
3
|
-
revision:
|
3
|
+
revision: 14599cc0f7a8bdf7b842714f776477061abda6e4
|
4
4
|
branch: master
|
5
5
|
specs:
|
6
6
|
faker (1.9.1)
|
@@ -10,7 +10,7 @@ PATH
|
|
10
10
|
remote: .
|
11
11
|
specs:
|
12
12
|
onesignal-ruby (0.2.0)
|
13
|
-
activesupport (~> 5.
|
13
|
+
activesupport (~> 5.0, >= 5.0.0)
|
14
14
|
faraday (~> 0.15, >= 0.15.4)
|
15
15
|
simple_command (~> 0, >= 0.0.9)
|
16
16
|
|
@@ -53,6 +53,8 @@ GEM
|
|
53
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
54
|
rspec-support (~> 3.8.0)
|
55
55
|
rspec-support (3.8.0)
|
56
|
+
rspec_junit_formatter (0.4.1)
|
57
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
56
58
|
safe_yaml (1.0.4)
|
57
59
|
simple_command (0.0.9)
|
58
60
|
thread_safe (0.3.6)
|
@@ -75,6 +77,7 @@ DEPENDENCIES
|
|
75
77
|
onesignal-ruby!
|
76
78
|
rake (~> 10.0)
|
77
79
|
rspec (~> 3.0)
|
80
|
+
rspec_junit_formatter (~> 0.4)
|
78
81
|
vcr (~> 4.0, >= 4.0.0)
|
79
82
|
webmock (~> 3.4)
|
80
83
|
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# OneSignal Ruby Client
|
2
|
+
[](https://badge.fury.io/rb/onesignal-ruby)
|
3
|
+
[](https://circleci.com/gh/mikamai/onesignal-ruby)
|
2
4
|
|
3
5
|
A simple, pure Ruby client to the [OneSignal](https://onesignal.com/apps/22bc6dec-5150-4d6d-8628-377259d2dd14/segments) API.
|
4
6
|
|
@@ -6,7 +8,6 @@ A simple, pure Ruby client to the [OneSignal](https://onesignal.com/apps/22bc6de
|
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
### COMING SOON (not yet published)
|
10
11
|
```ruby
|
11
12
|
gem 'onesignal-ruby'
|
12
13
|
```
|
@@ -30,15 +31,20 @@ It also defaults to `https://onesignal.com/api/v1` as the API URL.
|
|
30
31
|
You can also turn off OneSignal entirely with a boolean flag (for example to avoid sending
|
31
32
|
notification while in test or development environments)
|
32
33
|
|
34
|
+
It will also use an internal instance of the Ruby Logger at `INFO` level.
|
35
|
+
|
33
36
|
To customize those values, call the following snippet during your
|
34
37
|
initialization phase.
|
35
38
|
|
36
39
|
```ruby
|
40
|
+
require 'onesignal'
|
41
|
+
|
37
42
|
OneSignal.configure do |config|
|
38
43
|
config.app_id = 'my_app_id'
|
39
44
|
config.api_key = 'my_api_key'
|
40
45
|
config.api_url = 'http://my_api_url'
|
41
46
|
config.active = false
|
47
|
+
config.logger = Logger.new # Any Logger compliant implementation
|
42
48
|
end
|
43
49
|
```
|
44
50
|
## Usage
|
@@ -66,6 +72,20 @@ Then send it.
|
|
66
72
|
# => #<OneSignal::Responses::Notification> the created notification
|
67
73
|
```
|
68
74
|
|
75
|
+
### Sending a notification to specific devices
|
76
|
+
|
77
|
+
Instead of including/excluding a segment you can also target specific devices.
|
78
|
+
```ruby
|
79
|
+
# Setup headings and content
|
80
|
+
|
81
|
+
# Select the devices
|
82
|
+
include_player_ids = ["1dd608f2-c6a1-11e3-851d-000c2940e62c"]
|
83
|
+
notification = OneSignal::Notification.new(headings: headings, contents: contents, include_player_ids: include_player_ids)
|
84
|
+
```
|
85
|
+
You can pass the followings when creating a notification: `include_player_ids: []`, `include_email_tokens: []`, `include_ios_tokens: []`, `include_wp_wns_uris: []`, `include_amazon_reg_ids: []`, `include_chrome_reg_ids: []`, `include_chrome_web_reg_ids: []`, `include_android_reg_ids: []`.
|
86
|
+
Refer to [OneSignal's documentation](https://documentation.onesignal.com/reference#create-notification) for more information.
|
87
|
+
|
88
|
+
|
69
89
|
### Fetch a notification
|
70
90
|
You can fetch an existing notification given its ID.
|
71
91
|
```ruby
|
@@ -122,7 +142,7 @@ player = OneSignal.fetch_player(player_id)
|
|
122
142
|
|
123
143
|
### Filters
|
124
144
|
|
125
|
-
Filters can be created with a simple DSL. It closely matches the [JSON reference](), with a few touches of syntax
|
145
|
+
Filters can be created with a simple DSL. It closely matches the [JSON reference](https://documentation.onesignal.com/reference#section-send-to-users-based-on-filters), with a few touches of syntax
|
126
146
|
sugar.
|
127
147
|
|
128
148
|
**Example**
|
@@ -146,6 +166,19 @@ Becomes
|
|
146
166
|
]
|
147
167
|
```
|
148
168
|
|
169
|
+
The operator methods (`#lesser_than`, `#greater_than`, `#equals`, `#not_equals`) are also available through the following shorthands: `<`, `>`, `=`, `!=`.
|
170
|
+
|
171
|
+
**Example**
|
172
|
+
```ruby
|
173
|
+
filters = [
|
174
|
+
OneSignal::Filter.tag('userId') == 5,
|
175
|
+
OneSignal::Filter.session_count < 2,
|
176
|
+
OneSignal::Filter.language != 'en'
|
177
|
+
]
|
178
|
+
|
179
|
+
OneSignal::Notification.new(filters: filters)
|
180
|
+
```
|
181
|
+
|
149
182
|
### Custom Sounds
|
150
183
|
You can customize notification sounds by passing a `OneSignal::Sounds` object.
|
151
184
|
```ruby
|
@@ -153,6 +186,19 @@ sounds = OneSignal::Sounds.new(ios: 'ping.wav', android: 'ping')
|
|
153
186
|
OneSignal::Notification.new(sounds: sounds)
|
154
187
|
```
|
155
188
|
|
189
|
+
### Specific Targets
|
190
|
+
If you want to send a notification only to specific targets (a particular user's email or device) you can
|
191
|
+
pass a `OneSignal::IncludedTargets` to the notification object.
|
192
|
+
See [the official documentation](https://documentation.onesignal.com/reference#section-send-to-specific-devices) for a list of available params.
|
193
|
+
```ruby
|
194
|
+
included_targets = OneSignal::IncludedTargets.new(include_player_ids: 'test-id-12345')
|
195
|
+
OneSignal::Notification.new(included_targets: included_targets)
|
196
|
+
```
|
197
|
+
|
198
|
+
**WARNING**
|
199
|
+
Passing `include_player_ids` alongside other params is prohibited and will raise an `ArgumentError`.
|
200
|
+
Either use `include_player_ids` or use the other params.
|
201
|
+
|
156
202
|
## Development
|
157
203
|
|
158
204
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://onesignal.com/api/v1/notifications/?app_id
|
5
|
+
uri: https://onesignal.com/api/v1/notifications/?app_id
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -12,7 +12,7 @@ http_interactions:
|
|
12
12
|
Content-Type:
|
13
13
|
- application/json
|
14
14
|
Authorization:
|
15
|
-
- Basic
|
15
|
+
- Basic test
|
16
16
|
Accept-Encoding:
|
17
17
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
18
|
Accept:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://onesignal.com/api/v1/players/?app_id
|
5
|
+
uri: https://onesignal.com/api/v1/players/?app_id
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -12,7 +12,7 @@ http_interactions:
|
|
12
12
|
Content-Type:
|
13
13
|
- application/json
|
14
14
|
Authorization:
|
15
|
-
- Basic
|
15
|
+
- Basic test
|
16
16
|
Accept-Encoding:
|
17
17
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
18
|
Accept:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://onesignal.com/api/v1/players?app_id
|
5
|
+
uri: https://onesignal.com/api/v1/players?app_id
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -12,7 +12,7 @@ http_interactions:
|
|
12
12
|
Content-Type:
|
13
13
|
- application/json
|
14
14
|
Authorization:
|
15
|
-
- Basic
|
15
|
+
- Basic test
|
16
16
|
Accept-Encoding:
|
17
17
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
18
|
Accept:
|
@@ -13,7 +13,7 @@ http_interactions:
|
|
13
13
|
Content-Type:
|
14
14
|
- application/json
|
15
15
|
Authorization:
|
16
|
-
- Basic
|
16
|
+
- Basic test
|
17
17
|
Accept-Encoding:
|
18
18
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
19
19
|
Accept:
|
@@ -69,7 +69,7 @@ http_interactions:
|
|
69
69
|
recorded_at: Thu, 28 Jun 2018 15:30:57 GMT
|
70
70
|
- request:
|
71
71
|
method: get
|
72
|
-
uri: https://onesignal.com/api/v1/notifications/29e9c2ad-41da-46f0-94c3-e71ee5c103dc?app_id
|
72
|
+
uri: https://onesignal.com/api/v1/notifications/29e9c2ad-41da-46f0-94c3-e71ee5c103dc?app_id
|
73
73
|
body:
|
74
74
|
encoding: US-ASCII
|
75
75
|
string: ''
|
data/lib/onesignal.rb
CHANGED
@@ -15,24 +15,28 @@ module OneSignal
|
|
15
15
|
|
16
16
|
def send_notification notification
|
17
17
|
return unless OneSignal.config.active
|
18
|
+
|
18
19
|
created = Commands::CreateNotification.call notification
|
19
20
|
fetch_notification(JSON.parse(created.body)['id'])
|
20
21
|
end
|
21
22
|
|
22
23
|
def fetch_notification notification_id
|
23
24
|
return unless OneSignal.config.active
|
25
|
+
|
24
26
|
fetched = Commands::FetchNotification.call notification_id
|
25
27
|
Responses::Notification.from_json fetched.body
|
26
28
|
end
|
27
29
|
|
28
30
|
def fetch_player player_id
|
29
31
|
return unless OneSignal.config.active
|
32
|
+
|
30
33
|
fetched = Commands::FetchPlayer.call player_id
|
31
34
|
Responses::Player.from_json fetched.body
|
32
35
|
end
|
33
36
|
|
34
37
|
def fetch_players
|
35
38
|
return unless OneSignal.config.active
|
39
|
+
|
36
40
|
fetched = Commands::FetchPlayers.call
|
37
41
|
JSON.parse(fetched.body)['players'].map { |player| Responses::Player.from_json player }
|
38
42
|
end
|
data/lib/onesignal/client.rb
CHANGED
@@ -4,6 +4,8 @@ require 'faraday'
|
|
4
4
|
|
5
5
|
module OneSignal
|
6
6
|
class Client
|
7
|
+
class ApiError < RuntimeError; end
|
8
|
+
|
7
9
|
def initialize app_id, api_key, api_url
|
8
10
|
@app_id = app_id
|
9
11
|
@api_key = api_key
|
@@ -42,20 +44,31 @@ module OneSignal
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def post url, body
|
45
|
-
@conn.post do |req|
|
47
|
+
res = @conn.post do |req|
|
46
48
|
req.url url
|
47
49
|
req.body = create_body(body).to_json
|
48
50
|
req.headers['Content-Type'] = 'application/json'
|
49
51
|
req.headers['Authorization'] = "Basic #{@api_key}"
|
50
52
|
end
|
53
|
+
|
54
|
+
handle_errors res
|
51
55
|
end
|
52
56
|
|
53
57
|
def get url
|
54
|
-
@conn.get do |req|
|
58
|
+
res = @conn.get do |req|
|
55
59
|
req.url url, app_id: @app_id
|
56
60
|
req.headers['Content-Type'] = 'application/json'
|
57
61
|
req.headers['Authorization'] = "Basic #{@api_key}"
|
58
62
|
end
|
63
|
+
|
64
|
+
handle_errors res
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle_errors res
|
68
|
+
errors = JSON.parse(res.body).fetch 'errors', []
|
69
|
+
raise ApiError, (errors.first || "Error code #{res.status}") if res.status > 399 || errors.any?
|
70
|
+
|
71
|
+
res
|
59
72
|
end
|
60
73
|
end
|
61
74
|
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
3
5
|
module OneSignal
|
4
6
|
class Configuration
|
5
|
-
attr_accessor :app_id, :api_key, :api_url, :active
|
7
|
+
attr_accessor :app_id, :api_key, :api_url, :active, :logger
|
6
8
|
|
7
9
|
def initialize
|
8
10
|
@app_id = ENV['ONESIGNAL_APP_ID']
|
9
11
|
@api_key = ENV['ONESIGNAL_API_KEY']
|
10
12
|
@api_url = "https://onesignal.com/api/#{OneSignal::API_VERSION}"
|
11
13
|
@active = true
|
14
|
+
@logger = Logger.new(STDOUT).tap do |logger|
|
15
|
+
logger.level = Logger::INFO
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/lib/onesignal/filter.rb
CHANGED
@@ -43,18 +43,18 @@ module OneSignal
|
|
43
43
|
FilterBuilder.new 'app_version'
|
44
44
|
end
|
45
45
|
|
46
|
+
def country
|
47
|
+
FilterBuilder.new 'country'
|
48
|
+
end
|
49
|
+
|
46
50
|
def location radius:, lat:, long:
|
47
|
-
location = OpenStruct.new
|
48
|
-
new
|
51
|
+
location = OpenStruct.new radius: radius, latitude: lat, longitude: long
|
52
|
+
new FilterBuilder.new('location', location: location)
|
49
53
|
end
|
50
54
|
|
51
55
|
def email email
|
52
56
|
new(FilterBuilder.new('email', value: email))
|
53
57
|
end
|
54
|
-
|
55
|
-
def country
|
56
|
-
FilterBuilder.new('country')
|
57
|
-
end
|
58
58
|
end
|
59
59
|
|
60
60
|
def hours_ago!
|
@@ -70,48 +70,56 @@ module OneSignal
|
|
70
70
|
private
|
71
71
|
|
72
72
|
def initialize builder
|
73
|
-
@field
|
74
|
-
@key
|
75
|
-
@relation
|
76
|
-
@value
|
73
|
+
@field = builder.b_field
|
74
|
+
@key = builder.b_key
|
75
|
+
@relation = builder.b_relation
|
76
|
+
@value = builder.b_value
|
77
77
|
@hours_ago = builder.b_hours_ago
|
78
|
-
@location
|
78
|
+
@location = builder.b_location
|
79
79
|
end
|
80
80
|
|
81
81
|
class FilterBuilder
|
82
82
|
attr_reader :b_field, :b_key, :b_relation, :b_value, :b_hours_ago, :b_location
|
83
83
|
|
84
84
|
def initialize field, params = {}
|
85
|
-
@b_field
|
86
|
-
@b_key
|
85
|
+
@b_field = field
|
86
|
+
@b_key = params[:key]
|
87
87
|
@b_location = params[:location]
|
88
|
-
@b_value
|
88
|
+
@b_value = params[:value]
|
89
89
|
end
|
90
90
|
|
91
91
|
def lesser_than value
|
92
92
|
@b_relation = '<'
|
93
|
-
@b_value
|
93
|
+
@b_value = value.to_s
|
94
94
|
build
|
95
95
|
end
|
96
96
|
|
97
|
+
alias < lesser_than
|
98
|
+
|
97
99
|
def greater_than value
|
98
100
|
@b_relation = '>'
|
99
|
-
@b_value
|
101
|
+
@b_value = value.to_s
|
100
102
|
build
|
101
103
|
end
|
102
104
|
|
105
|
+
alias > greater_than
|
106
|
+
|
103
107
|
def equals value
|
104
108
|
@b_relation = '='
|
105
|
-
@b_value
|
109
|
+
@b_value = value.to_s
|
106
110
|
build
|
107
111
|
end
|
108
112
|
|
113
|
+
alias == equals
|
114
|
+
|
109
115
|
def not_equals value
|
110
116
|
@b_relation = '!='
|
111
|
-
@b_value
|
117
|
+
@b_value = value.to_s
|
112
118
|
build
|
113
119
|
end
|
114
120
|
|
121
|
+
alias != not_equals
|
122
|
+
|
115
123
|
def exists
|
116
124
|
@b_relation = 'exists'
|
117
125
|
build
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
class IncludedTargets
|
5
|
+
attr_reader :include_player_ids, :include_email_tokens, :include_external_user_ids, :include_ios_tokens,
|
6
|
+
:include_wp_wns_uris, :include_amazon_reg_ids, :include_chrome_reg_ids, :include_chrome_web_reg_ids,
|
7
|
+
:include_android_reg_ids
|
8
|
+
|
9
|
+
def initialize params
|
10
|
+
raise ArgumentError, 'include_player_ids cannot be used with other targets' if params.key?(:include_player_ids) && params.keys.count > 1
|
11
|
+
|
12
|
+
@include_player_ids = params[:include_player_ids]
|
13
|
+
@include_email_tokens = params[:include_email_tokens]
|
14
|
+
@include_external_user_ids = params[:include_external_user_ids]
|
15
|
+
|
16
|
+
@include_ios_tokens = print_warning params, :include_ios_tokens
|
17
|
+
@include_wp_wns_uris = print_warning params, :include_wp_wns_uris
|
18
|
+
@include_amazon_reg_ids = print_warning params, :include_amazon_reg_ids
|
19
|
+
@include_chrome_reg_ids = print_warning params, :include_chrome_reg_ids
|
20
|
+
@include_chrome_web_reg_ids = print_warning params, :include_chrome_web_reg_ids
|
21
|
+
@include_android_reg_ids = print_warning params, :include_android_reg_ids
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_warning params, name
|
25
|
+
if params.key? name
|
26
|
+
OneSignal.config.logger.warn "OneSignal WARNING - Use of #{name} is not recommended. " \
|
27
|
+
'Use either include_player_ids, include_email_tokens or include_external_user_ids. ' \
|
28
|
+
'See https://documentation.onesignal.com/reference#section-send-to-specific-devices'
|
29
|
+
end
|
30
|
+
params[name]
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_json options = nil
|
34
|
+
{
|
35
|
+
'include_player_ids' => @include_player_ids,
|
36
|
+
'include_email_tokens' => @include_email_tokens,
|
37
|
+
'include_external_user_ids' => @include_external_user_ids,
|
38
|
+
'include_ios_tokens' => @include_ios_tokens,
|
39
|
+
'include_wp_wns_uris' => @include_wp_wns_uris,
|
40
|
+
'include_amazon_reg_ids' => @include_amazon_reg_ids,
|
41
|
+
'include_chrome_reg_ids' => @include_chrome_reg_ids,
|
42
|
+
'include_chrome_web_reg_ids' => @include_chrome_web_reg_ids,
|
43
|
+
'include_android_reg_ids' => @include_android_reg_ids
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -6,29 +6,31 @@ 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
|
-
:send_after, :attachments, :sounds
|
9
|
+
:included_targets, :send_after, :attachments, :sounds
|
10
10
|
|
11
11
|
def initialize **params
|
12
12
|
unless params.include?(:contents) || params.include?(:template_id)
|
13
13
|
raise ArgumentError, 'missing contents or template_id'
|
14
14
|
end
|
15
15
|
|
16
|
-
@contents
|
17
|
-
@headings
|
18
|
-
@template_id
|
16
|
+
@contents = params[:contents]
|
17
|
+
@headings = params[:headings]
|
18
|
+
@template_id = params[:template_id]
|
19
19
|
@included_segments = params[:included_segments]
|
20
20
|
@excluded_segments = params[:excluded_segments]
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
21
|
+
@included_targets = params[:included_targets]
|
22
|
+
@send_after = params[:send_after].to_s
|
23
|
+
@attachments = params[:attachments]
|
24
|
+
@filters = params[:filters]
|
25
|
+
@sounds = params[:sounds]
|
25
26
|
end
|
26
27
|
|
27
28
|
def as_json options = {}
|
28
29
|
super(options)
|
29
|
-
.except('attachments', 'sounds')
|
30
|
+
.except('attachments', 'sounds', 'included_targets')
|
30
31
|
.merge(@attachments&.as_json(options) || {})
|
31
32
|
.merge(@sounds&.as_json(options) || {})
|
33
|
+
.merge(@included_targets&.as_json(options) || {})
|
32
34
|
.select { |_k, v| v.present? }
|
33
35
|
end
|
34
36
|
end
|
data/lib/onesignal/sounds.rb
CHANGED
data/lib/onesignal/version.rb
CHANGED
data/onesignal-ruby.gemspec
CHANGED
@@ -38,10 +38,11 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency 'factory_bot', '~> 4.11'
|
39
39
|
spec.add_development_dependency 'rake', '~> 10.0'
|
40
40
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
41
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
|
41
42
|
spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
|
42
43
|
spec.add_development_dependency 'webmock', '~> 3.4'
|
43
44
|
|
44
|
-
spec.add_runtime_dependency 'activesupport', '~> 5.
|
45
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.0', '>= 5.0.0'
|
45
46
|
spec.add_runtime_dependency 'faraday', '~> 0.15', '>= 0.15.4'
|
46
47
|
spec.add_runtime_dependency 'simple_command', '~> 0', '>= 0.0.9'
|
47
48
|
end
|
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.3.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: 2019-01-
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec_junit_formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: vcr
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,20 +134,20 @@ dependencies:
|
|
120
134
|
requirements:
|
121
135
|
- - "~>"
|
122
136
|
- !ruby/object:Gem::Version
|
123
|
-
version: '5.
|
137
|
+
version: '5.0'
|
124
138
|
- - ">="
|
125
139
|
- !ruby/object:Gem::Version
|
126
|
-
version: 5.
|
140
|
+
version: 5.0.0
|
127
141
|
type: :runtime
|
128
142
|
prerelease: false
|
129
143
|
version_requirements: !ruby/object:Gem::Requirement
|
130
144
|
requirements:
|
131
145
|
- - "~>"
|
132
146
|
- !ruby/object:Gem::Version
|
133
|
-
version: '5.
|
147
|
+
version: '5.0'
|
134
148
|
- - ">="
|
135
149
|
- !ruby/object:Gem::Version
|
136
|
-
version: 5.
|
150
|
+
version: 5.0.0
|
137
151
|
- !ruby/object:Gem::Dependency
|
138
152
|
name: faraday
|
139
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,6 +195,7 @@ executables: []
|
|
181
195
|
extensions: []
|
182
196
|
extra_rdoc_files: []
|
183
197
|
files:
|
198
|
+
- ".circleci/config.yml"
|
184
199
|
- ".editorconfig"
|
185
200
|
- ".gitignore"
|
186
201
|
- ".rspec"
|
@@ -211,6 +226,7 @@ files:
|
|
211
226
|
- lib/onesignal/commands/fetch_players.rb
|
212
227
|
- lib/onesignal/configuration.rb
|
213
228
|
- lib/onesignal/filter.rb
|
229
|
+
- lib/onesignal/included_targets.rb
|
214
230
|
- lib/onesignal/notification.rb
|
215
231
|
- lib/onesignal/notification/contents.rb
|
216
232
|
- lib/onesignal/notification/headings.rb
|