Skip to content

Commit d3ca591

Browse files
Merge branch 'release/0.6.0'
2 parents 3dcdd8c + cf89375 commit d3ca591

File tree

14 files changed

+262
-9
lines changed

14 files changed

+262
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.6.0] - 2021-10-21
10+
### Added
11+
- Support for external_player_id and for deleting a Player thanks to [@reachire-smendola] ([#35](https://github.com/mikamai/onesignal-ruby/pull/35))
12+
- Support for icons thanks to [@mtayllan] ([#33](https://github.com/mikamai/onesignal-ruby/pull/33))
13+
14+
915
## [0.5.0] - 2021-05-17
1016
### Added
11-
- Support for the email_subject field thanks to [@regedarek] ([#26](https://github.com/mikamai/onesignal-ruby/pull/26))
17+
- Support for the email_subject field thanks to [@regedarek] ([#26](https://github.com/mikamai/onesignal-ruby/pull/26))
1218
with tests contributed by [@martinjaimem] ([#28](https://github.com/mikamai/onesignal-ruby/pull/28))
1319
- Support for the email_body field thanks to [@martinjaimem] ([#29](https://github.com/mikamai/onesignal-ruby/pull/29))
1420

@@ -33,7 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3339
## [0.2.0] - 2019-01-07
3440
First public release. This version is the first publicly available on [RubyGems](https://rubygems.org/gems/onesignal-ruby).
3541

36-
[Unreleased]: https://github.com/mikamai/onesignal-ruby/compare/0.5.0...HEAD
42+
[Unreleased]: https://github.com/mikamai/onesignal-ruby/compare/0.6.0...HEAD
43+
[0.6.0]: https://github.com/mikamai/onesignal-ruby/compare/0.5.0...0.6.0
3744
[0.5.0]: https://github.com/mikamai/onesignal-ruby/compare/0.4.0...0.5.0
3845
[0.4.0]: https://github.com/mikamai/onesignal-ruby/compare/0.3.0...0.4.0
3946
[0.3.0]: https://github.com/mikamai/onesignal-ruby/compare/0.2.0...0.3.0
@@ -47,3 +54,4 @@ First public release. This version is the first publicly available on [RubyGems]
4754
[@martinjaimem]: https://github.com/martinjaimem
4855
[@regedarek]: https://github.com/regedarek
4956
[@rgould]: https://github.com/rgould
57+
[@reachire-smendola]: https://github.com/reachire-smendola

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Gem Version](https://badge.fury.io/rb/onesignal-ruby.svg)](https://badge.fury.io/rb/onesignal-ruby)
33
[![CircleCI](https://circleci.com/gh/mikamai/onesignal-ruby.svg?style=svg)](https://circleci.com/gh/mikamai/onesignal-ruby)
44

5-
A simple, pure Ruby client to the [OneSignal](https://onesignal.com/apps/22bc6dec-5150-4d6d-8628-377259d2dd14/segments) API.
5+
A simple, pure Ruby client to the [OneSignal Push Notification API](https://onesignal.com/). OneSignal provides a self-serve customer engagement solution for Push Notifications, Email, SMS & In-App.
66

77
## Installation
88

@@ -137,6 +137,13 @@ player = OneSignal.fetch_player(player_id)
137137
# => #<OneSignal::Responses::Player>
138138
```
139139

140+
### Delete players
141+
You can delete a single player by its ID.
142+
```ruby
143+
OneSignal.delete_player(player_id)
144+
#<OneSignal::Responses::Player:0x000056062f397d18 @attributes={}>
145+
```
146+
140147
### Filters
141148

142149
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
@@ -192,6 +199,23 @@ included_targets = OneSignal::IncludedTargets.new(include_player_ids: 'test-id-1
192199
OneSignal::Notification.new(included_targets: included_targets)
193200
```
194201

202+
### Icons
203+
You can customize notification icons by passing a `OneSignal::Icons` object.
204+
```ruby
205+
icons = OneSignal::Icons.new(
206+
small_icon: 'image URL',
207+
huawei_small_icon: 'image URL',
208+
large_icon: 'image URL',
209+
huawei_large_icon: 'image URL',
210+
adm_small_icon: 'image URL',
211+
adm_large_icon: 'image URL',
212+
chrome_web_icon: 'image URL',
213+
firefox_icon: 'image URL',
214+
chrome_icon: 'image URL'
215+
)
216+
OneSignal::Notification.new(icons: icons)
217+
```
218+
195219
**WARNING**
196220
Passing `include_player_ids` alongside other params is prohibited and will raise an `ArgumentError`.
197221
Either use `include_player_ids` or use the other params.
@@ -212,7 +236,7 @@ This repo is managed following the [Git Flow](https://danielkummer.github.io/git
212236
- `feature/my-awesome-branch` are personal, dedicated branches for working on actual features. They are merged in develop once completed and then deleted.
213237
- `hotfix/my-awesome-fix` are special branches dedicated to bugfixes that compromise the library functionality. They are merged
214238
in both master and develop and then deleted.
215-
239+
216240
[CHANGELOG](CHANGELOG.md) entries MUST be added for every change made to the source code.
217241

218242
## License

fixtures/vcr_cassettes/os-delete-player.yml

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/onesignal.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def fetch_player player_id
5959
Responses::Player.from_json fetched.body
6060
end
6161

62+
def delete_player player_id
63+
return unless OneSignal.config.active
64+
65+
fetched = Commands::DeletePlayer.call player_id
66+
Responses::Player.from_json fetched.body
67+
end
68+
6269
def fetch_players
6370
return unless OneSignal.config.active
6471

lib/onesignal/client.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def fetch_player player_id
4141
get "players/#{player_id}"
4242
end
4343

44+
def delete_player player_id
45+
delete "players/#{player_id}"
46+
end
47+
4448
def csv_export extra_fields: nil, last_active_since: nil, segment_name: nil
4549
post "players/csv_export?app_id=#{@app_id}",
4650
extra_fields: extra_fields,
@@ -56,6 +60,15 @@ def create_body payload
5660
body
5761
end
5862

63+
def delete url
64+
res = @conn.delete do |req|
65+
req.url url, app_id: @app_id
66+
req.headers['Authorization'] = "Basic #{@api_key}"
67+
end
68+
69+
handle_errors res
70+
end
71+
5972
def post url, body
6073
res = @conn.post do |req|
6174
req.url url
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module OneSignal
4+
module Commands
5+
class DeletePlayer < BaseCommand
6+
def initialize player_id
7+
@player_id = player_id
8+
end
9+
10+
def call
11+
client.delete_player @player_id
12+
end
13+
end
14+
end
15+
end

lib/onesignal/icons.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
module OneSignal
4+
class Icons
5+
attr_reader :small_icon, :huawei_small_icon, :large_icon, :huawei_large_icon, :adm_small_icon,
6+
:adm_large_icon, :chrome_web_icon, :firefox_icon, :chrome_icon
7+
8+
def initialize **params
9+
@small_icon = params[:small_icon]
10+
@huawei_small_icon = params[:huawei_small_icon]
11+
@large_icon = params[:large_icon]
12+
@huawei_large_icon = params[:huawei_large_icon]
13+
@adm_small_icon = params[:adm_small_icon]
14+
@adm_large_icon = params[:adm_large_icon]
15+
@chrome_web_icon = params[:chrome_web_icon]
16+
@firefox_icon = params[:firefox_icon]
17+
@chrome_icon = params[:chrome_icon]
18+
end
19+
20+
def as_json options = nil
21+
{
22+
'small_icon' => @small_icon,
23+
'huawei_small_icon' => @huawei_small_icon,
24+
'large_icon' => @large_icon,
25+
'huawei_large_icon' => @huawei_large_icon,
26+
'adm_small_icon' => @adm_small_icon,
27+
'adm_large_icon' => @adm_large_icon,
28+
'chrome_web_icon' => @chrome_web_icon,
29+
'firefox_icon' => @firefox_icon,
30+
'chrome_icon' => @chrome_icon
31+
}
32+
end
33+
end
34+
end

lib/onesignal/notification.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module OneSignal
77
class Notification
88
attr_reader :contents, :headings, :template_id, :included_segments, :excluded_segments,
99
:included_targets, :email_subject, :send_after, :attachments, :sounds, :buttons,
10-
:email_body
10+
:email_body, :icons, :external_id
1111

1212
def initialize **params
1313
unless params.include?(:contents) || params.include?(:template_id)
@@ -27,15 +27,18 @@ def initialize **params
2727
@filters = params[:filters]
2828
@sounds = params[:sounds]
2929
@buttons = params[:buttons]
30+
@icons = params[:icons]
31+
@external_id = params[:external_id]
3032
end
3133

3234
def as_json options = {}
3335
super(options)
34-
.except('attachments', 'sounds', 'included_targets')
36+
.except('attachments', 'sounds', 'included_targets', 'icons')
3537
.merge(@attachments&.as_json(options) || {})
3638
.merge(@sounds&.as_json(options) || {})
3739
.merge(@buttons&.as_json(options) || {})
3840
.merge(@included_targets&.as_json(options) || {})
41+
.merge(@icons&.as_json(options) || {})
3942
.select { |_k, v| v.present? }
4043
end
4144
end

lib/onesignal/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

33
module OneSignal
4-
VERSION = '0.5.0'
4+
VERSION = '0.6.0'
55
API_VERSION = 'v1'
66
end

spec/api_calls_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
end
6464
end
6565

66+
it 'deletes one player by id' do
67+
VCR.use_cassette('os-delete-player', :record => :new_episodes) do
68+
player = OneSignal.delete_player @player_id
69+
expect(player).to be_instance_of OneSignal::Responses::Player
70+
expect(player.id).to eq @player_id
71+
end
72+
end
73+
74+
6675
context 'with keys' do
6776
around do |example|
6877
OneSignal.config.app_id = app_id

0 commit comments

Comments
 (0)