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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 754c561ba01eaaaa715c61f8f4016309679cdd0c34a5d830dd031f1e5f905a53
4
+ data.tar.gz: 51835e1af00b1ce9f0e1c4fcab7da9ddb5e9e94939236f11d054e8922cc6e71c
5
+ SHA512:
6
+ metadata.gz: 535958641b3d7bfe27eaa6509155c91d2607b0c56597d91b1eeea0956fd948404c5078385613abac1061e7722663240028fe6b6cb3c7331b843a4b05c01a49eb
7
+ data.tar.gz: 779675317569ebc0cde184c31be27a6b870162041ab3947870c7487974d8eb419ebb578b1df0748dc4ee054df64948017a924788de1836963a8e40107e841c6a
data/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ charset = utf-8
7
+ insert_final_newline = true
8
+ trim_trailing_whitespace = true
9
+ end_of_line = lf
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ [*.md]
14
+ trim_trailing_whitespace = false
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .idea/
14
+ *.iml
15
+ .env
16
+ .env.*
17
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,182 @@
1
+ AllCops:
2
+ # Cop names are not displayed in offense messages by default. Change behavior
3
+ # by overriding DisplayCopNames, or by giving the `-D/--display-cop-names`
4
+ # option.
5
+ DisplayCopNames: true
6
+
7
+ # Style guide URLs are not displayed in offense messages by default. Change
8
+ # behavior by overriding `DisplayStyleGuide`, or by giving the
9
+ # `-S/--display-style-guide` option.
10
+ DisplayStyleGuide: true
11
+
12
+ # Extra details are not displayed in offense messages by default. Change
13
+ # behavior by overriding ExtraDetails, or by giving the
14
+ # `-E/--extra-details` option.
15
+ ExtraDetails: true
16
+
17
+ # What MRI version of the Ruby interpreter is the inspected code intended to
18
+ # run on? (If there is more than one, set this to the lowest version.)
19
+ # If a value is specified for TargetRubyVersion then it is used.
20
+ # Else if .ruby-version exists and it contains an MRI version it is used.
21
+ # Otherwise we fallback to the oldest officially supported Ruby version (2.1).
22
+ TargetRubyVersion: 2.4
23
+
24
+ # Align the elements of a hash literal if they span more than one line.
25
+ Layout/AlignHash:
26
+ # Alignment of entries using hash rocket as separator. Valid values are:
27
+ #
28
+ # key - left alignment of keys
29
+ # 'a' => 2
30
+ # 'bb' => 3
31
+ # separator - alignment of hash rockets, keys are right aligned
32
+ # 'a' => 2
33
+ # 'bb' => 3
34
+ # table - left alignment of keys, hash rockets, and values
35
+ # 'a' => 2
36
+ # 'bb' => 3
37
+ EnforcedHashRocketStyle: table
38
+ SupportedHashRocketStyles:
39
+ - key
40
+ - separator
41
+ - table
42
+ # Alignment of entries using colon as separator. Valid values are:
43
+ #
44
+ # key - left alignment of keys
45
+ # a: 0
46
+ # bb: 1
47
+ # separator - alignment of colons, keys are right aligned
48
+ # a: 0
49
+ # bb: 1
50
+ # table - left alignment of keys and values
51
+ # a: 0
52
+ # bb: 1
53
+ EnforcedColonStyle: table
54
+ SupportedColonStyles:
55
+ - key
56
+ - separator
57
+ - table
58
+ # Select whether hashes that are the last argument in a method call should be
59
+ # inspected? Valid values are:
60
+ #
61
+ # always_inspect - Inspect both implicit and explicit hashes.
62
+ # Registers an offense for:
63
+ # function(a: 1,
64
+ # b: 2)
65
+ # Registers an offense for:
66
+ # function({a: 1,
67
+ # b: 2})
68
+ # always_ignore - Ignore both implicit and explicit hashes.
69
+ # Accepts:
70
+ # function(a: 1,
71
+ # b: 2)
72
+ # Accepts:
73
+ # function({a: 1,
74
+ # b: 2})
75
+ # ignore_implicit - Ignore only implicit hashes.
76
+ # Accepts:
77
+ # function(a: 1,
78
+ # b: 2)
79
+ # Registers an offense for:
80
+ # function({a: 1,
81
+ # b: 2})
82
+ # ignore_explicit - Ignore only explicit hashes.
83
+ # Accepts:
84
+ # function({a: 1,
85
+ # b: 2})
86
+ # Registers an offense for:
87
+ # function(a: 1,
88
+ # b: 2)
89
+ EnforcedLastArgumentHashStyle: ignore_implicit
90
+ SupportedLastArgumentHashStyles:
91
+ - always_inspect
92
+ - always_ignore
93
+ - ignore_implicit
94
+ - ignore_explicit
95
+
96
+ Layout/EndOfLine:
97
+ # The `native` style means that CR+LF (Carriage Return + Line Feed) is
98
+ # enforced on Windows, and LF is enforced on other platforms. The other styles
99
+ # mean LF and CR+LF, respectively.
100
+ EnforcedStyle: lf
101
+ SupportedStyles:
102
+ - native
103
+ - lf
104
+ - crlf
105
+
106
+ Style/BlockDelimiters:
107
+ EnforcedStyle: braces_for_chaining
108
+ SupportedStyles:
109
+ # The `line_count_based` style enforces braces around single line blocks and
110
+ # do..end around multi-line blocks.
111
+ - line_count_based
112
+ # The `semantic` style enforces braces around functional blocks, where the
113
+ # primary purpose of the block is to return a value and do..end for
114
+ # procedural blocks, where the primary purpose of the block is its
115
+ # side-effects.
116
+ #
117
+ # This looks at the usage of a block's method to determine its type (e.g. is
118
+ # the result of a `map` assigned to a variable or passed to another
119
+ # method) but exceptions are permitted in the `ProceduralMethods`,
120
+ # `FunctionalMethods` and `IgnoredMethods` sections below.
121
+ - semantic
122
+ # The `braces_for_chaining` style enforces braces around single line blocks
123
+ # and do..end around multi-line blocks, except for multi-line blocks whose
124
+ # return value is being chained with another method (in which case braces
125
+ # are enforced).
126
+ - braces_for_chaining
127
+
128
+ Style/Documentation:
129
+ Enabled: false
130
+
131
+ Style/MethodDefParentheses:
132
+ EnforcedStyle: require_no_parentheses
133
+ SupportedStyles:
134
+ - require_parentheses
135
+ - require_no_parentheses
136
+ - require_no_parentheses_except_multiline
137
+
138
+ Style/RedundantReturn:
139
+ # When `true` allows code like `return x, y`.
140
+ AllowMultipleReturnValues: true
141
+
142
+ Style/Semicolon:
143
+ # Allow `;` to separate several expressions on the same line.
144
+ AllowAsExpressionSeparator: true
145
+
146
+ Metrics/BlockLength:
147
+ Exclude:
148
+ - "**/*_spec.rb"
149
+
150
+ Metrics/LineLength:
151
+ Max: 100
152
+ # To make it possible to copy or click on URIs in the code, we allow lines
153
+ # containing a URI to be longer than Max.
154
+ AllowHeredoc: true
155
+ AllowURI: true
156
+ URISchemes:
157
+ - http
158
+ - https
159
+ - ftp
160
+ # The IgnoreCopDirectives option causes the LineLength rule to ignore cop
161
+ # directives like '# rubocop: enable ...' when calculating a line's length.
162
+ IgnoreCopDirectives: false
163
+ # The IgnoredPatterns option is a list of !ruby/regexp and/or string
164
+ # elements. Strings will be converted to Regexp objects. A line that matches
165
+ # any regular expression listed in this option will be ignored by LineLength.
166
+ IgnoredPatterns: []
167
+
168
+ # Align ends correctly.
169
+ Lint/EndAlignment:
170
+ # The value `keyword` means that `end` should be aligned with the matching
171
+ # keyword (`if`, `while`, etc.).
172
+ # The value `variable` means that in assignments, `end` should be aligned
173
+ # with the start of the variable on the left hand side of `=`. In all other
174
+ # situations, `end` should still be aligned with the keyword.
175
+ # The value `start_of_line` means that `end` should be aligned with the start
176
+ # of the line which the matching keyword appears on.
177
+ EnforcedStyleAlignWith: variable
178
+ SupportedStylesAlignWith:
179
+ - keyword
180
+ - variable
181
+ - start_of_line
182
+ AutoCorrect: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at matteo.joliveau@mikamai.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in onesignal-ruby.gemspec
8
+ gemspec
9
+
10
+ group :test do
11
+ gem 'faker', git: 'https://github.com/stympy/faker.git', branch: 'master'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ GIT
2
+ remote: https://github.com/stympy/faker.git
3
+ revision: 41b212d6512eae974d612af7dab593ca8ab01349
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.2, >= 5.2.2)
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
+ safe_yaml (1.0.4)
57
+ simple_command (0.0.9)
58
+ thread_safe (0.3.6)
59
+ tzinfo (1.2.5)
60
+ thread_safe (~> 0.1)
61
+ vcr (4.0.0)
62
+ webmock (3.5.1)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+ hashdiff
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler (~> 1.16)
72
+ dotenv (~> 2.5)
73
+ factory_bot (~> 4.11)
74
+ faker!
75
+ onesignal-ruby!
76
+ rake (~> 10.0)
77
+ rspec (~> 3.0)
78
+ vcr (~> 4.0, >= 4.0.0)
79
+ webmock (~> 3.4)
80
+
81
+ BUNDLED WITH
82
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Mikamai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # OneSignal Ruby Client
2
+
3
+ A simple, pure Ruby client to the [OneSignal](https://onesignal.com/apps/22bc6dec-5150-4d6d-8628-377259d2dd14/segments) API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ### COMING SOON (not yet published)
10
+ ```ruby
11
+ gem 'onesignal-ruby'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install onesignal-ruby
21
+
22
+ ## Configuration
23
+ OneSignal requires an App ID and an API Key, which can be found
24
+ on the OneSignal dashboard.
25
+ By default, OneSignal Ruby looks for them in the environment, loading
26
+ `ONESIGNAL_APP_ID` and `ONESIGNAL_API_KEY` variables.
27
+
28
+ It also defaults to `https://onesignal.com/api/v1` as the API URL.
29
+
30
+ You can also turn off OneSignal entirely with a boolean flag (for example to avoid sending
31
+ notification while in test or development environments)
32
+
33
+ To customize those values, call the following snippet during your
34
+ initialization phase.
35
+
36
+ ```ruby
37
+ OneSignal.configure do |config|
38
+ config.app_id = 'my_app_id'
39
+ config.api_key = 'my_api_key'
40
+ config.api_url = 'http://my_api_url'
41
+ config.active = false
42
+ end
43
+ ```
44
+ ## Usage
45
+
46
+ ### Create a notification
47
+
48
+ Create a `Notification` object.
49
+ ```ruby
50
+ # Create headings for different languages. English is required.
51
+ headings = OneSignal::Notification::Headings.new(en: 'Hello!', it: 'Ciao!')
52
+
53
+ # Create contents for different languages. English is required.
54
+ contents = OneSignal::Notification::Contents.new(en: "I'm a notification!", it: 'Sono una notifica!')
55
+
56
+ # Select the included (and/or excluded) segments to target
57
+ included_segments = [OneSignal::Segment::ACTIVE_USERS, 'My custom segment']
58
+
59
+ # Create the Notification object
60
+ notification = OneSignal::Notification.new(headings: headings, contents: contents, included_segments: included_segments)
61
+ ```
62
+
63
+ Then send it.
64
+ ```ruby
65
+ response = OneSignal.send_notification(notification)
66
+ # => #<OneSignal::Responses::Notification> the created notification
67
+ ```
68
+
69
+ ### Fetch a notification
70
+ You can fetch an existing notification given its ID.
71
+ ```ruby
72
+ response = OneSignal.fetch_notification(notification_id)
73
+ # => #<OneSignal::Responses::Notification> the created notification
74
+ ```
75
+ `OneSignal::Responses::Notification` has the following fields.
76
+ ```ruby
77
+ id # Notification UUID
78
+ successful # Number of successful deliveries
79
+ failed # Number of failed deliveries
80
+ converted # Number of users who have clicked / tapped on your notification.
81
+ remaining # Number of notifications that have not been sent out yet
82
+ queued_at # Unix timestamp of enqueuing time
83
+ send_after # Unix timestamp indicating when notification delivery should begin
84
+ completed_at # Unix timestamp indicating when notification delivery completed.
85
+ url # URL associated with the notification
86
+ data # Custom metadata
87
+ canceled # Boolean, has the notification been canceled
88
+ headings # Map of locales to title strings
89
+ contents # Map of locales to content strings
90
+
91
+ response.id # => fe82c1ae-54c2-458b-8aad-7edc3e8a96c4
92
+ ```
93
+
94
+ ### Attachments
95
+ You can add files, data or images to a notification, or an external URL to open.
96
+ ```ruby
97
+ attachments = OneSignal::Attachments.new(
98
+ data: { 'test' => 'test' },
99
+ url: 'http://example.com',
100
+ ios_attachments: { 'something' => 'drawable resource name or URL.' },
101
+ android_picture: 'drawable resource name or URL.',
102
+ amazon_picture: 'drawable resource name or URL.',
103
+ chrome_picture: 'drawable resource name or URL.'
104
+ )
105
+
106
+ OneSignal::Notification.new(attachments: attachments)
107
+ ```
108
+
109
+ ### Fetch players
110
+ You can fetch all players and devices with a simple method.
111
+
112
+ ```ruby
113
+ players = OneSignal.fetch_players
114
+ # => Array of OneSignal::Responses::Player
115
+ ```
116
+
117
+ Or you can fetch a single player by its ID.
118
+ ```ruby
119
+ player = OneSignal.fetch_player(player_id)
120
+ # => #<OneSignal::Responses::Player>
121
+ ```
122
+
123
+ ### Filters
124
+
125
+ Filters can be created with a simple DSL. It closely matches the [JSON reference](), with a few touches of syntax
126
+ sugar.
127
+
128
+ **Example**
129
+ ```ruby
130
+ filters = [
131
+ OneSignal::Filter.last_session.lesser_than(2).hours_ago!,
132
+ OneSignal::Filter.session_count.equals(5),
133
+ OneSignal::Filter::OR,
134
+ OneSignal::Filter.country.equals('IT')
135
+ ]
136
+
137
+ OneSignal::Notification.new(filters: filters)
138
+ ```
139
+ Becomes
140
+ ```json
141
+ [
142
+ {"field":"last_session","relation":"<","hours_ago":"2"},
143
+ {"field":"session_count","relation":"=","value":"5"},
144
+ {"operator":"OR"},
145
+ {"field":"country","relation":"=","value":"IT"}
146
+ ]
147
+ ```
148
+
149
+ ### Custom Sounds
150
+ You can customize notification sounds by passing a `OneSignal::Sounds` object.
151
+ ```ruby
152
+ sounds = OneSignal::Sounds.new(ios: 'ping.wav', android: 'ping')
153
+ OneSignal::Notification.new(sounds: sounds)
154
+ ```
155
+
156
+ ## Development
157
+
158
+ 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.
159
+
160
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
161
+
162
+ ## Contributing
163
+
164
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mikamai/onesignal-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
165
+
166
+ This repo is managed following the [Git Flow](https://danielkummer.github.io/git-flow-cheatsheet/) principles.
167
+ - `master` is the stable, production-ready branch. Never work directly on it. The gem is published from this branch.
168
+ - `develop` is the active development branch. It is supposed to be somewhat stable. Every new feature is merged here once completed, before being released to master.
169
+ - `feature/my-awesome-branch` are personal, dedicated branches for working on actual features. They are merged in develop once completed and then deleted.
170
+ - `hotfix/my-awesome-fix` are special branches dedicated to bugfixes that compromise the library functionality. They are merged
171
+ in both master and develop and then deleted.
172
+
173
+ ## License
174
+
175
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
176
+
177
+ ## Code of Conduct
178
+
179
+ Everyone interacting in the OneSignal Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).