notifications_opener 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 883f8b5c7c2d01571e1c0eab6304dce6be1b8b85
|
4
|
+
data.tar.gz: 50e31296b78f07f8735a3d1a674ae749f2fd0c9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ccef8872761f72855b4c71bc48e4b3c9986321ded79533eed8bbe81d9001efef09afc4918c3b9c63fc54ff54b3e3e6df134b7e1d1ef0dd687d8a7ebfbb4caac
|
7
|
+
data.tar.gz: c7496ad12e0bfa3762ee66ea7de660e2a28cecd9fc1789a2f214d8de6777744d19730e72e93cb9e16d96a40e71d820e0d1e33b6e709cc18baaeb9363e76009d0
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://badge.fury.io/rb/notifications_opener)
|
2
|
+
|
1
3
|
# Notifications Opener
|
2
4
|
|
3
5
|
Blocks SMSs from being delivered in development. Instead opens a preview in the browser by intercepting the request to the configured SMS API.
|
@@ -1,10 +1,5 @@
|
|
1
|
-
##
|
2
|
-
# This class represents as an interceptor for the HTTP requests to the
|
3
|
-
# specified URL
|
4
|
-
|
5
1
|
require 'webmock'
|
6
2
|
require 'rack'
|
7
|
-
|
8
3
|
##
|
9
4
|
# On requiring webmock it disables HTTP connections by default
|
10
5
|
# so we need to call this method after requiring it, since we only
|
@@ -12,6 +7,9 @@ require 'rack'
|
|
12
7
|
WebMock.allow_net_connect!
|
13
8
|
|
14
9
|
module NotificationsOpener
|
10
|
+
##
|
11
|
+
# This class represents as an interceptor for the HTTP requests to the
|
12
|
+
# specified URL
|
15
13
|
class Interceptor
|
16
14
|
attr_accessor :config,
|
17
15
|
:response_handler
|
@@ -1,10 +1,9 @@
|
|
1
|
-
##
|
2
|
-
# This class represents builds a usable message based on the parameters
|
3
|
-
|
4
1
|
require 'erb'
|
5
2
|
require 'launchy'
|
6
3
|
|
7
4
|
module NotificationsOpener
|
5
|
+
##
|
6
|
+
# This class represents builds a usable message based on the parameters
|
8
7
|
class Message
|
9
8
|
attr_accessor :config,
|
10
9
|
:from,
|
@@ -20,14 +19,14 @@ module NotificationsOpener
|
|
20
19
|
@message = config[:message]
|
21
20
|
|
22
21
|
@location = config[:location]
|
23
|
-
@file_path =
|
22
|
+
@file_path = generate_file_path
|
24
23
|
end
|
25
24
|
|
26
25
|
# #
|
27
26
|
# Creates the file with the interpolated content in the specified location
|
28
27
|
# Opens it up in a browser from preview
|
29
28
|
def deliver
|
30
|
-
File.open(file_path, 'w') { |
|
29
|
+
File.open(file_path, 'w') { |file| file.write(rendered_content) }
|
31
30
|
Launchy.open("file:///#{URI.parse(file_path)}")
|
32
31
|
end
|
33
32
|
|
@@ -39,10 +38,10 @@ module NotificationsOpener
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def template
|
42
|
-
File.read(File.expand_path(
|
41
|
+
File.read(File.expand_path('../message.html.erb', __FILE__))
|
43
42
|
end
|
44
|
-
|
45
|
-
def
|
43
|
+
|
44
|
+
def generate_file_path
|
46
45
|
location + '/' + SecureRandom.hex + '.html'
|
47
46
|
end
|
48
47
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
##
|
2
|
-
# The (instance of)class represents a Rack application
|
3
|
-
# Responsible to handle a stubbed request manually
|
4
|
-
|
5
1
|
module NotificationsOpener
|
2
|
+
##
|
3
|
+
# The (instance of)class represents a Rack application
|
4
|
+
# Responsible to handle a stubbed request manually
|
6
5
|
class ResponseHandler
|
7
6
|
attr_accessor :config,
|
8
7
|
:message
|
@@ -12,10 +11,11 @@ module NotificationsOpener
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def call(env)
|
15
|
-
|
14
|
+
message_params = get_required_params(env['QUERY_STRING'])
|
15
|
+
@message = NotificationsOpener::Message.new(message_params)
|
16
16
|
message.deliver
|
17
17
|
|
18
|
-
[200, {
|
18
|
+
[200, {}, []]
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -31,12 +31,11 @@ module NotificationsOpener
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_params_from_query_string(q)
|
34
|
-
p = {
|
35
|
-
q.split('&').each do |
|
34
|
+
p = {}
|
35
|
+
q.split('&').each do |kv|
|
36
36
|
kv = kv.split('=')
|
37
37
|
p[kv[0]] = kv[1]
|
38
38
|
end
|
39
|
-
p p
|
40
39
|
p
|
41
40
|
end
|
42
41
|
end
|