magicbell 1.0.0 → 2.0.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: 6e077cbab9516c5f39de74e8d751cb7f4c02535d20e607c7a1f114b4871d4162
4
- data.tar.gz: 2178667f6c4a195fabc1b18088de577890b44318b0503d8ab22ac99b03fdccaf
3
+ metadata.gz: 76d91ee7dd27c175853dff9ff3dcf5a296dbf58c5151f1a228841a23beb57cc3
4
+ data.tar.gz: dd40c6308d20d6219ef0d5a7962d4a70f5e0f381bf8911c76eec1d9d3dbcd439
5
5
  SHA512:
6
- metadata.gz: 9115a61e4752213c1a8fa196bfeec81dfbd0238f9f6726f7aa8d6b8298150883388fed947938bf7208b503c5828dce30d0976b27d2b607bd0fad3e6a2018d365
7
- data.tar.gz: 412d96624b8c875f2ebbf422d6891d444ea933ed891ad8fe51bd39dfead821599a87f5a5bcd0bb18f8e63cb7cc68be2638fc6bda085eec1b6a325dbed3c20625
6
+ metadata.gz: 2eb10d824cc3228716ef4e1f0c4f392d44528e6b961352e382bb8dc8790ec12cafccdb9a9210a4211dc459a436930a5ec1901bdf8fa58ee17bc63cc041c779ab
7
+ data.tar.gz: 1895cbe977bcd395598963545f057fb2e5bb614faa5b6d57eed185d1892dbef0a90e9aa736a59ac601c6b26478718f1b52a289bb23c3566bd0f0e2126c77652b
data/README.md CHANGED
@@ -1,18 +1,22 @@
1
1
  # magicbell-ruby
2
2
 
3
- [MagicBell](https://magicbell.io) is an embeddable Notification Inbox for web applications.
3
+ [MagicBell](https://magicbell.io) is an embeddable Notification Inbox for web & mobile applications.
4
+
5
+ Please familiarlize yourself with the [core concepts of MagicBell](https://developer.magicbell.io/docs/core-concepts) before using this gem.
4
6
 
5
7
  This gem
6
8
 
7
9
  1. Makes it easy to interact with [MagicBell's REST API](https://developer.magicbell.io/reference) from Ruby.
8
10
 
9
11
  You can use it to create a notification in your MagicBell project etc.
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
14
12
 
15
- <img width="415" alt="MagicBell Notification Inbox" src="https://user-images.githubusercontent.com/1789832/28327736-f3503f44-6c01-11e7-9a72-c15023db18c6.png">
13
+ 2. Can BCC your ActionMailer email notifications to MagicBell if you rather not use MagicBell's API in your Rails application.
14
+
15
+ MagicBell will create an in-app notification from any email notification that's blind copied to it.
16
+
17
+ 3. Helps you calculate the HMAC for a user's email or external_id when you turn on [HMAC Authentication](https://developer.magicbell.io/docs/turn-on-hmac-authentication) for your MagicBell project
18
+
19
+ <img width="415" alt="MagicBell Notification Inbox" src="https://files.readme.io/c09b21a-image1.png">
16
20
 
17
21
  ## Installation
18
22
 
@@ -51,7 +55,7 @@ This gem makes it easy to interact with MagicBell's REST API https://developer.m
51
55
 
52
56
  ### Create a notification
53
57
 
54
- Send a notification to one or many users
58
+ Send a notification to one or many users by identifying them with their email address
55
59
 
56
60
  ```ruby
57
61
  magicbell = MagicBell::Client.new
@@ -65,6 +69,17 @@ magicbell.create_notification(
65
69
  )
66
70
  ```
67
71
 
72
+ You can also identify users with their `external_id`, which is their ID in your database. That way, if their email address changes, they'd still have access to their notifications. You'll need to make sure you identify them with their `externalID` [in your frontend](https://developer.magicbell.io/docs/browser-js#identifying-users).
73
+
74
+ ```ruby
75
+ magicbell.create_notification(
76
+ title: "Welcome to Muziboo",
77
+ recipients: [{
78
+ external_id: "id_in_your_database"
79
+ }]
80
+ )
81
+ ```
82
+
68
83
  You can even provide content for the notification and a URL to redirect the user to when they click on the notification the MagicBell Notification Inbox
69
84
 
70
85
  ```ruby
@@ -162,7 +177,7 @@ class NotificationMailer < ActionMailer::Base
162
177
  def new_comment
163
178
  # ...
164
179
  end
165
-
180
+
166
181
  # This is another email notification in your app
167
182
  def mentioned
168
183
  # ...
@@ -233,7 +248,14 @@ hmac = MagicBell.hmac(user_email)
233
248
 
234
249
  See https://developer.magicbell.io/docs/turn-on-hmac-authentication for more information on turning on HMAC Authentication for your MagicBell Project
235
250
 
251
+ ## API docs
252
+
253
+ Please visit our website https://magicbell.io and our API docs https://developer.magicbell.io for more information MagicBell's embeddable notification inbox and MagicBell's REST API
254
+
255
+ ## Contact Us
236
256
 
237
- ## Developer Hub
257
+ Have a query or hit upon a problem? Create a post in our Developer Community https://community.magicbell.io or contact us at hello@magicbell.io
238
258
 
239
- Please visit our [Developer Hub](https://developer.magicbell.io) for documentation on MagicBell's API and MagicBell's embeddable Notification Inbox
259
+ ```
260
+
261
+ ```
@@ -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
- response = HTTParty.get(
5
- url,
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
- response = HTTParty.post(
15
- url,
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
- response = HTTParty.put(
25
- url,
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
@@ -1,4 +1,5 @@
1
1
  require "active_support/inflector"
2
+ require "active_support/core_ext/object/blank"
2
3
  require "json"
3
4
 
4
5
  module MagicBell
@@ -8,6 +9,12 @@ module MagicBell
8
9
  new(client, attributes).create
9
10
  end
10
11
 
12
+ def find(client, id)
13
+ api_resource = new(client, "id" => id)
14
+ api_resource.retrieve
15
+ api_resource
16
+ end
17
+
11
18
  def name
12
19
  to_s.demodulize.underscore
13
20
  end
@@ -72,7 +79,7 @@ module MagicBell
72
79
  response = @client.post(
73
80
  create_url,
74
81
  body: { name => attributes }.to_json,
75
- headers: authentication_headers
82
+ headers: extra_headers
76
83
  )
77
84
  parse_response(response)
78
85
 
@@ -83,7 +90,7 @@ module MagicBell
83
90
  response = @client.put(
84
91
  url,
85
92
  body: new_attributes.to_json,
86
- headers: authentication_headers
93
+ headers: extra_headers
87
94
  )
88
95
  parse_response(response)
89
96
 
@@ -92,8 +99,8 @@ module MagicBell
92
99
 
93
100
  protected
94
101
 
95
- def authentication_headers
96
- MagicBell.authentication_headers
102
+ def extra_headers
103
+ {}
97
104
  end
98
105
 
99
106
  private
@@ -109,7 +116,7 @@ module MagicBell
109
116
 
110
117
  def parse_response(response)
111
118
  @response = response
112
- unless response.body.empty?
119
+ unless response.body.blank?
113
120
  @response_hash = JSON.parse(@response.body)
114
121
  @attributes = @response_hash[name]
115
122
  end
@@ -15,6 +15,11 @@ module MagicBell
15
15
  MagicBell::UserNotifications.new(client, query_params)
16
16
  end
17
17
 
18
+ def find_notification(notification_id)
19
+ client = self
20
+ MagicBell::UserNotification.find(client, notification_id)
21
+ end
22
+
18
23
  def mark_all_notifications_as_read
19
24
  client = self
20
25
  MagicBell::UserNotificationsRead.new(client).create
@@ -1,5 +1,5 @@
1
1
  module MagicBell
2
- class UserNotificationRead < SingletonApiResource
2
+ class UserNotificationUnread < SingletonApiResource
3
3
  attr_reader :user_notification
4
4
 
5
5
  def initialize(client, attributes)
@@ -3,7 +3,8 @@ 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
@@ -1,3 +1,3 @@
1
1
  module MagicBell
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.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: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hana Mohan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-03 00:00:00.000000000 Z
12
+ date: 2021-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: colorize
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: actionmailer
44
58
  requirement: !ruby/object:Gem::Requirement