magicbell 2.1.1 → 2.2.1

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: 227b2cb36060dcd39e520a0bb39da83c26c51dace5628654e53f6183de9d4f1f
4
- data.tar.gz: 8831c5e2e1ecbfb92571274fa2c88ffa5f69e31f584056bbbbd45ba516a40a0e
3
+ metadata.gz: eedaf7b8daa059db2c0477a2603219d6e5aa4b35d70e6ea53a8054916789952e
4
+ data.tar.gz: a37230ec4507798ee0399c104d3b7a910619d608bcd68356be3c88c374e4c778
5
5
  SHA512:
6
- metadata.gz: 9cf7e78a7f15536638a6689c65b1fc2c87138c708c062b6b28744838df205cb2e0f72f6350bba502d57ad12300911bb485e61f54b03fe6e2c6d6b12597ff0f11
7
- data.tar.gz: a498534bed9613ec8dbd0c04641fee9a657fd60468a0db903799933665450279e30ffcb13afeaf41b49f3933876b3efb321e1ab3dc6d5f0c834d2d7bb49a0528
6
+ metadata.gz: 117c76b63a947597ca6eaf21b1c08cd77f718b94aef7c1ecac0ed8def997efee414fb7c2fbabf6e5435cde5678c14bd335ec7b4ff61426e5628af018a500a894
7
+ data.tar.gz: 7a1103309ed1672be22535373d59ea9c5083e856022008ce4b4078088a704277f70f77267c707c081fe07273074fb6797ede8a252c13775a3bb3dc53c258823d
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).
@@ -46,10 +46,14 @@ module MagicBell
46
46
  body = JSON.parse(response.body)
47
47
  e.errors = body["errors"].is_a?(Array) ? body["errors"] : []
48
48
  e.errors.each do |error, index|
49
- puts "#{error["suggestion"].red}"
50
- puts "#{error["help_link"].blue.on_white}"
49
+ suggestion = error["suggestion"]
50
+ help_link = error["help_link"]
51
+
52
+ puts "#{suggestion.red}" if suggestion
53
+ puts "#{help_link.blue.on_white}" if help_link
51
54
  end
52
55
  end
56
+
53
57
  raise e
54
58
  end
55
59
  end
@@ -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
@@ -40,7 +41,7 @@ module MagicBell
40
41
  private
41
42
 
42
43
  def sha256_digest
43
- OpenSSL::Digest::Digest.new('sha256')
44
+ OpenSSL::Digest.new('sha256')
44
45
  end
45
46
  end
46
47
  end
@@ -1,3 +1,3 @@
1
1
  module MagicBell
2
- VERSION = '2.1.1'
2
+ VERSION = '2.2.1'
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.1
4
+ version: 2.2.1
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: 2022-03-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty