Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoJoliveau committed Oct 21, 2021
2 parents 3dcdd8c + cf89375 commit d3ca591
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 9 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.0] - 2021-10-21
### Added
- Support for external_player_id and for deleting a Player thanks to [@reachire-smendola] ([#35](https://github.com/mikamai/onesignal-ruby/pull/35))
- Support for icons thanks to [@mtayllan] ([#33](https://github.com/mikamai/onesignal-ruby/pull/33))


## [0.5.0] - 2021-05-17
### Added
- Support for the email_subject field thanks to [@regedarek] ([#26](https://github.com/mikamai/onesignal-ruby/pull/26))
- Support for the email_subject field thanks to [@regedarek] ([#26](https://github.com/mikamai/onesignal-ruby/pull/26))
with tests contributed by [@martinjaimem] ([#28](https://github.com/mikamai/onesignal-ruby/pull/28))
- Support for the email_body field thanks to [@martinjaimem] ([#29](https://github.com/mikamai/onesignal-ruby/pull/29))

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

[Unreleased]: https://github.com/mikamai/onesignal-ruby/compare/0.5.0...HEAD
[Unreleased]: https://github.com/mikamai/onesignal-ruby/compare/0.6.0...HEAD
[0.6.0]: https://github.com/mikamai/onesignal-ruby/compare/0.5.0...0.6.0
[0.5.0]: https://github.com/mikamai/onesignal-ruby/compare/0.4.0...0.5.0
[0.4.0]: https://github.com/mikamai/onesignal-ruby/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/mikamai/onesignal-ruby/compare/0.2.0...0.3.0
Expand All @@ -47,3 +54,4 @@ First public release. This version is the first publicly available on [RubyGems]
[@martinjaimem]: https://github.com/martinjaimem
[@regedarek]: https://github.com/regedarek
[@rgould]: https://github.com/rgould
[@reachire-smendola]: https://github.com/reachire-smendola
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Gem Version](https://badge.fury.io/rb/onesignal-ruby.svg)](https://badge.fury.io/rb/onesignal-ruby)
[![CircleCI](https://circleci.com/gh/mikamai/onesignal-ruby.svg?style=svg)](https://circleci.com/gh/mikamai/onesignal-ruby)

A simple, pure Ruby client to the [OneSignal](https://onesignal.com/apps/22bc6dec-5150-4d6d-8628-377259d2dd14/segments) API.
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.

## Installation

Expand Down Expand Up @@ -137,6 +137,13 @@ player = OneSignal.fetch_player(player_id)
# => #<OneSignal::Responses::Player>
```

### Delete players
You can delete a single player by its ID.
```ruby
OneSignal.delete_player(player_id)
#<OneSignal::Responses::Player:0x000056062f397d18 @attributes={}>
```

### Filters

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

### Icons
You can customize notification icons by passing a `OneSignal::Icons` object.
```ruby
icons = OneSignal::Icons.new(
small_icon: 'image URL',
huawei_small_icon: 'image URL',
large_icon: 'image URL',
huawei_large_icon: 'image URL',
adm_small_icon: 'image URL',
adm_large_icon: 'image URL',
chrome_web_icon: 'image URL',
firefox_icon: 'image URL',
chrome_icon: 'image URL'
)
OneSignal::Notification.new(icons: icons)
```

**WARNING**
Passing `include_player_ids` alongside other params is prohibited and will raise an `ArgumentError`.
Either use `include_player_ids` or use the other params.
Expand All @@ -212,7 +236,7 @@ This repo is managed following the [Git Flow](https://danielkummer.github.io/git
- `feature/my-awesome-branch` are personal, dedicated branches for working on actual features. They are merged in develop once completed and then deleted.
- `hotfix/my-awesome-fix` are special branches dedicated to bugfixes that compromise the library functionality. They are merged
in both master and develop and then deleted.

[CHANGELOG](CHANGELOG.md) entries MUST be added for every change made to the source code.

## License
Expand Down
72 changes: 72 additions & 0 deletions fixtures/vcr_cassettes/os-delete-player.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lib/onesignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def fetch_player player_id
Responses::Player.from_json fetched.body
end

def delete_player player_id
return unless OneSignal.config.active

fetched = Commands::DeletePlayer.call player_id
Responses::Player.from_json fetched.body
end

def fetch_players
return unless OneSignal.config.active

Expand Down
13 changes: 13 additions & 0 deletions lib/onesignal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def fetch_player player_id
get "players/#{player_id}"
end

def delete_player player_id
delete "players/#{player_id}"
end

def csv_export extra_fields: nil, last_active_since: nil, segment_name: nil
post "players/csv_export?app_id=#{@app_id}",
extra_fields: extra_fields,
Expand All @@ -56,6 +60,15 @@ def create_body payload
body
end

def delete url
res = @conn.delete do |req|
req.url url, app_id: @app_id
req.headers['Authorization'] = "Basic #{@api_key}"
end

handle_errors res
end

def post url, body
res = @conn.post do |req|
req.url url
Expand Down
15 changes: 15 additions & 0 deletions lib/onesignal/commands/delete_player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module OneSignal
module Commands
class DeletePlayer < BaseCommand
def initialize player_id
@player_id = player_id
end

def call
client.delete_player @player_id
end
end
end
end
34 changes: 34 additions & 0 deletions lib/onesignal/icons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module OneSignal
class Icons
attr_reader :small_icon, :huawei_small_icon, :large_icon, :huawei_large_icon, :adm_small_icon,
:adm_large_icon, :chrome_web_icon, :firefox_icon, :chrome_icon

def initialize **params
@small_icon = params[:small_icon]
@huawei_small_icon = params[:huawei_small_icon]
@large_icon = params[:large_icon]
@huawei_large_icon = params[:huawei_large_icon]
@adm_small_icon = params[:adm_small_icon]
@adm_large_icon = params[:adm_large_icon]
@chrome_web_icon = params[:chrome_web_icon]
@firefox_icon = params[:firefox_icon]
@chrome_icon = params[:chrome_icon]
end

def as_json options = nil
{
'small_icon' => @small_icon,
'huawei_small_icon' => @huawei_small_icon,
'large_icon' => @large_icon,
'huawei_large_icon' => @huawei_large_icon,
'adm_small_icon' => @adm_small_icon,
'adm_large_icon' => @adm_large_icon,
'chrome_web_icon' => @chrome_web_icon,
'firefox_icon' => @firefox_icon,
'chrome_icon' => @chrome_icon
}
end
end
end
7 changes: 5 additions & 2 deletions lib/onesignal/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module OneSignal
class Notification
attr_reader :contents, :headings, :template_id, :included_segments, :excluded_segments,
:included_targets, :email_subject, :send_after, :attachments, :sounds, :buttons,
:email_body
:email_body, :icons, :external_id

def initialize **params
unless params.include?(:contents) || params.include?(:template_id)
Expand All @@ -27,15 +27,18 @@ def initialize **params
@filters = params[:filters]
@sounds = params[:sounds]
@buttons = params[:buttons]
@icons = params[:icons]
@external_id = params[:external_id]
end

def as_json options = {}
super(options)
.except('attachments', 'sounds', 'included_targets')
.except('attachments', 'sounds', 'included_targets', 'icons')
.merge(@attachments&.as_json(options) || {})
.merge(@sounds&.as_json(options) || {})
.merge(@buttons&.as_json(options) || {})
.merge(@included_targets&.as_json(options) || {})
.merge(@icons&.as_json(options) || {})
.select { |_k, v| v.present? }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/onesignal/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module OneSignal
VERSION = '0.5.0'
VERSION = '0.6.0'
API_VERSION = 'v1'
end
9 changes: 9 additions & 0 deletions spec/api_calls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
end
end

it 'deletes one player by id' do
VCR.use_cassette('os-delete-player', :record => :new_episodes) do
player = OneSignal.delete_player @player_id
expect(player).to be_instance_of OneSignal::Responses::Player
expect(player.id).to eq @player_id
end
end


context 'with keys' do
around do |example|
OneSignal.config.app_id = app_id
Expand Down
17 changes: 17 additions & 0 deletions spec/factories/icons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

FactoryBot.define do
factory :icons, class: OneSignal::Icons do
small_icon { Faker::Avatar.image }
huawei_small_icon { Faker::Avatar.image }
large_icon { Faker::Avatar.image }
huawei_large_icon { Faker::Avatar.image }
adm_small_icon { Faker::Avatar.image }
adm_large_icon { Faker::Avatar.image }
chrome_web_icon { Faker::Avatar.image }
firefox_icon { Faker::Avatar.image }
chrome_icon { Faker::Avatar.image }

initialize_with { new(attributes) }
end
end
1 change: 1 addition & 0 deletions spec/factories/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
contents
headings
attachments { build :attachments }
icons { build :icons }
included_segments { [build(:segment), build(:segment)] }
excluded_segments { [build(:segment), build(:segment)] }
send_after { Time.now }
Expand Down
39 changes: 39 additions & 0 deletions spec/onesignal/icons_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'spec_helper'

describe OneSignal::Icons do
let(:params) do
{
small_icon: Faker::Avatar.image,
huawei_small_icon: Faker::Avatar.image,
large_icon: Faker::Avatar.image,
huawei_large_icon: Faker::Avatar.image,
adm_small_icon: Faker::Avatar.image,
adm_large_icon: Faker::Avatar.image,
chrome_web_icon: Faker::Avatar.image,
firefox_icon: Faker::Avatar.image,
chrome_icon: Faker::Avatar.image
}
end

subject { build :icons }

it 'creates an attachment' do
expect(described_class.new(params)).to be_instance_of OneSignal::Icons
end

it 'serializes as json' do
expect(subject.as_json.deep_symbolize_keys).to include(
small_icon: subject.small_icon,
huawei_small_icon: subject.huawei_small_icon,
large_icon: subject.large_icon,
huawei_large_icon: subject.huawei_large_icon,
adm_small_icon: subject.adm_small_icon,
adm_large_icon: subject.adm_large_icon,
chrome_web_icon: subject.chrome_web_icon,
firefox_icon: subject.firefox_icon,
chrome_icon: subject.chrome_icon
)
end
end
Loading

0 comments on commit d3ca591

Please sign in to comment.