ribbon-intercom 0.1.0 → 0.1.1
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 +4 -4
- data/lib/ribbon/intercom/service.rb +61 -35
- data/lib/ribbon/intercom/utils.rb +4 -0
- data/lib/ribbon/intercom/version.rb +1 -1
- data/lib/tasks/intercom.rake +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f19a9d7871332a1a8abfb1a9b3a376c17b7389a0
|
4
|
+
data.tar.gz: b946129b0caf8b2d3a2236ec58d1a177e692fc96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd606324dd603044b14c318fd0194b7ef571c91214931a519e9b4d3e7c8920d7d82f5220693709dc36dfa6f135967306c569d3dd317fa740f901d70688b318d
|
7
|
+
data.tar.gz: 3de7e4b3da0da1aa1619c91a1c8ac9676dc9509f033e5af1192b5038286829cba55a828042006ba399da81d114b77be43d8afc9d974ff66c4a17a98288cc67ab
|
@@ -33,14 +33,20 @@ module Ribbon::Intercom
|
|
33
33
|
end.merge(@_method_permissions).dup
|
34
34
|
end
|
35
35
|
|
36
|
+
# The call method is needed here because Rails checks to see if a mounted
|
37
|
+
# Rack app can respond_to?(:call). Without it, the Service will not mount
|
38
|
+
def call(env)
|
39
|
+
instance.call(env)
|
40
|
+
end
|
41
|
+
|
36
42
|
def method_missing(meth, *args, &block)
|
37
43
|
instance.send(meth, *args, &block)
|
38
44
|
end
|
39
45
|
|
40
46
|
def _load_store
|
41
|
-
raise "Store name missing"
|
47
|
+
raise "Store name missing" unless (store_name = @_store_name.to_s)
|
42
48
|
|
43
|
-
store =
|
49
|
+
store = Utils.classify(store_name) + "Store"
|
44
50
|
Intercom::Service::ChannelStores.const_get(store).new(@_store_params)
|
45
51
|
end
|
46
52
|
end # Class methods
|
@@ -71,7 +77,8 @@ module Ribbon::Intercom
|
|
71
77
|
end
|
72
78
|
|
73
79
|
def method_permissions!(method_name)
|
74
|
-
method_permissions(method_name) or
|
80
|
+
method_permissions(method_name) or
|
81
|
+
_respond!(404, {}, "Method requested not found.")
|
75
82
|
end
|
76
83
|
|
77
84
|
def sufficient_permissions?(intercom_method)
|
@@ -80,35 +87,14 @@ module Ribbon::Intercom
|
|
80
87
|
end
|
81
88
|
|
82
89
|
def sufficient_permissions!(intercom_method)
|
83
|
-
sufficient_permissions?(intercom_method) or
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# Check permissions
|
92
|
-
intercom_method = env['HTTP_X_INTERCOM_METHOD'].to_sym
|
93
|
-
sufficient_permissions!(intercom_method)
|
94
|
-
|
95
|
-
# Execute the requested method
|
96
|
-
args = _decode_args(request.body.read)
|
97
|
-
|
98
|
-
[intercom_method, args]
|
99
|
-
rescue Errors::UnsafeValueError
|
100
|
-
_respond!(400, {}, "Arg types are invalid")
|
101
|
-
rescue Errors::MissingPermissionsError
|
102
|
-
_respond!(403, {"X-Intercom-Permissions-Missing" => _missing_permissions(intercom_method).to_a.join(',')}, "Permissions missing.")
|
103
|
-
rescue Errors::InvalidMethodError
|
104
|
-
_respond!(404, {}, "Method requested not found.")
|
105
|
-
end
|
106
|
-
|
107
|
-
def call_method(intercom_method, *args)
|
108
|
-
body = Utils.sanitize(send(intercom_method, *args))
|
109
|
-
_respond!(200, {}, body)
|
110
|
-
rescue Errors::UnsafeValueError
|
111
|
-
_respond!(500, {}, "Return value type is invalid")
|
90
|
+
sufficient_permissions?(intercom_method) or
|
91
|
+
_respond!(
|
92
|
+
403,
|
93
|
+
{
|
94
|
+
"X-Intercom-Permissions-Missing" => _missing_permissions(intercom_method).to_a.join(',')
|
95
|
+
},
|
96
|
+
"Permissions missing."
|
97
|
+
)
|
112
98
|
end
|
113
99
|
|
114
100
|
def call(env)
|
@@ -119,8 +105,9 @@ module Ribbon::Intercom
|
|
119
105
|
@env = env
|
120
106
|
|
121
107
|
response = catch(:response) {
|
122
|
-
|
123
|
-
|
108
|
+
_setup_request
|
109
|
+
intercom_method, args = _process_request
|
110
|
+
_call_method(intercom_method, *args)
|
124
111
|
}
|
125
112
|
|
126
113
|
response.finish
|
@@ -130,7 +117,33 @@ module Ribbon::Intercom
|
|
130
117
|
|
131
118
|
private
|
132
119
|
|
133
|
-
def
|
120
|
+
def _setup_request
|
121
|
+
@request = Rack::Request.new(env)
|
122
|
+
_respond!(405) unless request.put?
|
123
|
+
end
|
124
|
+
|
125
|
+
def _process_request
|
126
|
+
_request_authenticated!
|
127
|
+
|
128
|
+
# Load the method name and args from the request
|
129
|
+
intercom_method = _load_method_name
|
130
|
+
args = _load_args
|
131
|
+
|
132
|
+
[intercom_method, args]
|
133
|
+
end
|
134
|
+
|
135
|
+
def _call_method(intercom_method, *args)
|
136
|
+
body = Utils.sanitize(send(intercom_method, *args))
|
137
|
+
_respond!(200, {}, body)
|
138
|
+
rescue Errors::UnsafeValueError
|
139
|
+
_respond!(500, {}, "Return value type is invalid")
|
140
|
+
end
|
141
|
+
|
142
|
+
def _request_authenticated!
|
143
|
+
_respond!(401) unless _request_authenticated?
|
144
|
+
end
|
145
|
+
|
146
|
+
def _request_authenticated?
|
134
147
|
auth = Rack::Auth::Basic::Request.new(env)
|
135
148
|
|
136
149
|
if auth.provided? && auth.basic?
|
@@ -143,6 +156,19 @@ module Ribbon::Intercom
|
|
143
156
|
end
|
144
157
|
end
|
145
158
|
|
159
|
+
def _load_method_name
|
160
|
+
env['HTTP_X_INTERCOM_METHOD'].to_sym.tap { |intercom_method|
|
161
|
+
# Check permissions
|
162
|
+
sufficient_permissions!(intercom_method)
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
def _load_args
|
167
|
+
_decode_args(request.body.read)
|
168
|
+
rescue Errors::UnsafeValueError
|
169
|
+
_respond!(400, {}, "Arg types are invalid")
|
170
|
+
end
|
171
|
+
|
146
172
|
def _missing_permissions(intercom_method)
|
147
173
|
method_permissions(intercom_method) - channel.permissions
|
148
174
|
end
|
data/lib/tasks/intercom.rake
CHANGED
@@ -12,7 +12,7 @@ namespace :intercom do
|
|
12
12
|
|
13
13
|
namespace :service do
|
14
14
|
task :open_channel, [:service_name, :channel_name] => :environment do |t, args|
|
15
|
-
service = args[:service_name]
|
15
|
+
service = Intercom::Utils.classify(args[:service_name])
|
16
16
|
channel_name = args[:channel_name]
|
17
17
|
|
18
18
|
Intercom::const_get(service).open_channel(name: channel_name)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ribbon-intercom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Honer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|