magicbell 0.1.0 → 0.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: 489e38783982ec38f0044781f6bfdb156d7feb782a4bf51d624659fb35accd25
4
- data.tar.gz: 3283ccf989b48e59448386d6471e31bd0e34fb5ef3a33e2ed9df9ec78e11545b
3
+ metadata.gz: b556f6bac34d0deac121d7b456b3322f918e3f77b4e82f0cdcbd8cef395d32d1
4
+ data.tar.gz: 6a56c2b7331c5f3296293f8d2a4bbef8b785bdb762e694b506cab3ac28f21b79
5
5
  SHA512:
6
- metadata.gz: 1c463bee03db65cbde34bc722a5ee368965e56342e0207426daf61337eb1f4fc56b3a394ef4133407beb641b36434085936a81669b9a4f48d78c162453aebee8
7
- data.tar.gz: 26906f1128c18a296bd0478682e79c0151bccbf9b21e809ac07a22840e0cf9e79d52c1f1b97c54078c84386c14a9d789793494856d1d65f1630e95c66693a253
6
+ metadata.gz: a6139d8789a33f4f5cb45216106d86d7f78c9b1fb9743af3115d4ff9f193035a6c3565ebca3195a130529f81d7110ee8fecbbf5790004642b13c4c56887ba53c
7
+ data.tar.gz: 5f2f592ea6a3f13500a084a468118e2bc6ad68a7d0e48a5a087e728b052fa20bd1b6e17a09faa37fe5ddaf5b55f5b4975a231f330a98421de5fdb0f806937367
data/README.md CHANGED
@@ -6,10 +6,10 @@ Convert your email notifications to an in-app notification center. This gem make
6
6
 
7
7
  ## Installation
8
8
 
9
- Add the magicbell-rails gem to your app's Gemfile
9
+ Add the magicbell gem to your app's Gemfile
10
10
 
11
11
  ```ruby
12
- gem "magicbell-rails"
12
+ gem "magicbell"
13
13
  ```
14
14
 
15
15
  Run
@@ -18,10 +18,10 @@ Run
18
18
  bundle install
19
19
  ```
20
20
 
21
- Create the initializer file `config/initializers/magicbell-rails.rb` and add your MagicBell credentials there.
21
+ Create the initializer file `config/initializers/magicbell.rb` and add your MagicBell credentials there.
22
22
 
23
23
  ```
24
- vim config/initializers/magicbell-rails.rb
24
+ vim config/initializers/magicbell.rb
25
25
  ```
26
26
 
27
27
  ```ruby
@@ -51,11 +51,11 @@ Create the partial file `config/layouts/_magicbell.html.erb` and copy paste the
51
51
  $('<link/>', {
52
52
  rel: 'stylesheet',
53
53
  type: 'text/css',
54
- href: "<%= MagicBell.extras_css_url %>"
54
+ href: "<%= MagicBell::EXTRAS_CSS_URL %>"
55
55
  }).appendTo('head');
56
56
  $(document).ready(function () {
57
57
  // Initialize the widget after fetching its javascript
58
- $.getScript("<%= MagicBell.widget_javascript_url %>", initializeMagicBell);
58
+ $.getScript("<%= MagicBell::WIDGET_JAVASCRIPT_URL %>", initializeMagicBell);
59
59
  });
60
60
  function initializeMagicBell() {
61
61
  MagicBell.initialize({
@@ -186,8 +186,32 @@ function initializeMagicBell() {
186
186
  }
187
187
  ```
188
188
 
189
- If you'd like us to add more callbacks to the widget, reach out to us at hana@supportbee.com
189
+
190
+ ## Managing notifications
191
+
192
+ ### Creating a notification
193
+
194
+ You can create notifications for users. Once `MagicBell` is configured, you can
195
+ call `create_notification` method to create a notification for a given project.
196
+
197
+ ```
198
+ params = {
199
+ to: "user@example.com",
200
+ title: "Your download is ready",
201
+ content: "Zip file to download is here",
202
+ action_url: "https://example.com/notifications/1"
203
+ }
204
+
205
+ client = MagicBell::Client.new()
206
+ client.create_notification(params)
207
+ ```
208
+
209
+ The response will be a Faraday response object, and methods like `status` and
210
+ `body` will be available for further inspection.
211
+
212
+
213
+ If you'd like us to add more callbacks to the widget, reach out to us at hana@magicbell.io
190
214
 
191
215
  ## Documentation
192
216
 
193
- Visit our [Docs Site](https://magicbell.supportbee.com/149-magicbell-s-help-docs) for more information on MagicBell, MagicBell's widget and Advanced Features.
217
+ Visit our [Docs Site](https://docs.magicbell.io) for more information on MagicBell, MagicBell's widget and Advanced Features.
@@ -1,12 +1,21 @@
1
1
  require "magicbell/config"
2
2
  require "magicbell/hmac"
3
3
  require "magicbell/user"
4
+ require "magicbell/railtie" if defined?(Rails)
5
+ require "magicbell/client"
6
+
7
+ require 'forwardable'
4
8
 
5
9
 
6
10
  module MagicBell
7
- CLOUDFRONT_DOMAIN = "dxd8ma9fvw6e2.cloudfront.net"
11
+ WIDGET_JAVASCRIPT_URL = "https://assets.magicbell.io/widget.magicbell.js"
12
+ EXTRAS_CSS_URL = "https://assets.magicbell.io/extras.magicbell.css"
8
13
 
9
14
  class << self
15
+ extend Forwardable
16
+
17
+ def_delegators :@config, :api_key, :api_secret, :project_id, :magic_address, :api_host
18
+
10
19
  def configure
11
20
  yield(config)
12
21
  end
@@ -19,35 +28,6 @@ module MagicBell
19
28
  @config = nil
20
29
  end
21
30
 
22
- def extras_css_url
23
- "//#{CLOUDFRONT_DOMAIN}/extras.magicbell.css"
24
- end
25
- alias_method :host_page_css_url, :extras_css_url # Backward compatibility
26
-
27
- def api_host
28
- config.api_host
29
- end
30
-
31
- def widget_javascript_url
32
- "//#{CLOUDFRONT_DOMAIN}/widget.magicbell.js"
33
- end
34
-
35
- def api_key
36
- config.api_key
37
- end
38
-
39
- def api_secret
40
- config.api_secret
41
- end
42
-
43
- def project_id
44
- config.project_id
45
- end
46
-
47
- def magic_address
48
- config.magic_address
49
- end
50
-
51
31
  def project_specific_headers
52
32
  {
53
33
  'X-MAGICBELL-API-KEY' => config.api_key,
@@ -61,5 +41,3 @@ module MagicBell
61
41
  end
62
42
  end
63
43
  end
64
-
65
- require "magicbell/railtie"
@@ -0,0 +1,13 @@
1
+ require "magicbell/client/notifications"
2
+
3
+ module MagicBell
4
+ class Client
5
+ include MagicBell::Client::Notifications
6
+
7
+ # Returns an authenticated connection object which can be
8
+ # used to make requests
9
+ def connection
10
+ @connection ||= Faraday.new(url: MagicBell.api_host)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module MagicBell
2
+ class Client
3
+ module Notifications
4
+ # Creates a notification for a given project
5
+ #
6
+ # @param to [String] Email of a user for this notification
7
+ # @param title [String] Title of the notification
8
+ # @param content [String] Content of the notification
9
+ # @param action_url [String] Url to redirect to from widget
10
+ def create_notification(to, title, content, action_url)
11
+ params = {to: to, title: title, content: content, action_url: action_url}
12
+
13
+ connection.post("/notifications.json") do |req|
14
+ req.headers = {"X-MAGICBELL-API-SECRET" => MagicBell.api_secret}
15
+ req.body = {notification: params}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,5 @@
1
1
  require 'faraday'
2
+ require 'json'
2
3
 
3
4
  module MagicBell
4
5
  class User
@@ -37,4 +38,4 @@ module MagicBell
37
38
  end
38
39
 
39
40
  end
40
- end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module MagicBell
2
- VERSION = '0.1.0'
2
+ VERSION = '0.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: 0.1.0
4
+ version: 0.2.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-04-22 00:00:00.000000000 Z
12
+ date: 2020-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -80,9 +80,10 @@ files:
80
80
  - Rakefile
81
81
  - lib/magicbell.rb
82
82
  - lib/magicbell/action_mailer_extension.rb
83
+ - lib/magicbell/client.rb
84
+ - lib/magicbell/client/notifications.rb
83
85
  - lib/magicbell/config.rb
84
86
  - lib/magicbell/hmac.rb
85
- - lib/magicbell/init/rails.rb
86
87
  - lib/magicbell/railtie.rb
87
88
  - lib/magicbell/user.rb
88
89
  - lib/magicbell/version.rb
@@ -1,27 +0,0 @@
1
- require 'rails'
2
- require 'yaml'
3
-
4
- module MagicBell
5
- module Init
6
- module Rails
7
- class Railtie < ::Rails::Railtie
8
- #rake_tasks do
9
- # load 'magicbell/tasks.rb'
10
- #end
11
-
12
- config.after_initialize do
13
- MagicBell.init!({
14
- :root => ::Rails.root.to_s,
15
- :env => ::Rails.env,
16
- :'config.path' => ::Rails.root.join('config', 'magicbell.yml'),
17
- :logger => Logging::FormattedLogger.new(::Rails.logger),
18
- :framework => :rails
19
- })
20
- MagicBell.load_plugins!
21
- end
22
- end
23
- end
24
- end
25
- end
26
-
27
- MagicBell.install_at_exit_callback