magicbell 1.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +147 -140
- data/lib/magicbell.rb +4 -14
- data/lib/magicbell/action_mailer_extension.rb +0 -10
- data/lib/magicbell/api_operations.rb +25 -13
- data/lib/magicbell/api_resource.rb +4 -4
- data/lib/magicbell/client.rb +20 -2
- data/lib/magicbell/config.rb +0 -5
- data/lib/magicbell/version.rb +1 -1
- metadata +27 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2806ab42cdd91d4eaada59a02ef686432dec09656fd369d244e9a9111a5f0f
|
4
|
+
data.tar.gz: ad0d1da2faf2bbdc2c51da677bf4c91c90a4fbb759a70e74da19d525e47de7a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6849a6a65cb71d23f3f96b7cfccf47bdc2d808c76004bbfafb4321f9b670b852cb7b2770f0fa3fc0a553ca3c6e5d2ba85a52820c63e00350c61f1a69cffee730
|
7
|
+
data.tar.gz: e0a8e457403e9b67210d0ada15d8aa3adbbbfea7a7c50810e40ad04dcf0b6d3ca74c193f191a34e127a9b5080aab834e9fa6ed66cca7c2ab95e71484c007d4ee
|
data/README.md
CHANGED
@@ -1,243 +1,250 @@
|
|
1
|
-
#
|
1
|
+
# MagicBell Ruby Library
|
2
2
|
|
3
|
-
[MagicBell](https://magicbell.
|
3
|
+
This library provides convenient access to the [MagicBell REST API](https://magicbell.com/docs/rest-api/overview) from applications written in Ruby. It includes helpers for creating notifications, fetching them, and calculating the HMAC for a user.
|
4
4
|
|
5
|
-
|
5
|
+
[MagicBell](https://magicbell.com) is the notification inbox for your web and mobile applications. You may find it helpful to familiarize yourself with the [core concepts of MagicBell](https://magicbell.com/docs/core-concepts).
|
6
6
|
|
7
|
-
|
7
|
+
<img width="415" alt="MagicBell Notification Inbox" src="https://files.readme.io/c09b21a-image1.png">
|
8
8
|
|
9
|
-
|
10
|
-
3. Can BCC your ActionMailer email notifications to MagicBell if you rather not use MagicBell's API in your Rails application.
|
11
|
-
|
12
|
-
MagicBell will create an in-app notification from any email notification that's blind copied to it.
|
13
|
-
3. Helps you calculate the HMAC for a user's email when you turn on HMAC Authentication for your MagicBell project
|
9
|
+
## Installation
|
14
10
|
|
15
|
-
|
11
|
+
First, [sign up for a MagicBell account](https://magicbell.com) and grab your MagicBell project's API key and secret from the "Settings" section of your MagicBell dashboard.
|
16
12
|
|
17
|
-
|
13
|
+
If you just want to use the package, run:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install magicbell
|
17
|
+
```
|
18
18
|
|
19
|
-
|
19
|
+
### Bundler
|
20
20
|
|
21
|
-
|
21
|
+
If you are installing via bundler, add the gem to your app's Gemfile:
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
|
24
|
+
# Gemfile
|
25
|
+
source 'https://rubygems.org'
|
26
|
+
|
27
|
+
gem 'magicbell'
|
25
28
|
```
|
26
29
|
|
27
|
-
and install
|
30
|
+
and run `bundle install` a usual.
|
28
31
|
|
29
|
-
|
30
|
-
bundle install
|
31
|
-
```
|
32
|
+
## Configuration
|
32
33
|
|
33
|
-
The
|
34
|
+
The library needs to be configured with your MagicBell project's API key and secret.
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
### Global configuration
|
37
|
+
|
38
|
+
By default, this library will automatically pick your MagicBell project's API key and secret from the `MAGICBELL_API_KEY` and `MAGICBELL_API_SECRET` environment variables, respectively.
|
39
|
+
|
40
|
+
Alternatively, you can configure your MagicBell manually. For example, for a rails project, create an initializer file for MagicBell and set your project's keys:
|
38
41
|
|
39
42
|
```ruby
|
40
43
|
# config/initializers/magicbell.rb
|
41
44
|
|
42
45
|
MagicBell.configure do |config|
|
43
|
-
config.api_key =
|
44
|
-
config.api_secret =
|
46
|
+
config.api_key = 'MAGICBELL_API_KEY'
|
47
|
+
config.api_secret = 'MAGICBELL_API_SECRET'
|
45
48
|
end
|
46
49
|
```
|
47
50
|
|
48
|
-
|
51
|
+
### Per-request configuration
|
52
|
+
|
53
|
+
For apps that need to use multiple keys during the lifetime of a process, provide the specific keys when you create instances of `MagicBell::Client`:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require 'magicbell'
|
57
|
+
|
58
|
+
magicbell = MagicBell::Client.new(
|
59
|
+
api_key: 'MAGICBELL_PROJECT_API_KEY',
|
60
|
+
api_secret: 'MAGICBELL_PROJECT_API_SECRET'
|
61
|
+
)
|
62
|
+
```
|
63
|
+
|
64
|
+
Please keep in mind that any instance of `MagicBell::Client` will default to the global configuration unless an API key and secret are provided.
|
49
65
|
|
50
|
-
|
66
|
+
## Usage
|
51
67
|
|
52
68
|
### Create a notification
|
53
69
|
|
54
|
-
|
70
|
+
You can send a notification to one or many users by identifying them by their email address:
|
55
71
|
|
56
72
|
```ruby
|
73
|
+
require 'magicbell'
|
74
|
+
|
57
75
|
magicbell = MagicBell::Client.new
|
58
76
|
magicbell.create_notification(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
]
|
77
|
+
title: 'Rob assigned a task to you',
|
78
|
+
recipients: [{
|
79
|
+
email: 'joe@example.com'
|
80
|
+
}, {
|
81
|
+
email: 'mary@example.com'
|
82
|
+
}]
|
65
83
|
)
|
66
84
|
```
|
67
85
|
|
68
|
-
|
86
|
+
Or you can identify users by an `external_id` (their ID in your database, for example):
|
69
87
|
|
70
88
|
```ruby
|
89
|
+
require 'magicbell'
|
90
|
+
|
71
91
|
magicbell = MagicBell::Client.new
|
72
92
|
magicbell.create_notification(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
93
|
+
title: 'Rob assigned a task to you',
|
94
|
+
recipients: [{
|
95
|
+
external_id: 'DATABASE_ID'
|
96
|
+
}]
|
97
|
+
)
|
98
|
+
```
|
99
|
+
|
100
|
+
This method has the benefit of allowing users to access their notifications when their email address changes. Make sure you identify users by their `externalID` when you [initialize the notification inbox](https://magicbell.com/docs/react/identifying-users), too.
|
101
|
+
|
102
|
+
You can also provide other data accepted by [our API](https://magicbell.com/docs/rest-api/reference):
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
require 'magicbell'
|
106
|
+
|
107
|
+
magicbell = MagicBell::Client.new
|
108
|
+
magicbell.create_notification(
|
109
|
+
title: 'Rob assigned to a task to you',
|
110
|
+
content: 'Hey Joe, can give this customer a demo of our app?',
|
111
|
+
action_url: 'https://example.com/task_path',
|
112
|
+
custom_attributes: {
|
113
|
+
recipient: {
|
114
|
+
first_name: 'Joe',
|
115
|
+
last_name: 'Smith'
|
116
|
+
}
|
117
|
+
},
|
118
|
+
overrides: {
|
119
|
+
channels: {
|
120
|
+
web_push: {
|
121
|
+
title: 'New task assigned'
|
122
|
+
}
|
123
|
+
}
|
124
|
+
},
|
125
|
+
recipients: [{
|
126
|
+
email: 'joe@example.com'
|
127
|
+
}],
|
81
128
|
)
|
82
129
|
```
|
83
130
|
|
84
131
|
### Fetch a user's notifications
|
85
132
|
|
86
|
-
|
133
|
+
To fetch a user's notifications you can do this:
|
87
134
|
|
88
135
|
```ruby
|
136
|
+
require 'magicbell'
|
137
|
+
|
89
138
|
magicbell = MagicBell::Client.new
|
90
|
-
|
91
|
-
|
92
|
-
|
139
|
+
|
140
|
+
user = magicbell.user_with_email('joe@example.com')
|
141
|
+
user.notifications.each { |notification| puts notification.attribute('title') }
|
93
142
|
```
|
94
143
|
|
95
|
-
Please note that the example above fetches the user's 15 most recent
|
144
|
+
Please note that the example above fetches the user's 15 most recent notifications (the default number per page). If you'd like to fetch subsequent pages, use the `each_page` method instead:
|
96
145
|
|
97
146
|
```ruby
|
147
|
+
require 'magicbell'
|
148
|
+
|
98
149
|
magicbell = MagicBell::Client.new
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
page.each do |
|
103
|
-
puts
|
150
|
+
|
151
|
+
user = magicbell.user_with_email('joe@example.com')
|
152
|
+
user.notifications.each_page do |page|
|
153
|
+
page.each do |notification|
|
154
|
+
puts notification.attribute('title')
|
104
155
|
end
|
105
156
|
end
|
106
157
|
```
|
107
158
|
|
108
|
-
### Mark a user notification as read/unread
|
159
|
+
### Mark a user's notification as read/unread
|
109
160
|
|
110
161
|
```ruby
|
162
|
+
require 'magicbell'
|
163
|
+
|
111
164
|
magicbell = MagicBell::Client.new
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
165
|
+
|
166
|
+
user = magicbell.user_with_email('joe@example.com')
|
167
|
+
|
168
|
+
notification = user.notifications.first
|
169
|
+
notification.mark_as_read
|
170
|
+
notification.mark_as_unread
|
116
171
|
```
|
117
172
|
|
118
|
-
### Mark all notifications of a user as read
|
173
|
+
### Mark all notifications of a user as read
|
119
174
|
|
120
175
|
```ruby
|
176
|
+
require 'magicbell'
|
177
|
+
|
121
178
|
magicbell = MagicBell::Client.new
|
122
|
-
|
179
|
+
|
180
|
+
user = magicbell.user_with_email('joe@example.com')
|
123
181
|
user.mark_all_notifications_as_read
|
182
|
+
```
|
183
|
+
|
184
|
+
### Mark all notifications of a user as seen
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
require 'magicbell'
|
188
|
+
|
189
|
+
magicbell = MagicBell::Client.new
|
190
|
+
|
191
|
+
user = magicbell.user_with_email('joe@example.com')
|
124
192
|
user.mark_all_notifications_as_seen
|
125
193
|
```
|
126
194
|
|
127
195
|
### Error handling
|
128
196
|
|
129
|
-
|
197
|
+
This gem raises a `MagicBell::Client::HTTPError` if the MagicBell API returns a non-2xx response.
|
130
198
|
|
131
199
|
```ruby
|
200
|
+
require 'magicbell'
|
201
|
+
|
132
202
|
begin
|
133
203
|
magicbell = MagicBell::Client.new
|
134
204
|
magicbell.create_notification(
|
135
|
-
|
205
|
+
title: 'Rob assigned to a task to you'
|
136
206
|
)
|
137
207
|
rescue MagicBell::Client::HTTPError => e
|
138
|
-
# Report the error to your error tracker
|
208
|
+
# Report the error to your error tracker, for example
|
139
209
|
error_context = {
|
140
210
|
response_status: e.response_status,
|
141
211
|
response_headers: e.response_headers,
|
142
212
|
response_body: e.response_body
|
143
213
|
}
|
144
|
-
ErrorReporter.report(e, context: error_context)
|
145
|
-
end
|
146
|
-
```
|
147
|
-
|
148
|
-
## Rails integration
|
149
|
-
|
150
|
-
If you've existing ActionMailer email notifications in your Rails app and prefer to not spend time migrating to MagicBell's API, you can blind copy your ActionMailer email notifications to MagicBell. MagicBell will create in-app notifications from email notifications blind copied to it.
|
151
|
-
|
152
|
-
Call the `ring_the_magicbell` method in your action mailers like in the example below
|
153
|
-
|
154
|
-
```ruby
|
155
|
-
class NotificationMailer < ActionMailer::Base
|
156
|
-
# The ring_the_magicbell method will bcc your email notifications to your MagicBell project's BCC email address
|
157
|
-
#
|
158
|
-
# Upon receiving a blind copied email notification, magicbell.io will automatically create an in-app notification for the user
|
159
|
-
ring_the_magicbell
|
160
|
-
|
161
|
-
# This is an email notification in your app
|
162
|
-
def new_comment
|
163
|
-
# ...
|
164
|
-
end
|
165
|
-
|
166
|
-
# This is another email notification in your app
|
167
|
-
def mentioned
|
168
|
-
# ...
|
169
|
-
end
|
170
|
-
end
|
171
|
-
```
|
172
|
-
|
173
|
-
The gem will automatically pick your MagicBell project's BCC email from the `MAGICBELL_BCC_EMAIL` environment variable. Alternatively, provide your MagicBell project's BCC email address in an initializer
|
174
|
-
|
175
|
-
```
|
176
|
-
vim config/initializers/magicbell.rb
|
177
|
-
```
|
178
|
-
|
179
|
-
```ruby
|
180
|
-
# config/initializers/magicbell.rb
|
181
214
|
|
182
|
-
|
183
|
-
config.api_key = "your_magicbell_api_key"
|
184
|
-
config.api_secret = "your_magicbell_api_secret"
|
185
|
-
config.bcc_email = "your_magicbell_bcc_email@ring.magicbell.io"
|
215
|
+
ErrorReporter.report(e, context: error_context)
|
186
216
|
end
|
187
217
|
```
|
188
218
|
|
189
|
-
|
190
|
-
|
191
|
-
### Customize Action URL
|
219
|
+
### Calculate the HMAC secret for a user
|
192
220
|
|
193
|
-
|
194
|
-
|
195
|
-
If you wish to redirect users to a different URL instead, provide an `action_url` in your mailers
|
221
|
+
You can use the `MagicBell.hmac` method. Note that in this case, the API secret, which is used to generate the HMAC, will be fetched from the global configuration.
|
196
222
|
|
197
223
|
```ruby
|
198
|
-
|
199
|
-
ring_the_magicbell
|
224
|
+
require 'magicbell'
|
200
225
|
|
201
|
-
|
202
|
-
# ...
|
203
|
-
magicbell_notification_action_url("https://myapp.com/comments/#{comment.id}")
|
204
|
-
# ...
|
205
|
-
end
|
206
|
-
end
|
226
|
+
hmac = MagicBell.hmac('joe@example.com')
|
207
227
|
```
|
208
228
|
|
209
|
-
|
210
|
-
|
211
|
-
The Notification inbox will use the subject of the email notification as a notification's title. If this behaviour isn't sutiable for your app, provide a title in your mailers
|
229
|
+
You can also use the API secret of a specific client instance to calculate the HMAC:
|
212
230
|
|
213
231
|
```ruby
|
214
|
-
|
215
|
-
ring_the_magicbell
|
216
|
-
|
217
|
-
def new_comment(comment)
|
218
|
-
# ...
|
219
|
-
magicbell_notification_title("Richard posted a new comment")
|
220
|
-
# ...
|
221
|
-
end
|
222
|
-
end
|
223
|
-
```
|
224
|
-
|
225
|
-
## HMAC Authentication
|
232
|
+
require 'magicbell'
|
226
233
|
|
227
|
-
|
234
|
+
magicbell = MagicBell::Client.new(
|
235
|
+
api_key: 'MAGICBELL_API_KEY',
|
236
|
+
api_secret: 'MAGICBELL_API_SECRET'
|
237
|
+
)
|
228
238
|
|
239
|
+
hmac = magicbell.hmac('joe@example.com')
|
229
240
|
```
|
230
|
-
user_email = "joe@example.com"
|
231
|
-
hmac = MagicBell.hmac(user_email)
|
232
|
-
```
|
233
|
-
|
234
|
-
See https://developer.magicbell.io/docs/turn-on-hmac-authentication for more information on turning on HMAC Authentication for your MagicBell Project
|
235
241
|
|
242
|
+
Please refer to our docs to know [how to turn on HMAC authentication](https://magicbell.com/docs/turn-on-hmac-authentication) for your MagicBell project.
|
236
243
|
|
237
244
|
## API docs
|
238
245
|
|
239
|
-
Please visit our website
|
246
|
+
Please visit [our website](https://magicbell.com) and [our docs](https://magicbell.com/docs) for more information.
|
240
247
|
|
241
248
|
## Contact Us
|
242
249
|
|
243
|
-
Have a query or hit upon a problem?
|
250
|
+
Have a query or hit upon a problem? Feel free to contact us at [hello@magicbell.io](mailto:hello@magicbell.io).
|
data/lib/magicbell.rb
CHANGED
@@ -32,7 +32,6 @@ module MagicBell
|
|
32
32
|
|
33
33
|
def_delegators :config, :api_key,
|
34
34
|
:api_secret,
|
35
|
-
:bcc_email,
|
36
35
|
:api_host
|
37
36
|
|
38
37
|
def configure
|
@@ -47,25 +46,16 @@ module MagicBell
|
|
47
46
|
@config = Config.new
|
48
47
|
end
|
49
48
|
|
50
|
-
def authentication_headers
|
49
|
+
def authentication_headers(client_api_key: nil, client_api_secret: nil)
|
51
50
|
{
|
52
|
-
"X-MAGICBELL-API-KEY" => api_key,
|
53
|
-
"X-MAGICBELL-API-SECRET" => api_secret
|
51
|
+
"X-MAGICBELL-API-KEY" => client_api_key || api_key,
|
52
|
+
"X-MAGICBELL-API-SECRET" => client_api_secret || api_secret
|
54
53
|
}
|
55
54
|
end
|
56
55
|
|
57
56
|
# Calculate HMAC for user's email
|
58
57
|
def hmac(message)
|
59
|
-
|
60
|
-
secret = api_secret
|
61
|
-
|
62
|
-
Base64.encode64(OpenSSL::HMAC.digest(digest, secret, message)).strip
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def sha256_digest
|
68
|
-
OpenSSL::Digest::Digest.new('sha256')
|
58
|
+
MagicBell::Client.new(api_key: api_key, api_secret: api_secret).hmac(message)
|
69
59
|
end
|
70
60
|
end
|
71
61
|
end
|
@@ -2,16 +2,6 @@ require "json"
|
|
2
2
|
|
3
3
|
module MagicBell
|
4
4
|
module ActionMailerExtension
|
5
|
-
def self.included(mailer_class)
|
6
|
-
mailer_class.send :extend, ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
def ring_the_magicbell
|
11
|
-
default bcc: MagicBell.bcc_email
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
def magicbell_notification_action_url(action_url)
|
16
6
|
headers["X-MagicBell-Notification-ActionUrl"] = action_url
|
17
7
|
end
|
@@ -1,44 +1,56 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'colorize'
|
1
3
|
module MagicBell
|
2
4
|
module ApiOperations
|
3
5
|
def get(url, options = {})
|
4
|
-
|
5
|
-
|
6
|
-
options.merge(headers: authentication_headers)
|
7
|
-
)
|
6
|
+
defaults = { headers: default_headers }
|
7
|
+
response = HTTParty.get(url, options.merge(defaults))
|
8
8
|
raise_http_error_unless_2xx_response(response)
|
9
9
|
|
10
10
|
response
|
11
11
|
end
|
12
12
|
|
13
13
|
def post(url, options = {})
|
14
|
-
|
15
|
-
|
16
|
-
options.merge(headers: authentication_headers)
|
17
|
-
)
|
14
|
+
defaults = { headers: default_headers }
|
15
|
+
response = HTTParty.post(url, options.merge(defaults))
|
18
16
|
raise_http_error_unless_2xx_response(response)
|
19
17
|
|
20
18
|
response
|
21
19
|
end
|
22
20
|
|
23
21
|
def put(url, options = {})
|
24
|
-
|
25
|
-
|
26
|
-
options.merge(headers: authentication_headers)
|
27
|
-
)
|
22
|
+
defaults = { headers: default_headers }
|
23
|
+
response = HTTParty.put(url, options.merge(defaults))
|
28
24
|
raise_http_error_unless_2xx_response(response)
|
29
25
|
|
30
26
|
response
|
31
27
|
end
|
32
28
|
|
29
|
+
protected
|
30
|
+
|
31
|
+
def default_headers
|
32
|
+
authentication_headers.merge({ "Content-Type" => "application/json", "Accept"=> "application/json" })
|
33
|
+
end
|
34
|
+
|
33
35
|
private
|
34
36
|
|
35
37
|
def raise_http_error_unless_2xx_response(response)
|
36
38
|
return if response.success?
|
39
|
+
|
37
40
|
e = MagicBell::Client::HTTPError.new
|
38
41
|
e.response_status = response.code
|
39
42
|
e.response_headers = response.headers.to_h
|
40
43
|
e.response_body = response.body
|
44
|
+
e.errors = []
|
45
|
+
unless e.response_body.nil? || e.response_body.empty?
|
46
|
+
body = JSON.parse(response.body)
|
47
|
+
e.errors = body["errors"]
|
48
|
+
e.errors.each do |error, index|
|
49
|
+
puts "#{error["suggestion"].red}"
|
50
|
+
puts "#{error["help_link"].blue.on_white}"
|
51
|
+
end
|
52
|
+
end
|
41
53
|
raise e
|
42
54
|
end
|
43
55
|
end
|
44
|
-
end
|
56
|
+
end
|
@@ -79,7 +79,7 @@ module MagicBell
|
|
79
79
|
response = @client.post(
|
80
80
|
create_url,
|
81
81
|
body: { name => attributes }.to_json,
|
82
|
-
headers:
|
82
|
+
headers: extra_headers
|
83
83
|
)
|
84
84
|
parse_response(response)
|
85
85
|
|
@@ -90,7 +90,7 @@ module MagicBell
|
|
90
90
|
response = @client.put(
|
91
91
|
url,
|
92
92
|
body: new_attributes.to_json,
|
93
|
-
headers:
|
93
|
+
headers: extra_headers
|
94
94
|
)
|
95
95
|
parse_response(response)
|
96
96
|
|
@@ -99,8 +99,8 @@ module MagicBell
|
|
99
99
|
|
100
100
|
protected
|
101
101
|
|
102
|
-
def
|
103
|
-
|
102
|
+
def extra_headers
|
103
|
+
{}
|
104
104
|
end
|
105
105
|
|
106
106
|
private
|
data/lib/magicbell/client.rb
CHANGED
@@ -3,11 +3,17 @@ module MagicBell
|
|
3
3
|
class HTTPError < StandardError
|
4
4
|
attr_accessor :response_status,
|
5
5
|
:response_headers,
|
6
|
-
:response_body
|
6
|
+
:response_body,
|
7
|
+
:errors
|
7
8
|
end
|
8
9
|
|
9
10
|
include ApiOperations
|
10
11
|
|
12
|
+
def initialize(api_key: nil, api_secret: nil)
|
13
|
+
@api_key = api_key
|
14
|
+
@api_secret = api_secret
|
15
|
+
end
|
16
|
+
|
11
17
|
def create_notification(notification_attributes)
|
12
18
|
MagicBell::Notification.create(self, notification_attributes)
|
13
19
|
end
|
@@ -22,7 +28,19 @@ module MagicBell
|
|
22
28
|
end
|
23
29
|
|
24
30
|
def authentication_headers
|
25
|
-
MagicBell.authentication_headers
|
31
|
+
MagicBell.authentication_headers(client_api_key: @api_key, client_api_secret: @api_secret)
|
32
|
+
end
|
33
|
+
|
34
|
+
def hmac(message)
|
35
|
+
secret = @api_secret || MagicBell.api_secret
|
36
|
+
|
37
|
+
Base64.encode64(OpenSSL::HMAC::digest(sha256_digest, secret, message)).strip
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def sha256_digest
|
43
|
+
OpenSSL::Digest::Digest.new('sha256')
|
26
44
|
end
|
27
45
|
end
|
28
46
|
end
|
data/lib/magicbell/config.rb
CHANGED
@@ -2,7 +2,6 @@ module MagicBell
|
|
2
2
|
class Config
|
3
3
|
attr_writer :api_key
|
4
4
|
attr_writer :api_secret
|
5
|
-
attr_writer :bcc_email
|
6
5
|
attr_writer :api_host
|
7
6
|
|
8
7
|
def initialize
|
@@ -17,10 +16,6 @@ module MagicBell
|
|
17
16
|
@api_secret || ENV["MAGICBELL_API_SECRET"]
|
18
17
|
end
|
19
18
|
|
20
|
-
def bcc_email
|
21
|
-
@bcc_email || ENV["MAGICBELL_BCC_EMAIL"]
|
22
|
-
end
|
23
|
-
|
24
19
|
def api_host
|
25
20
|
@api_host || ENV["MAGICBELL_API_HOST"] || "https://api.magicbell.io"
|
26
21
|
end
|
data/lib/magicbell/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicbell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hana Mohan
|
8
8
|
- Nisanth Chunduru
|
9
|
+
- Rahmane Ousmane
|
10
|
+
- Josue Montano
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: httparty
|
@@ -39,6 +41,20 @@ dependencies:
|
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
41
43
|
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: colorize
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
42
58
|
- !ruby/object:Gem::Dependency
|
43
59
|
name: actionmailer
|
44
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,10 +125,12 @@ dependencies:
|
|
109
125
|
- - ">="
|
110
126
|
- !ruby/object:Gem::Version
|
111
127
|
version: '0'
|
112
|
-
description:
|
128
|
+
description: The notification inbox for your product
|
113
129
|
email:
|
114
130
|
- hana@magicbell.io
|
115
131
|
- nisanth@supportbee.com
|
132
|
+
- rahmane@magicbell.io
|
133
|
+
- josue@magicbell.io
|
116
134
|
executables: []
|
117
135
|
extensions: []
|
118
136
|
extra_rdoc_files: []
|
@@ -139,11 +157,13 @@ files:
|
|
139
157
|
- lib/magicbell/railtie.rb
|
140
158
|
- lib/magicbell/singleton_api_resource.rb
|
141
159
|
- lib/magicbell/version.rb
|
142
|
-
homepage: https://magicbell.
|
160
|
+
homepage: https://magicbell.com
|
143
161
|
licenses:
|
144
162
|
- MIT
|
145
163
|
metadata: {}
|
146
|
-
post_install_message:
|
164
|
+
post_install_message: "\n *** Breaking Change:: The 2.0.0 release removes the BCC
|
165
|
+
functionality. ***\n Please update your MagicBell integration to use the API
|
166
|
+
for creating notifications or downgrade to 1.0.4\n "
|
147
167
|
rdoc_options: []
|
148
168
|
require_paths:
|
149
169
|
- lib
|
@@ -158,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
178
|
- !ruby/object:Gem::Version
|
159
179
|
version: '0'
|
160
180
|
requirements: []
|
161
|
-
rubygems_version: 3.1.
|
181
|
+
rubygems_version: 3.1.6
|
162
182
|
signing_key:
|
163
183
|
specification_version: 4
|
164
|
-
summary: Ruby
|
184
|
+
summary: Ruby Library for MagicBell
|
165
185
|
test_files: []
|