|
1 | 1 | # onesignal |
2 | 2 |
|
3 | | -OneSignal - the Ruby gem for the OneSignal |
| 3 | +OneSignal - the Ruby gem for OneSignal |
4 | 4 |
|
5 | 5 | A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com |
6 | 6 |
|
7 | | -This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: |
8 | | - |
9 | 7 | - API version: 5.3.0 |
10 | 8 | - Package version: 5.3.0 |
11 | | -- Build package: org.openapitools.codegen.languages.RubyClientCodegen |
12 | | -For more information, please visit [https://onesignal.com](https://onesignal.com) |
13 | 9 |
|
14 | 10 | ## Installation |
15 | 11 |
|
16 | | -### Build a gem |
17 | | - |
18 | | -To build the Ruby code into a gem: |
19 | | - |
20 | | -```shell |
21 | | -gem build onesignal.gemspec |
22 | | -``` |
23 | | - |
24 | | -Then either install the gem locally: |
| 12 | +Add to your `Gemfile`: |
25 | 13 |
|
26 | | -```shell |
27 | | -gem install ./onesignal-5.3.0.gem |
| 14 | +```ruby |
| 15 | +gem 'onesignal', '~> 5.3.0' |
28 | 16 | ``` |
29 | 17 |
|
30 | | -(for development, run `gem install --dev ./onesignal-5.3.0.gem` to install the development dependencies) |
| 18 | +Then run `bundle install`. |
31 | 19 |
|
32 | | -or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/). |
| 20 | +## Configuration |
33 | 21 |
|
34 | | -Finally add this to the Gemfile: |
| 22 | +Every SDK requires authentication via API keys. Two key types are available: |
35 | 23 |
|
36 | | - gem 'onesignal', '~> 5.3.0' |
| 24 | +- **REST API Key** — required for most endpoints (sending notifications, managing users, etc.). Found in your app's **Settings > Keys & IDs**. |
| 25 | +- **Organization API Key** — only required for organization-level endpoints like creating or listing apps. Found in **Organization Settings**. |
37 | 26 |
|
38 | | -### Install from Git |
| 27 | +> **Warning:** Store your API keys in environment variables or a secrets manager. Never commit them to source control. |
39 | 28 |
|
40 | | -If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile: |
41 | | - |
42 | | - gem 'onesignal', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git' |
43 | | - |
44 | | -### Include the Ruby code directly |
| 29 | +```ruby |
| 30 | +require 'onesignal' |
45 | 31 |
|
46 | | -Include the Ruby code directly using `-I` as follows: |
| 32 | +OneSignal.configure do |config| |
| 33 | + config.rest_api_key = 'YOUR_REST_API_KEY' |
| 34 | + config.organization_api_key = 'YOUR_ORGANIZATION_API_KEY' |
| 35 | +end |
47 | 36 |
|
48 | | -```shell |
49 | | -ruby -Ilib script.rb |
| 37 | +client = OneSignal::DefaultApi.new |
50 | 38 | ``` |
51 | 39 |
|
52 | | -## Getting Started |
53 | | - |
54 | | -Please follow the [installation](#installation) procedure and then run the following code: |
| 40 | +## Send a push notification |
55 | 41 |
|
56 | 42 | ```ruby |
57 | | -# Load the gem |
58 | | -require 'onesignal' |
| 43 | +notification = OneSignal::Notification.new({ |
| 44 | + app_id: 'YOUR_APP_ID', |
| 45 | + contents: { en: 'Hello from OneSignal!' }, |
| 46 | + headings: { en: 'Push Notification' }, |
| 47 | + included_segments: ['Subscribed Users'] |
| 48 | +}) |
| 49 | + |
| 50 | +response = client.create_notification(notification) |
| 51 | +puts "Notification ID: #{response.id}" |
| 52 | +``` |
59 | 53 |
|
60 | | -# Setup authorization |
61 | | -OneSignal.configure do |config| |
62 | | - # Configure Bearer authorization: organization_api_key |
63 | | - config.organization_api_key = 'ORGANIZATION_API_KEY' # Organization key is only required for creating new apps and other top-level endpoints |
64 | | - # Configure Bearer authorization: rest_api_key |
65 | | - config.rest_api_key = 'REST_API_KEY' # App REST API key required for most endpoints |
66 | | -end |
| 54 | +## Send an email |
67 | 55 |
|
68 | | -api_instance = OneSignal::DefaultApi.new |
69 | | -app_id = 'app_id_example' # String | |
70 | | -notification_id = 'notification_id_example' # String | |
| 56 | +```ruby |
| 57 | +notification = OneSignal::Notification.new({ |
| 58 | + app_id: 'YOUR_APP_ID', |
| 59 | + email_subject: 'Important Update', |
| 60 | + email_body: '<h1>Hello!</h1><p>This is an HTML email.</p>', |
| 61 | + included_segments: ['Subscribed Users'], |
| 62 | + channel_for_external_user_ids: 'email' |
| 63 | +}) |
| 64 | + |
| 65 | +response = client.create_notification(notification) |
| 66 | +``` |
71 | 67 |
|
72 | | -begin |
73 | | - #Stop a scheduled or currently outgoing notification |
74 | | - result = api_instance.cancel_notification(app_id, notification_id) |
75 | | - p result |
76 | | -rescue OneSignal::ApiError => e |
77 | | - puts "Exception when calling DefaultApi->cancel_notification: #{e}" |
78 | | -end |
| 68 | +## Send an SMS |
79 | 69 |
|
| 70 | +```ruby |
| 71 | +notification = OneSignal::Notification.new({ |
| 72 | + app_id: 'YOUR_APP_ID', |
| 73 | + contents: { en: 'Your SMS message content here' }, |
| 74 | + included_segments: ['Subscribed Users'], |
| 75 | + channel_for_external_user_ids: 'sms', |
| 76 | + sms_from: '+15551234567' |
| 77 | +}) |
| 78 | + |
| 79 | +response = client.create_notification(notification) |
80 | 80 | ``` |
81 | 81 |
|
82 | | -## Documentation for API Endpoints |
83 | | - |
84 | | -All URIs are relative to *https://api.onesignal.com* |
85 | | - |
86 | | -Class | Method | HTTP request | Description |
87 | | ------------- | ------------- | ------------- | ------------- |
88 | | -*OneSignal::DefaultApi* | [**cancel_notification**](docs/DefaultApi.md#cancel_notification) | **DELETE** /notifications/{notification_id} | Stop a scheduled or currently outgoing notification |
89 | | -*OneSignal::DefaultApi* | [**copy_template_to_app**](docs/DefaultApi.md#copy_template_to_app) | **POST** /templates/{template_id}/copy_to_app | Copy template to another app |
90 | | -*OneSignal::DefaultApi* | [**create_alias**](docs/DefaultApi.md#create_alias) | **PATCH** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity | |
91 | | -*OneSignal::DefaultApi* | [**create_alias_by_subscription**](docs/DefaultApi.md#create_alias_by_subscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id}/user/identity | |
92 | | -*OneSignal::DefaultApi* | [**create_api_key**](docs/DefaultApi.md#create_api_key) | **POST** /apps/{app_id}/auth/tokens | Create API key |
93 | | -*OneSignal::DefaultApi* | [**create_app**](docs/DefaultApi.md#create_app) | **POST** /apps | Create an app |
94 | | -*OneSignal::DefaultApi* | [**create_custom_events**](docs/DefaultApi.md#create_custom_events) | **POST** /apps/{app_id}/integrations/custom_events | Create custom events |
95 | | -*OneSignal::DefaultApi* | [**create_notification**](docs/DefaultApi.md#create_notification) | **POST** /notifications | Create notification |
96 | | -*OneSignal::DefaultApi* | [**create_segment**](docs/DefaultApi.md#create_segment) | **POST** /apps/{app_id}/segments | Create Segment |
97 | | -*OneSignal::DefaultApi* | [**create_subscription**](docs/DefaultApi.md#create_subscription) | **POST** /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions | |
98 | | -*OneSignal::DefaultApi* | [**create_template**](docs/DefaultApi.md#create_template) | **POST** /templates | Create template |
99 | | -*OneSignal::DefaultApi* | [**create_user**](docs/DefaultApi.md#create_user) | **POST** /apps/{app_id}/users | |
100 | | -*OneSignal::DefaultApi* | [**delete_alias**](docs/DefaultApi.md#delete_alias) | **DELETE** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity/{alias_label_to_delete} | |
101 | | -*OneSignal::DefaultApi* | [**delete_api_key**](docs/DefaultApi.md#delete_api_key) | **DELETE** /apps/{app_id}/auth/tokens/{token_id} | Delete API key |
102 | | -*OneSignal::DefaultApi* | [**delete_segment**](docs/DefaultApi.md#delete_segment) | **DELETE** /apps/{app_id}/segments/{segment_id} | Delete Segment |
103 | | -*OneSignal::DefaultApi* | [**delete_subscription**](docs/DefaultApi.md#delete_subscription) | **DELETE** /apps/{app_id}/subscriptions/{subscription_id} | |
104 | | -*OneSignal::DefaultApi* | [**delete_template**](docs/DefaultApi.md#delete_template) | **DELETE** /templates/{template_id} | Delete template |
105 | | -*OneSignal::DefaultApi* | [**delete_user**](docs/DefaultApi.md#delete_user) | **DELETE** /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
106 | | -*OneSignal::DefaultApi* | [**export_events**](docs/DefaultApi.md#export_events) | **POST** /notifications/{notification_id}/export_events?app_id={app_id} | Export CSV of Events |
107 | | -*OneSignal::DefaultApi* | [**export_subscriptions**](docs/DefaultApi.md#export_subscriptions) | **POST** /players/csv_export?app_id={app_id} | Export CSV of Subscriptions |
108 | | -*OneSignal::DefaultApi* | [**get_aliases**](docs/DefaultApi.md#get_aliases) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity | |
109 | | -*OneSignal::DefaultApi* | [**get_aliases_by_subscription**](docs/DefaultApi.md#get_aliases_by_subscription) | **GET** /apps/{app_id}/subscriptions/{subscription_id}/user/identity | |
110 | | -*OneSignal::DefaultApi* | [**get_app**](docs/DefaultApi.md#get_app) | **GET** /apps/{app_id} | View an app |
111 | | -*OneSignal::DefaultApi* | [**get_apps**](docs/DefaultApi.md#get_apps) | **GET** /apps | View apps |
112 | | -*OneSignal::DefaultApi* | [**get_notification**](docs/DefaultApi.md#get_notification) | **GET** /notifications/{notification_id} | View notification |
113 | | -*OneSignal::DefaultApi* | [**get_notification_history**](docs/DefaultApi.md#get_notification_history) | **POST** /notifications/{notification_id}/history | Notification History |
114 | | -*OneSignal::DefaultApi* | [**get_notifications**](docs/DefaultApi.md#get_notifications) | **GET** /notifications | View notifications |
115 | | -*OneSignal::DefaultApi* | [**get_outcomes**](docs/DefaultApi.md#get_outcomes) | **GET** /apps/{app_id}/outcomes | View Outcomes |
116 | | -*OneSignal::DefaultApi* | [**get_segments**](docs/DefaultApi.md#get_segments) | **GET** /apps/{app_id}/segments | Get Segments |
117 | | -*OneSignal::DefaultApi* | [**get_user**](docs/DefaultApi.md#get_user) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
118 | | -*OneSignal::DefaultApi* | [**rotate_api_key**](docs/DefaultApi.md#rotate_api_key) | **POST** /apps/{app_id}/auth/tokens/{token_id}/rotate | Rotate API key |
119 | | -*OneSignal::DefaultApi* | [**start_live_activity**](docs/DefaultApi.md#start_live_activity) | **POST** /apps/{app_id}/activities/activity/{activity_type} | Start Live Activity |
120 | | -*OneSignal::DefaultApi* | [**transfer_subscription**](docs/DefaultApi.md#transfer_subscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id}/owner | |
121 | | -*OneSignal::DefaultApi* | [**unsubscribe_email_with_token**](docs/DefaultApi.md#unsubscribe_email_with_token) | **POST** /apps/{app_id}/notifications/{notification_id}/unsubscribe | Unsubscribe with token |
122 | | -*OneSignal::DefaultApi* | [**update_api_key**](docs/DefaultApi.md#update_api_key) | **PATCH** /apps/{app_id}/auth/tokens/{token_id} | Update API key |
123 | | -*OneSignal::DefaultApi* | [**update_app**](docs/DefaultApi.md#update_app) | **PUT** /apps/{app_id} | Update an app |
124 | | -*OneSignal::DefaultApi* | [**update_live_activity**](docs/DefaultApi.md#update_live_activity) | **POST** /apps/{app_id}/live_activities/{activity_id}/notifications | Update a Live Activity via Push |
125 | | -*OneSignal::DefaultApi* | [**update_subscription**](docs/DefaultApi.md#update_subscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id} | |
126 | | -*OneSignal::DefaultApi* | [**update_subscription_by_token**](docs/DefaultApi.md#update_subscription_by_token) | **PATCH** /apps/{app_id}/subscriptions_by_token/{token_type}/{token} | Update subscription by token |
127 | | -*OneSignal::DefaultApi* | [**update_template**](docs/DefaultApi.md#update_template) | **PATCH** /templates/{template_id} | Update template |
128 | | -*OneSignal::DefaultApi* | [**update_user**](docs/DefaultApi.md#update_user) | **PATCH** /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
129 | | -*OneSignal::DefaultApi* | [**view_api_keys**](docs/DefaultApi.md#view_api_keys) | **GET** /apps/{app_id}/auth/tokens | View API keys |
130 | | -*OneSignal::DefaultApi* | [**view_template**](docs/DefaultApi.md#view_template) | **GET** /templates/{template_id} | View template |
131 | | -*OneSignal::DefaultApi* | [**view_templates**](docs/DefaultApi.md#view_templates) | **GET** /templates | View templates |
132 | | - |
133 | | - |
134 | | -## Documentation for Models |
135 | | - |
136 | | - - [OneSignal::ApiKeyToken](docs/ApiKeyToken.md) |
137 | | - - [OneSignal::ApiKeyTokensListResponse](docs/ApiKeyTokensListResponse.md) |
138 | | - - [OneSignal::App](docs/App.md) |
139 | | - - [OneSignal::BasicNotification](docs/BasicNotification.md) |
140 | | - - [OneSignal::BasicNotificationAllOf](docs/BasicNotificationAllOf.md) |
141 | | - - [OneSignal::BasicNotificationAllOfAndroidBackgroundLayout](docs/BasicNotificationAllOfAndroidBackgroundLayout.md) |
142 | | - - [OneSignal::Button](docs/Button.md) |
143 | | - - [OneSignal::CopyTemplateRequest](docs/CopyTemplateRequest.md) |
144 | | - - [OneSignal::CreateApiKeyRequest](docs/CreateApiKeyRequest.md) |
145 | | - - [OneSignal::CreateApiKeyResponse](docs/CreateApiKeyResponse.md) |
146 | | - - [OneSignal::CreateNotificationSuccessResponse](docs/CreateNotificationSuccessResponse.md) |
147 | | - - [OneSignal::CreateSegmentConflictResponse](docs/CreateSegmentConflictResponse.md) |
148 | | - - [OneSignal::CreateSegmentSuccessResponse](docs/CreateSegmentSuccessResponse.md) |
149 | | - - [OneSignal::CreateTemplateRequest](docs/CreateTemplateRequest.md) |
150 | | - - [OneSignal::CreateUserConflictResponse](docs/CreateUserConflictResponse.md) |
151 | | - - [OneSignal::CreateUserConflictResponseErrorsInner](docs/CreateUserConflictResponseErrorsInner.md) |
152 | | - - [OneSignal::CreateUserConflictResponseErrorsItemsMeta](docs/CreateUserConflictResponseErrorsItemsMeta.md) |
153 | | - - [OneSignal::CustomEvent](docs/CustomEvent.md) |
154 | | - - [OneSignal::CustomEventsRequest](docs/CustomEventsRequest.md) |
155 | | - - [OneSignal::DeliveryData](docs/DeliveryData.md) |
156 | | - - [OneSignal::ExportEventsSuccessResponse](docs/ExportEventsSuccessResponse.md) |
157 | | - - [OneSignal::ExportSubscriptionsRequestBody](docs/ExportSubscriptionsRequestBody.md) |
158 | | - - [OneSignal::ExportSubscriptionsSuccessResponse](docs/ExportSubscriptionsSuccessResponse.md) |
159 | | - - [OneSignal::Filter](docs/Filter.md) |
160 | | - - [OneSignal::FilterExpression](docs/FilterExpression.md) |
161 | | - - [OneSignal::GenericError](docs/GenericError.md) |
162 | | - - [OneSignal::GenericSuccessBoolResponse](docs/GenericSuccessBoolResponse.md) |
163 | | - - [OneSignal::GetNotificationHistoryRequestBody](docs/GetNotificationHistoryRequestBody.md) |
164 | | - - [OneSignal::GetSegmentsSuccessResponse](docs/GetSegmentsSuccessResponse.md) |
165 | | - - [OneSignal::LanguageStringMap](docs/LanguageStringMap.md) |
166 | | - - [OneSignal::Notification](docs/Notification.md) |
167 | | - - [OneSignal::NotificationAllOf](docs/NotificationAllOf.md) |
168 | | - - [OneSignal::NotificationHistorySuccessResponse](docs/NotificationHistorySuccessResponse.md) |
169 | | - - [OneSignal::NotificationSlice](docs/NotificationSlice.md) |
170 | | - - [OneSignal::NotificationTarget](docs/NotificationTarget.md) |
171 | | - - [OneSignal::NotificationWithMeta](docs/NotificationWithMeta.md) |
172 | | - - [OneSignal::NotificationWithMetaAllOf](docs/NotificationWithMetaAllOf.md) |
173 | | - - [OneSignal::Operator](docs/Operator.md) |
174 | | - - [OneSignal::OutcomeData](docs/OutcomeData.md) |
175 | | - - [OneSignal::OutcomesData](docs/OutcomesData.md) |
176 | | - - [OneSignal::PlatformDeliveryData](docs/PlatformDeliveryData.md) |
177 | | - - [OneSignal::PlatformDeliveryDataEmailAllOf](docs/PlatformDeliveryDataEmailAllOf.md) |
178 | | - - [OneSignal::PlatformDeliveryDataSmsAllOf](docs/PlatformDeliveryDataSmsAllOf.md) |
179 | | - - [OneSignal::PropertiesBody](docs/PropertiesBody.md) |
180 | | - - [OneSignal::PropertiesDeltas](docs/PropertiesDeltas.md) |
181 | | - - [OneSignal::PropertiesObject](docs/PropertiesObject.md) |
182 | | - - [OneSignal::Purchase](docs/Purchase.md) |
183 | | - - [OneSignal::RateLimitError](docs/RateLimitError.md) |
184 | | - - [OneSignal::Segment](docs/Segment.md) |
185 | | - - [OneSignal::SegmentData](docs/SegmentData.md) |
186 | | - - [OneSignal::SegmentNotificationTarget](docs/SegmentNotificationTarget.md) |
187 | | - - [OneSignal::StartLiveActivityRequest](docs/StartLiveActivityRequest.md) |
188 | | - - [OneSignal::StartLiveActivitySuccessResponse](docs/StartLiveActivitySuccessResponse.md) |
189 | | - - [OneSignal::Subscription](docs/Subscription.md) |
190 | | - - [OneSignal::SubscriptionBody](docs/SubscriptionBody.md) |
191 | | - - [OneSignal::SubscriptionNotificationTarget](docs/SubscriptionNotificationTarget.md) |
192 | | - - [OneSignal::TemplateResource](docs/TemplateResource.md) |
193 | | - - [OneSignal::TemplatesListResponse](docs/TemplatesListResponse.md) |
194 | | - - [OneSignal::TransferSubscriptionRequestBody](docs/TransferSubscriptionRequestBody.md) |
195 | | - - [OneSignal::UpdateApiKeyRequest](docs/UpdateApiKeyRequest.md) |
196 | | - - [OneSignal::UpdateLiveActivityRequest](docs/UpdateLiveActivityRequest.md) |
197 | | - - [OneSignal::UpdateLiveActivitySuccessResponse](docs/UpdateLiveActivitySuccessResponse.md) |
198 | | - - [OneSignal::UpdateTemplateRequest](docs/UpdateTemplateRequest.md) |
199 | | - - [OneSignal::UpdateUserRequest](docs/UpdateUserRequest.md) |
200 | | - - [OneSignal::User](docs/User.md) |
201 | | - - [OneSignal::UserIdentityBody](docs/UserIdentityBody.md) |
202 | | - - [OneSignal::WebButton](docs/WebButton.md) |
203 | | - |
204 | | - |
205 | | -## Documentation for Authorization |
206 | | - |
207 | | - |
208 | | -### organization_api_key |
209 | | - |
210 | | -- **Type**: Bearer authentication |
211 | | - |
212 | | -### rest_api_key |
213 | | - |
214 | | -- **Type**: Bearer authentication |
| 82 | +## Full API reference |
| 83 | + |
| 84 | +The complete list of API endpoints and their parameters is available in the [DefaultApi documentation](https://github.com/OneSignal/onesignal-ruby-api/blob/master/docs/DefaultApi.md). |
215 | 85 |
|
| 86 | +For the underlying REST API, see the [OneSignal API reference](https://documentation.onesignal.com/reference). |
0 commit comments