Skip to content

Commit 21f6439

Browse files
author
coding-chimp
committed
Adds documentation
1 parent 2f22e82 commit 21f6439

1 file changed

Lines changed: 101 additions & 9 deletions

File tree

README.md

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
[![Build Status][trb]][trl] [![Code Climate][ccb]][ccl]
44

5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/onesignal`. To experiment with that code, run `bin/console` for an interactive prompt.
6-
7-
TODO: Delete this and the text above, and describe your gem
5+
OneSignal is a simple ruby wrapper for the [OneSignal API][osa].
86

97
## Installation
108

@@ -24,24 +22,118 @@ Or install it yourself as:
2422

2523
## Usage
2624

27-
TODO: Write usage instructions here
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:
2844

29-
## Development
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+
```
30111

31-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
112+
Actions supported:
32113

33-
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).
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)`
34120

35121
## Contributing
36122

37-
Bug reports and pull requests are welcome on GitHub at https://github.com/coding-chimp/onesignal. 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.
123+
Bug reports and pull requests are welcome on [GitHub][gh].
38124

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.
39127

40128
## License
41129

42-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
130+
The gem is available as open source under the terms of the [MIT License][mit].
43131

44132
[trb]: https://travis-ci.org/coding-chimp/onesignal.svg?branch=master
45133
[trl]: https://travis-ci.org/coding-chimp/onesignal
46134
[ccb]: https://codeclimate.com/github/coding-chimp/onesignal/badges/gpa.svg
47135
[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

0 commit comments

Comments
 (0)