magicbell 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a080e99c355e6781a4387124238f7e02e738cd5a0bb4a7a5c71856f079e70f9d
4
- data.tar.gz: 26811279e07a4952a4ec17f3e02d84f7d845b4abd0137545df04a5efeeb58fe2
3
+ metadata.gz: 205676a39e21a70f18682b926501b0d8c67ea674df273cbda92fe838f21b0750
4
+ data.tar.gz: 9d0e2fbf7661d9cd6f4f910fa2d0dd89e2ee6d230798015cabe606202627ca53
5
5
  SHA512:
6
- metadata.gz: 25de345e29db78e48e568d43f86df7c1165eeed5f239ae6ec135073012489a1f9c31b966bc05c8fa4265926c37eae288c2c77a801b265e99219fa6c3332e80f6
7
- data.tar.gz: 178dc4d58a27803ab5af948dcfc89d70eceeb6dd5bb6fc08fae998004af8a4ecfa0a611a222657b38c95a03999b418f44bd626557571c9cfd9fb63cae6291cad
6
+ metadata.gz: 524d8ed46c49c90e295974547b72b05db01a80ce3215070f48348a846ddcada01f07368846f4bbd5baca680a3ff8127e43abe5915bf1c85dfcb423270e72a8b9
7
+ data.tar.gz: 0d3d21452e55687032910556225db73a2f95d933d6a6f54edc9897c3499326ce8d9b527fa1226f9853352157cfb3c1cdbe1634dbbb58910078dd822c264e3512
data/README.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # MagicBell Ruby Library
2
2
 
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.
3
+ This library provides convenient access to the [MagicBell REST API](https://magicbell.com/docs/rest-api/overview)
4
+ from applications written in Ruby. It includes helpers for creating
5
+ notifications, fetching them, and calculating the HMAC for a user.
4
6
 
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).
7
+ [MagicBell](https://magicbell.com) is the notification inbox for your web and
8
+ mobile applications. You may find it helpful to familiarize yourself with the
9
+ [core concepts of MagicBell](https://magicbell.com/docs/core-concepts).
6
10
 
7
11
  <img width="415" alt="MagicBell Notification Inbox" src="https://files.readme.io/c09b21a-image1.png">
8
12
 
9
13
  ## Installation
10
14
 
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.
15
+ First, [sign up for a MagicBell account](https://magicbell.com) and grab your
16
+ MagicBell project's API key and secret from the "Settings" section of your
17
+ MagicBell dashboard.
12
18
 
13
19
  If you just want to use the package, run:
14
20
 
@@ -31,13 +37,18 @@ and run `bundle install` a usual.
31
37
 
32
38
  ## Configuration
33
39
 
34
- The library needs to be configured with your MagicBell project's API key and secret.
40
+ The library needs to be configured with your MagicBell project's API key and
41
+ secret.
35
42
 
36
43
  ### Global configuration
37
44
 
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.
45
+ By default, this library will automatically pick your MagicBell project's API
46
+ key and secret from the `MAGICBELL_API_KEY` and `MAGICBELL_API_SECRET`
47
+ environment variables, respectively.
39
48
 
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:
49
+ Alternatively, you can configure your MagicBell manually. For example, for a
50
+ rails project, create an initializer file for MagicBell and set your project's
51
+ keys:
41
52
 
42
53
  ```ruby
43
54
  # config/initializers/magicbell.rb
@@ -50,7 +61,8 @@ end
50
61
 
51
62
  ### Per-request configuration
52
63
 
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`:
64
+ For apps that need to use multiple keys during the lifetime of a process,
65
+ provide the specific keys when you create instances of `MagicBell::Client`:
54
66
 
55
67
  ```ruby
56
68
  require 'magicbell'
@@ -61,13 +73,15 @@ magicbell = MagicBell::Client.new(
61
73
  )
62
74
  ```
63
75
 
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.
76
+ Please keep in mind that any instance of `MagicBell::Client` will default to the
77
+ global configuration unless an API key and secret are provided.
65
78
 
66
79
  ## Usage
67
80
 
68
81
  ### Create a notification
69
82
 
70
- You can send a notification to one or many users by identifying them by their email address:
83
+ You can send a notification to one or many users by identifying them by their
84
+ email address:
71
85
 
72
86
  ```ruby
73
87
  require 'magicbell'
@@ -97,7 +111,9 @@ magicbell.create_notification(
97
111
  )
98
112
  ```
99
113
 
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.
114
+ This method has the benefit of allowing users to access their notifications when
115
+ their email address changes. Make sure you identify users by their `externalID`
116
+ when you [initialize the notification inbox](https://magicbell.com/docs/react/identifying-users), too.
101
117
 
102
118
  You can also provide other data accepted by [our API](https://magicbell.com/docs/rest-api/reference):
103
119
 
@@ -141,7 +157,12 @@ user = magicbell.user_with_email('joe@example.com')
141
157
  user.notifications.each { |notification| puts notification.attribute('title') }
142
158
  ```
143
159
 
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:
160
+ If you identify a user by an ID, you can use the
161
+ `magicbell.user_with_external_id` method instead.
162
+
163
+ Please note that the example above fetches the user's 15 most recent
164
+ notifications (the default number per page). If you'd like to fetch subsequent
165
+ pages, use the `each_page` method instead:
145
166
 
146
167
  ```ruby
147
168
  require 'magicbell'
@@ -194,7 +215,8 @@ user.mark_all_notifications_as_seen
194
215
 
195
216
  ### Error handling
196
217
 
197
- This gem raises a `MagicBell::Client::HTTPError` if the MagicBell API returns a non-2xx response.
218
+ This gem raises a `MagicBell::Client::HTTPError` if the MagicBell API returns a
219
+ non-2xx response.
198
220
 
199
221
  ```ruby
200
222
  require 'magicbell'
@@ -218,7 +240,9 @@ end
218
240
 
219
241
  ### Calculate the HMAC secret for a user
220
242
 
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.
243
+ You can use the `MagicBell.hmac` method. Note that in this case, the API secret,
244
+ which is used to generate the HMAC, will be fetched from the global
245
+ configuration.
222
246
 
223
247
  ```ruby
224
248
  require 'magicbell'
@@ -226,7 +250,8 @@ require 'magicbell'
226
250
  hmac = MagicBell.hmac('joe@example.com')
227
251
  ```
228
252
 
229
- You can also use the API secret of a specific client instance to calculate the HMAC:
253
+ You can also use the API secret of a specific client instance to calculate the
254
+ HMAC:
230
255
 
231
256
  ```ruby
232
257
  require 'magicbell'
@@ -239,12 +264,15 @@ magicbell = MagicBell::Client.new(
239
264
  hmac = magicbell.hmac('joe@example.com')
240
265
  ```
241
266
 
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.
267
+ Please refer to our docs to know [how to turn on HMAC authentication](https://magicbell.com/docs/turn-on-hmac-authentication)
268
+ for your MagicBell project.
243
269
 
244
270
  ## API docs
245
271
 
246
- Please visit [our website](https://magicbell.com) and [our docs](https://magicbell.com/docs) for more information.
272
+ Please visit [our website](https://magicbell.com) and
273
+ [our docs](https://magicbell.com/docs) for more information.
247
274
 
248
275
  ## Contact Us
249
276
 
250
- Have a query or hit upon a problem? Feel free to contact us at [hello@magicbell.io](mailto:hello@magicbell.io).
277
+ Have a query or hit upon a problem? Feel free to contact us at
278
+ [hello@magicbell.io](mailto:hello@magicbell.io).
@@ -2,11 +2,13 @@ module MagicBell
2
2
  class User < ApiResource
3
3
  include ApiOperations
4
4
 
5
- attr_reader :email
5
+ attr_reader :email, :external_id
6
6
 
7
7
  def initialize(client, attributes)
8
8
  @client = client
9
9
  @email = attributes["email"]
10
+ @external_id = attributes["external_id"]
11
+
10
12
  super(client, attributes)
11
13
  end
12
14
 
@@ -38,13 +40,19 @@ module MagicBell
38
40
  def path
39
41
  if id
40
42
  self.class.path + "/#{id}"
43
+ elsif external_id
44
+ self.class.path + "/external_id:#{external_id}"
41
45
  elsif email
42
46
  self.class.path + "/email:#{email}"
43
47
  end
44
48
  end
45
49
 
46
50
  def authentication_headers
47
- MagicBell.authentication_headers.merge("X-MAGICBELL-USER-EMAIL" => email)
51
+ if external_id
52
+ MagicBell.authentication_headers.merge("X-MAGICBELL-USER-EXTERNAL-ID" => external_id)
53
+ elsif email
54
+ MagicBell.authentication_headers.merge("X-MAGICBELL-USER-EMAIL" => email)
55
+ end
48
56
  end
49
57
  end
50
58
  end
@@ -18,15 +18,16 @@ module MagicBell
18
18
  MagicBell::Notification.create(self, notification_attributes)
19
19
  end
20
20
 
21
- # def user(user_id)
22
- # MagicBell::User.find(user_id)
23
- # end
24
-
25
21
  def user_with_email(email)
26
22
  client = self
27
23
  MagicBell::User.new(client, "email" => email)
28
24
  end
29
25
 
26
+ def user_with_external_id(external_id)
27
+ client = self
28
+ MagicBell::User.new(client, "external_id" => external_id)
29
+ end
30
+
30
31
  def authentication_headers
31
32
  MagicBell.authentication_headers(client_api_key: @api_key, client_api_secret: @api_secret)
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module MagicBell
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magicbell
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hana Mohan
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-10-04 00:00:00.000000000 Z
14
+ date: 2021-10-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty