notifications_opener 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: b6cadc4fb66af2f831b90f3f7b19d2482160a56c
4
- data.tar.gz: 276c9ec2a0998abe9ea187504ed1d0c517b702cf
3
+ metadata.gz: 73460d17fb8bd6f0f018b8fbfd7da6136adc50ea
4
+ data.tar.gz: 09bcb14762bfce0381b52c51779c51c5bda58079
5
5
  SHA512:
6
- metadata.gz: 893b8ced489af284a16d2c0d459fc5b5cc3aadbb356660a5f810b6d2d7b648af00fb9749139b938939a48032773c0a94b223b8718cb0e325fb23c934e226f14e
7
- data.tar.gz: b9babedc4ac5b7ecf4583cc2d42e171baec1cb08002559e3895d19c506192b0646bcc022b95a01f6b75e88bb0f8f79ed5bce341c3e3baf24bcc2fe5f395446cb
6
+ metadata.gz: 22ee94c4749f15356b7a60ba03670e49f47fb937b036ad51db7424d32e4af07269e2898d936563480ec7ab0354c0af7633753921903e732ae8bf9bfeb1623f7d
7
+ data.tar.gz: 8ec7c6309b5a80a6b8fa854a87e0c6779e8b090d1ca86fb15e1b3a85ed8ab963b1603ed821e1346cd371a1b9699c059311b41ad4c76f64e6109b4d344528d590
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # NotificationsOpener
1
+ # Notifications Opener
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/notifications_opener`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Blocks SMSs from being delivered in development. Instead opens a preview in the browser by intercepting the request to the configured SMS API.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,29 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Add the following configuration in your `development.rb`. The following is an example for springedge. It will probably differ based on your provider.
24
+
25
+ ```ruby
26
+ # Blocks SMSs from being delivered in development
27
+ # Instead opens a preview in the browser by intercepting the request to
28
+ # the configured SMS API
29
+ NotificationsOpener.configure do | c |
30
+ # Param name for the sender that will be passed to the SMS API
31
+ c[:from_key_name] = "sender"
32
+
33
+ # Param name for the receiver that will be passed to the SMS API
34
+ c[:to_key_name] = "to"
35
+
36
+ # Param name for the message that will be passed to the API
37
+ c[:message_key_name] = "message"
38
+
39
+ # Location to store the preview email files, usually tmp
40
+ c[:location] = Rails.root.join("tmp").to_s
41
+
42
+ # The SMS API call to intercept
43
+ c[:url] = /.*alerts.springedge.com.*/
44
+ end
45
+ ```
26
46
 
27
47
  ## Development
28
48
 
@@ -32,4 +52,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
52
 
33
53
  ## Contributing
34
54
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/notifications_opener. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abhisheksarka/notifications_opener. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -1,9 +1,14 @@
1
+ ##
2
+ # This class represents as an interceptor for the HTTP requests to the
3
+ # specified URL
4
+
1
5
  require 'webmock'
2
6
  require 'rack'
3
7
 
4
-
8
+ ##
5
9
  # On requiring webmock it disables HTTP connections by default
6
- # so we need to call this method after requiring it
10
+ # so we need to call this method after requiring it, since we only
11
+ # want stub the url that has been passed in the configuration
7
12
  WebMock.allow_net_connect!
8
13
 
9
14
  module NotificationsOpener
@@ -14,9 +19,13 @@ module NotificationsOpener
14
19
  def initialize(config)
15
20
  @config = config
16
21
  @response_handler = ResponseHandler.new(config)
17
- intercept_and_redirect_to_rack_app
18
22
  end
19
23
 
24
+ ##
25
+ # Stubs all HTTP requests to the specified URL
26
+ # We also need to process the response to figure
27
+ # out the sender, receiver and the message so we
28
+ # pass it on a rack application
20
29
  def intercept_and_redirect_to_rack_app
21
30
  WebMock.stub_request(:any, config[:url]).to_rack(response_handler)
22
31
  end
@@ -1,3 +1,6 @@
1
+ ##
2
+ # This class represents builds a usable message based on the parameters
3
+
1
4
  require 'erb'
2
5
  require 'launchy'
3
6
 
@@ -20,19 +23,25 @@ module NotificationsOpener
20
23
  @file_path = get_file_path
21
24
  end
22
25
 
26
+ # #
27
+ # Creates the file with the interpolated content in the specified location
28
+ # Opens it up in a browser from preview
23
29
  def deliver
24
30
  File.open(file_path, 'w') { | file | file.write(rendered_content) }
25
31
  Launchy.open("file:///#{URI.parse(file_path)}")
26
32
  end
27
33
 
28
- def template
29
- File.read(File.expand_path("../message.html.erb", __FILE__))
30
- end
31
-
34
+ # #
35
+ # Uses the message template and binds the instance variable to the template
36
+ # to generate the final markup
32
37
  def rendered_content
33
38
  ERB.new(template).result(binding)
34
39
  end
35
40
 
41
+ def template
42
+ File.read(File.expand_path("../message.html.erb", __FILE__))
43
+ end
44
+
36
45
  def get_file_path
37
46
  location + '/' + SecureRandom.hex + '.html'
38
47
  end
@@ -1,3 +1,7 @@
1
+ ##
2
+ # The (instance of)class represents a Rack application
3
+ # Responsible to handle a stubbed request manually
4
+
1
5
  module NotificationsOpener
2
6
  class ResponseHandler
3
7
  attr_accessor :config,
@@ -1,3 +1,3 @@
1
1
  module NotificationsOpener
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -5,11 +5,22 @@ require "notifications_opener/interceptor"
5
5
  require 'fileutils'
6
6
 
7
7
  module NotificationsOpener
8
+
9
+ # #
10
+ # Configure the module by passing required options
11
+ #
12
+ # * url - The SMS API URL
13
+ # * location - Generated preview files will stored here, usually tmp
14
+ # * from_key_name - The parameter name you pass to the SMS API that identifies the sender
15
+ # * to_key_name - The parameter name you pass to the SMS API that identifies the receiver
16
+ # * message_key_name - The parameter name you pass to the SMS API that identifies the message
8
17
  def self.configure
9
18
  c = { }
10
19
  yield(c)
11
20
  create_storage_directory(c)
12
21
  ins = Interceptor.new(c)
22
+ ins.intercept_and_redirect_to_rack_app
23
+ ins
13
24
  end
14
25
 
15
26
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications_opener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - abhisheksarka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-07 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler