onesignal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +15 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +139 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/onesignal.rb +23 -0
- data/lib/onesignal/app_id_missing_error.rb +7 -0
- data/lib/onesignal/client.rb +34 -0
- data/lib/onesignal/models/app.rb +37 -0
- data/lib/onesignal/models/base_model.rb +19 -0
- data/lib/onesignal/models/notification.rb +16 -0
- data/lib/onesignal/models/player.rb +24 -0
- data/lib/onesignal/request.rb +94 -0
- data/lib/onesignal/request_error.rb +21 -0
- data/lib/onesignal/resources/app_resource.rb +27 -0
- data/lib/onesignal/resources/base_resource.rb +35 -0
- data/lib/onesignal/resources/notification_resource.rb +33 -0
- data/lib/onesignal/resources/player_resource.rb +53 -0
- data/lib/onesignal/version.rb +3 -0
- data/onesignal.gemspec +26 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0425bbf023a93b56cbf6822e82ca90ec0e9ddd17
|
4
|
+
data.tar.gz: 53a5b0e44ac0b652f852c25e5675ff3e0f211146
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e635f56e0636dcb21596c465a9f9aa65c061accd814d6a959019792852900f544a18b0866811915b8ad50e9bc3421d117a40ebffc94be496c8720da9674738e
|
7
|
+
data.tar.gz: 103a67b3abd506225e4b08f06da30a73fb7ddaf3f52bf6fb4a0ba1391a0ce874e6c385ad13e85f5721c77ace5ab9ced45fa1670ebaecadb6c9320cb947f9c5e0
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 2.1.0
|
6
|
+
- 2.2.0
|
7
|
+
- 2.3.0
|
8
|
+
|
9
|
+
before_install:
|
10
|
+
- gem install bundler -v 1.11.2
|
11
|
+
|
12
|
+
notifications:
|
13
|
+
slack:
|
14
|
+
rooms:
|
15
|
+
secure: Gr8OCGVXegUFZmA0GYQnvAMs6cei1139C7sce13VvcG1HulIvpidnobJuNghfTx44psQTYDptHpz8AVn+kChbsQ46+0zXdNgCq2t9fJAVzTlTGnsB5O28FjUUEJAppjztUeRPKJX+B284AHJ0ZM/Vw7upoJ9IPbJ9bpcr5Xbms8eF/iYmJcicZ7iZNkHET8PFKqQP4H4/ahBOHfiI150zys1Pjos66wRukss1K52i6cvGmMajx58aVxDdwrw8wksNOHFu7VuoThipNHTIFyzr39EdG+DDrrfDLkLtpcb4+3QFn3/XZO7WHNfubnUY2DQ9xZrn8mUgIBFx6bVbcZ+xt/eh+4h5cDQyeEFY3GI+GiWJBDQa8VS69+CZQqEAvBNzHMPAkp19DZt0KFPEQqNG7KwXwuMx/kVsbnDhSGGN7d1Dc2m1XXVHViOUS6YePPzwjOZ3B7MTtb4FFSnsDeYvFFeBxqkX7a25L4llR9AcBMMxgCHDJi070qr3bOoQv9Qwi/Xw4P92ZLQ+VRoskzPRmbFcdfZxsI6R9orxJ1YgA/FGuQZAbmVQ3gZAWcW4iP1sgYh8EkOUH/c1c5tb03gC4OyU1R44L/FBBQiAXBCAl50PhJgCR13KrR6vxBnV/AIg+Pbk1uQPx4zqda4UbertMc+bB0M6EDV9OUPezb59Pk=
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at babartmann@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Bastian Bartmann
|
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,139 @@
|
|
1
|
+
# OneSignal
|
2
|
+
|
3
|
+
[![Build Status][trb]][trl] [![Code Climate][ccb]][ccl]
|
4
|
+
|
5
|
+
OneSignal is a simple ruby wrapper for the [OneSignal API][osa].
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'onesignal'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install onesignal
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You can find your auth keys and app IDs on the Account Management page when
|
26
|
+
you're logged into OneSignal. With those at hand, you can create a client.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
client = OneSignal::Client.new((auth_token: 'AUTH_TOKEN', app_id: 'APP_ID')
|
30
|
+
```
|
31
|
+
|
32
|
+
### Design
|
33
|
+
|
34
|
+
This gem follows a strict design of resoures as methods on your client. For
|
35
|
+
examples, for apps, you will call your client like this:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN')
|
39
|
+
client.apps #=> AppResource
|
40
|
+
```
|
41
|
+
|
42
|
+
It will return objects that contain the information provided by the API. For
|
43
|
+
example:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN')
|
47
|
+
client.apps.all
|
48
|
+
# => [ OneSignal::App(id: '92911750-242d-4260-9e00-9d9034f139ce', name: 'Your App 1', ...), OneSignal::App(id: 'e4e87830-b954-11e3-811d-f3b376925f15', name: Your app 2', ...) ]
|
49
|
+
```
|
50
|
+
|
51
|
+
To retrieve objects, you can perform this type of action on the resource (if
|
52
|
+
the API supports it):
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN')
|
56
|
+
app = client.apps.find(id: 'e4e87830-b954-11e3-811d-f3b376925f15')
|
57
|
+
# => OneSignal::App(id: 'e4e87830-b954-11e3-811d-f3b376925f15', name: 'Your app', ...)
|
58
|
+
```
|
59
|
+
|
60
|
+
To create objects, you just have to build a params hash and pass it to the
|
61
|
+
action on the resource:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN')
|
65
|
+
params = { name: 'Your app', apns_env: 'sandbox', ... }
|
66
|
+
app = client.apps.create(params)
|
67
|
+
# => OneSignal::App(id: 'e4e87830-b954-11e3-811d-f3b376925f15', name: 'Your app', ...)
|
68
|
+
```
|
69
|
+
|
70
|
+
### All Resources and actions
|
71
|
+
|
72
|
+
#### App resource
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN')
|
76
|
+
client.apps #=> OneSignal::AppResource
|
77
|
+
```
|
78
|
+
|
79
|
+
Actions supported:
|
80
|
+
|
81
|
+
* `client.apps.all`
|
82
|
+
* `client.apps.find(id)`
|
83
|
+
* `client.apps.create(params)`
|
84
|
+
* `client.apps.update(id, params)`
|
85
|
+
|
86
|
+
#### Player resource
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN', app_id: 'APP_ID')
|
90
|
+
client.players #=> OneSignal::PlayerResource
|
91
|
+
```
|
92
|
+
|
93
|
+
Actions supported:
|
94
|
+
|
95
|
+
* `client.players.all`
|
96
|
+
* `client.players.all(params)`
|
97
|
+
* `client.players.find(id)`
|
98
|
+
* `client.players.create(params)`
|
99
|
+
* `client.players.update(id, params)`
|
100
|
+
* `client.players.on_session(id, params)`
|
101
|
+
* `client.players.on_purchase(id, params)`
|
102
|
+
* `client.players.on_focus(id, params)`
|
103
|
+
* `client.players.csv_export(id)`
|
104
|
+
|
105
|
+
#### Notification resource
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
client = OneSignal::Client.new(auth_token: 'AUTH_TOKEN', app_id: 'APP_ID')
|
109
|
+
client.notifications #=> OneSignal::NotificationResource
|
110
|
+
```
|
111
|
+
|
112
|
+
Actions supported:
|
113
|
+
|
114
|
+
* `client.notifications.all`
|
115
|
+
* `client.notifications.all(params)`
|
116
|
+
* `client.notifications.find(id)`
|
117
|
+
* `client.notifications.track_open(id, params)`
|
118
|
+
* `client.notifications.create(params)`
|
119
|
+
* `client.notifications.cancel(id)`
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
Bug reports and pull requests are welcome on [GitHub][gh].
|
124
|
+
|
125
|
+
This project is intended to be a safe, welcoming space for collaboration, and
|
126
|
+
contributors are expected to adhere to the [Contributor Covenant][cc] code of conduct.
|
127
|
+
|
128
|
+
## License
|
129
|
+
|
130
|
+
The gem is available as open source under the terms of the [MIT License][mit].
|
131
|
+
|
132
|
+
[trb]: https://travis-ci.org/coding-chimp/onesignal.svg?branch=master
|
133
|
+
[trl]: https://travis-ci.org/coding-chimp/onesignal
|
134
|
+
[ccb]: https://codeclimate.com/github/coding-chimp/onesignal/badges/gpa.svg
|
135
|
+
[ccl]: https://codeclimate.com/github/coding-chimp/onesignal
|
136
|
+
[osa]: https://documentation.onesignal.com/docs/server-api-overview
|
137
|
+
[cc]: http://contributor-covenant.org
|
138
|
+
[gh]: https://github.com/coding-chimp/onesignal
|
139
|
+
[mit]: http://opensource.org/licenses/MIT
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'onesignal'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/onesignal.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'onesignal/version'
|
2
|
+
require 'onesignal/client'
|
3
|
+
require 'onesignal/request'
|
4
|
+
require 'onesignal/request_error'
|
5
|
+
require 'onesignal/app_id_missing_error'
|
6
|
+
require 'onesignal/models/base_model'
|
7
|
+
require 'onesignal/models/app'
|
8
|
+
require 'onesignal/models/player'
|
9
|
+
require 'onesignal/models/notification'
|
10
|
+
require 'onesignal/resources/base_resource'
|
11
|
+
require 'onesignal/resources/app_resource'
|
12
|
+
require 'onesignal/resources/player_resource'
|
13
|
+
require 'onesignal/resources/notification_resource'
|
14
|
+
|
15
|
+
module OneSignal
|
16
|
+
DEVICE_TYPES = %w(
|
17
|
+
ios android amazon mpns chrome_app chrome_website wns safari firefox
|
18
|
+
).freeze
|
19
|
+
|
20
|
+
def self.device_type_as_integer(device_type)
|
21
|
+
DEVICE_TYPES.index(device_type)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class Client
|
3
|
+
BASE_URL = 'https://onesignal.com/api/v1'.freeze
|
4
|
+
|
5
|
+
attr_reader :auth_token, :app_id
|
6
|
+
|
7
|
+
def initialize(auth_token:, app_id: nil)
|
8
|
+
@auth_token = auth_token
|
9
|
+
@app_id = app_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def apps
|
13
|
+
@apps ||= AppResource.new(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def players
|
17
|
+
ensure_app_id_presence
|
18
|
+
|
19
|
+
@players ||= PlayerResource.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def notifications
|
23
|
+
ensure_app_id_presence
|
24
|
+
|
25
|
+
@notifications ||= NotificationResource.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def ensure_app_id_presence
|
31
|
+
raise AppIdMissingError if app_id.nil?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
class App < BaseModel
|
5
|
+
DATE_REGEX = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
|
6
|
+
|
7
|
+
attr_accessor :apns_certificates, :apns_env, :basic_auth_key, :chrome_key,
|
8
|
+
:chrome_web_default_notification_icon, :chrome_web_gcm_sender_id,
|
9
|
+
:chrome_web_origin, :chrome_web_sub_domain, :created_at, :gcm_key, :id,
|
10
|
+
:messageable_players, :name, :players, :safari_apns_certificate,
|
11
|
+
:safari_icon_128_128, :safari_icon_16_16, :safari_icon_256_256,
|
12
|
+
:safari_icon_32_32, :safari_icon_64_64, :safari_push_id,
|
13
|
+
:safari_site_origin, :site_name, :updated_at
|
14
|
+
|
15
|
+
def created_at=(time)
|
16
|
+
parse_time('created_at', time)
|
17
|
+
end
|
18
|
+
|
19
|
+
def updated_at=(time)
|
20
|
+
parse_time('updated_at', time)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse_time(attribute, value)
|
26
|
+
if string_date?(value)
|
27
|
+
value = Time.parse(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
instance_variable_set("@#{attribute}", value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def string_date?(date)
|
34
|
+
date.is_a?(String) && date.match(DATE_REGEX)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class BaseModel
|
3
|
+
def self.to_proc
|
4
|
+
method(:new).to_proc
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
attributes.each { |key, value| send("#{key}=", value) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
values = Hash[
|
13
|
+
instance_variables.map { |name| [name, instance_variable_get(name)] }
|
14
|
+
]
|
15
|
+
|
16
|
+
"<#{self.class.name} #{values}>"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class Notification < BaseModel
|
3
|
+
attr_accessor :canceled, :contents, :converted, :data, :errored, :failed,
|
4
|
+
:headings, :id, :include_player_ids, :included_segments, :isAdm,
|
5
|
+
:isAndroid, :isChrome, :isChromeWeb, :isFirefox, :isIos, :isSafari,
|
6
|
+
:isWP, :isWP_WNS, :queued_at, :remaining, :send_after, :successful, :url
|
7
|
+
|
8
|
+
def queued_at=(time)
|
9
|
+
@queued_at = Time.at(time)
|
10
|
+
end
|
11
|
+
|
12
|
+
def send_after=(time)
|
13
|
+
@send_after = Time.at(time)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class Player < BaseModel
|
3
|
+
attr_accessor :ad_id, :amount_spent, :badge_count, :created_at,
|
4
|
+
:device_model, :device_os, :device_type, :game_version, :id, :identifier,
|
5
|
+
:invalid_identifier, :language, :last_active, :playtime, :session_count,
|
6
|
+
:sdk, :tags, :timezone
|
7
|
+
|
8
|
+
def created_at=(time)
|
9
|
+
@created_at = Time.at(time)
|
10
|
+
end
|
11
|
+
|
12
|
+
def device_type=(type)
|
13
|
+
if type.is_a?(Integer)
|
14
|
+
type = OneSignal::DEVICE_TYPES[type]
|
15
|
+
end
|
16
|
+
|
17
|
+
@device_type = type
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_active=(time)
|
21
|
+
@last_active = Time.at(time)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
class Request
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(path, params = {})
|
10
|
+
uri = uri(path)
|
11
|
+
|
12
|
+
if @client.app_id
|
13
|
+
params[:app_id] = @client.app_id
|
14
|
+
end
|
15
|
+
|
16
|
+
uri.query = URI.encode_www_form(params)
|
17
|
+
|
18
|
+
request(uri, Net::HTTP::Get)
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(path, params)
|
22
|
+
uri = uri(path)
|
23
|
+
request(uri, Net::HTTP::Post, params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(path, params)
|
27
|
+
uri = uri(path)
|
28
|
+
request(uri, Net::HTTP::Put, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(path, params = {})
|
32
|
+
uri = uri(path)
|
33
|
+
|
34
|
+
if @client.app_id
|
35
|
+
params[:app_id] = @client.app_id
|
36
|
+
end
|
37
|
+
|
38
|
+
uri.query = URI.encode_www_form(params)
|
39
|
+
|
40
|
+
request(uri, Net::HTTP::Delete, params)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def uri(path)
|
46
|
+
URI.parse(OneSignal::Client::BASE_URL + path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def request(uri, klass, params = nil)
|
50
|
+
request = klass.new(uri.request_uri)
|
51
|
+
|
52
|
+
if params && @client.app_id
|
53
|
+
params[:app_id] = @client.app_id
|
54
|
+
end
|
55
|
+
|
56
|
+
if params
|
57
|
+
request.body = params.to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
response = make_request(uri, request)
|
61
|
+
|
62
|
+
ensure_success(response, uri, params)
|
63
|
+
|
64
|
+
response
|
65
|
+
end
|
66
|
+
|
67
|
+
def make_request(uri, request)
|
68
|
+
add_headers(request)
|
69
|
+
http = http_object(uri)
|
70
|
+
http.request(request)
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_headers(request)
|
74
|
+
request.add_field('Content-Type', 'application/json')
|
75
|
+
request.add_field('Authorization', "Basic #{@client.auth_token}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def http_object(uri)
|
79
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
80
|
+
http.use_ssl = true
|
81
|
+
http.open_timeout = 30
|
82
|
+
http.read_timeout = 30
|
83
|
+
|
84
|
+
http
|
85
|
+
end
|
86
|
+
|
87
|
+
def ensure_success(response, uri, params = nil)
|
88
|
+
if response.code != '200'
|
89
|
+
message = "OneSignal error - uri: #{uri} - params: #{params}"
|
90
|
+
raise RequestError.new(message, response.code, response.body)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class RequestError < StandardError
|
3
|
+
attr_reader :http_status
|
4
|
+
attr_reader :http_body
|
5
|
+
|
6
|
+
def initialize(message, http_status, http_body)
|
7
|
+
@http_status = http_status
|
8
|
+
@http_body = http_body
|
9
|
+
|
10
|
+
if @http_status
|
11
|
+
message += " - http status : #{@http_status}"
|
12
|
+
end
|
13
|
+
|
14
|
+
if @http_body
|
15
|
+
message += " - http body : #{@http_body}"
|
16
|
+
end
|
17
|
+
|
18
|
+
super(message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class AppResource < BaseResource
|
3
|
+
def all
|
4
|
+
get('/apps')
|
5
|
+
|
6
|
+
response_body.map(&OneSignal::App)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(id)
|
10
|
+
get("/apps/#{id}")
|
11
|
+
|
12
|
+
OneSignal::App.new(response_body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(params)
|
16
|
+
post('/apps', params)
|
17
|
+
|
18
|
+
OneSignal::App.new(response_body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(id, params)
|
22
|
+
put("/apps/#{id}", params)
|
23
|
+
|
24
|
+
OneSignal::App.new(response_body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OneSignal
|
4
|
+
class BaseResource
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get(path, params = {})
|
12
|
+
@response = request.get(path, params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def put(path, params)
|
16
|
+
@response = request.put(path, params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(path, params)
|
20
|
+
@response = request.post(path, params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(path)
|
24
|
+
@response = request.delete(path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def request
|
28
|
+
@request ||= OneSignal::Request.new(@client)
|
29
|
+
end
|
30
|
+
|
31
|
+
def response_body
|
32
|
+
JSON.parse(@response.body)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class NotificationResource < BaseResource
|
3
|
+
def all(params = {})
|
4
|
+
get('/notifications', params)
|
5
|
+
|
6
|
+
response_body['notifications'].map(&OneSignal::Notification)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(id)
|
10
|
+
get("/notifications/#{id}")
|
11
|
+
|
12
|
+
OneSignal::Notification.new(response_body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def track_open(id, params)
|
16
|
+
put("/notifications/#{id}", params)
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(params)
|
22
|
+
post('/notifications', params)
|
23
|
+
|
24
|
+
response_body
|
25
|
+
end
|
26
|
+
|
27
|
+
def cancel(id)
|
28
|
+
delete("/notifications/#{id}")
|
29
|
+
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module OneSignal
|
2
|
+
class PlayerResource < BaseResource
|
3
|
+
def all(params = {})
|
4
|
+
get('/players', params)
|
5
|
+
players = response_body['players']
|
6
|
+
|
7
|
+
players.map(&OneSignal::Player)
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(id)
|
11
|
+
get("/players/#{id}")
|
12
|
+
|
13
|
+
OneSignal::Player.new(response_body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(params)
|
17
|
+
post('/players', params)
|
18
|
+
|
19
|
+
response_body['id']
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(id, params)
|
23
|
+
put("/players/#{id}", params)
|
24
|
+
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_session(id, params)
|
29
|
+
post("/players/#{id}/on_session", params)
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_purchase(id, params)
|
35
|
+
post("/players/#{id}/on_purchase", params)
|
36
|
+
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_focus(id, params)
|
41
|
+
post("/players/#{id}/on_focus", params)
|
42
|
+
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def csv_export(id)
|
47
|
+
params = { app_id: id }
|
48
|
+
post('/players/csv_export', params)
|
49
|
+
|
50
|
+
response_body['csv_file_url']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/onesignal.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onesignal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'onesignal'
|
8
|
+
spec.version = OneSignal::VERSION
|
9
|
+
spec.authors = ['Bastian Bartmann']
|
10
|
+
spec.email = ['babartmann@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Simple wrapper for the OneSignal API.'
|
13
|
+
spec.description = 'Simple wrapper for the OneSignal API.'
|
14
|
+
spec.homepage = 'https://github.com/coding-chimp/onesignal.'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 1.24'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onesignal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bastian Bartmann
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-29 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.24'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.24'
|
69
|
+
description: Simple wrapper for the OneSignal API.
|
70
|
+
email:
|
71
|
+
- babartmann@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/onesignal.rb
|
87
|
+
- lib/onesignal/app_id_missing_error.rb
|
88
|
+
- lib/onesignal/client.rb
|
89
|
+
- lib/onesignal/models/app.rb
|
90
|
+
- lib/onesignal/models/base_model.rb
|
91
|
+
- lib/onesignal/models/notification.rb
|
92
|
+
- lib/onesignal/models/player.rb
|
93
|
+
- lib/onesignal/request.rb
|
94
|
+
- lib/onesignal/request_error.rb
|
95
|
+
- lib/onesignal/resources/app_resource.rb
|
96
|
+
- lib/onesignal/resources/base_resource.rb
|
97
|
+
- lib/onesignal/resources/notification_resource.rb
|
98
|
+
- lib/onesignal/resources/player_resource.rb
|
99
|
+
- lib/onesignal/version.rb
|
100
|
+
- onesignal.gemspec
|
101
|
+
homepage: https://github.com/coding-chimp/onesignal.
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Simple wrapper for the OneSignal API.
|
125
|
+
test_files: []
|