gripcontrol 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/channel.rb +3 -3
- data/lib/gripcontrol.rb +79 -79
- data/lib/grippubcontrol.rb +20 -20
- data/lib/httpresponseformat.rb +21 -21
- data/lib/httpstreamformat.rb +17 -17
- data/lib/websocketevent.rb +3 -3
- data/lib/websocketmessageformat.rb +11 -11
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9f6361417cf24e7e6adfd1113870404cf76d94
|
4
|
+
data.tar.gz: ff8e318986b9334a8f7942448447c3bcf0c5edff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57c6e2fd38ddd0e7284a4e69082699f1f2f2252de667165681eebea39c536656e45301b9d6f8c615c86873b730f0db1ddec68c215edcad3a40ed51ed6b1bcd7b
|
7
|
+
data.tar.gz: fe11ef3af7d180d7893d3ce0b753cc9e2cd2d181146567a9a40ff6e038e36356f8810071d213dd9aade7c7d6ce8fc5894da5be50eb3ac5f731aeda604229db8a
|
data/lib/channel.rb
CHANGED
data/lib/gripcontrol.rb
CHANGED
@@ -16,129 +16,129 @@ require_relative 'grippubcontrol.rb'
|
|
16
16
|
|
17
17
|
class GripControl
|
18
18
|
def self.create_hold(mode, channels, response)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
hold = Hash.new
|
20
|
+
hold['mode'] = mode
|
21
|
+
if channels.is_a?(Channel)
|
22
|
+
channels = [channels]
|
23
|
+
elsif channels.is_a?(String)
|
24
|
+
channels = [Channel.new(channels)]
|
25
25
|
end
|
26
|
-
|
27
|
-
|
26
|
+
raise 'channels.length equal to 0' unless channels.length > 0
|
27
|
+
ichannels = []
|
28
28
|
channels.each do |channel|
|
29
|
-
|
30
|
-
|
29
|
+
if channel.is_a?(String)
|
30
|
+
channel = Channel(channel)
|
31
31
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
ichannel = Hash.new
|
33
|
+
ichannel['name'] = channel.name
|
34
|
+
if !channel.prev_id.nil?
|
35
|
+
ichannel['prev-id'] = channel.prev_id
|
36
36
|
end
|
37
|
-
|
37
|
+
ichannels.push(ichannel)
|
38
38
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
hold['channels'] = ichannels
|
40
|
+
iresponse = nil
|
41
|
+
if !response.nil?
|
42
|
+
if response.is_a?(String)
|
43
|
+
response = Response(nil, nil, nil, response)
|
44
44
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
iresponse = Hash.new
|
46
|
+
if !response.code.nil?
|
47
|
+
iresponse['code'] = response.code
|
48
48
|
end
|
49
|
-
|
50
|
-
|
49
|
+
if !response.reason.nil?
|
50
|
+
iresponse['reason'] = response.reason
|
51
51
|
end
|
52
|
-
|
53
|
-
|
52
|
+
if !response.headers.nil? and response.headers.length > 0
|
53
|
+
iresponse['headers'] = response.headers
|
54
54
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
if !response.body.nil?
|
56
|
+
if response.body.encoding.name == 'ASCII-8BIT'
|
57
|
+
iresponse['body'] = response.body
|
58
|
+
else
|
59
|
+
iresponse['body-bin'] = Base64.encode64(response.body)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
instruct = Hash.new
|
64
|
+
instruct['hold'] = hold
|
65
|
+
if !iresponse.nil?
|
66
|
+
instruct['response'] = iresponse
|
67
67
|
end
|
68
|
-
|
68
|
+
return instruct.to_json
|
69
69
|
end
|
70
70
|
|
71
71
|
def self.create_hold_response(channels, response=nil)
|
72
|
-
|
72
|
+
return GripControl.create_hold('response', channels, response)
|
73
73
|
end
|
74
74
|
|
75
75
|
def self.create_hold_stream(channels, response=nil)
|
76
|
-
|
76
|
+
return create_hold('stream', channels, response)
|
77
77
|
end
|
78
78
|
|
79
79
|
def self.validate_sig(token, key)
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
token = token.encode('utf-8')
|
81
|
+
begin
|
82
|
+
claim = JWT.encode(claim, @auth_jwt_key).decode(token, key,
|
83
83
|
verify_expiration=false)
|
84
|
-
|
85
|
-
|
84
|
+
rescue
|
85
|
+
return false
|
86
86
|
end
|
87
|
-
|
87
|
+
exp = claim.get('exp')
|
88
88
|
if !claim.has_key?('exp')
|
89
89
|
return false
|
90
90
|
end
|
91
|
-
|
92
|
-
|
91
|
+
if Time.now.utc.to_i >= claim['exp']
|
92
|
+
return false
|
93
93
|
end
|
94
|
-
|
94
|
+
return true
|
95
95
|
end
|
96
96
|
|
97
97
|
def self.decode_websocket_events(body)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
out = []
|
99
|
+
start = 0
|
100
|
+
while start < body.length do
|
101
|
+
at = body.index('\r\n', start)
|
102
|
+
if !at.nil?
|
103
|
+
raise 'bad format'
|
104
104
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
105
|
+
typeline = body[start..at - 1]
|
106
|
+
start = at + 2
|
107
|
+
at = typeline.index(' ')
|
108
|
+
if !at.nil?
|
109
|
+
etype = typeline[0..at - 1]
|
110
|
+
clen = ('0x' + typeline[at + 1..-1]).to_s(16)
|
111
|
+
content = body[start:start + clen - 1]
|
112
|
+
start += clen + 2
|
113
|
+
e = WebSocketEvent.new(etype, content)
|
114
|
+
else
|
115
|
+
e = WebSocketEvent.new(typeline)
|
116
116
|
end
|
117
|
-
|
117
|
+
out.push(e)
|
118
118
|
end
|
119
|
-
|
119
|
+
return out
|
120
120
|
end
|
121
121
|
|
122
122
|
def self.encode_websocket_events(events)
|
123
|
-
|
123
|
+
out = ''
|
124
124
|
events.each do |event|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
if !event.content.nil?
|
126
|
+
out += '%s %x\r\n%s\r\n' % [e.type, len(event.content), event.content]
|
127
|
+
else
|
128
|
+
out += '%s\r\n' % [e.type]
|
129
129
|
end
|
130
130
|
end
|
131
|
-
|
131
|
+
return out
|
132
132
|
end
|
133
133
|
|
134
134
|
def self.websocket_control_message(type, args=nil)
|
135
|
-
|
135
|
+
if !args.nil?
|
136
136
|
# REVIEW: is this deep copy workaround effective in this case?
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
out = Marshal.load(Marshal.dump(args))
|
138
|
+
else
|
139
|
+
out = Hash.new
|
140
140
|
end
|
141
|
-
|
142
|
-
|
141
|
+
out['type'] = type
|
142
|
+
return out.to_json
|
143
143
|
end
|
144
144
|
end
|
data/lib/grippubcontrol.rb
CHANGED
@@ -11,37 +11,37 @@ class GripPubControl < PubControl
|
|
11
11
|
alias super_publish publish
|
12
12
|
alias super_publish_async publish_async
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def publish_http_response(channel, http_response, id=nil, prev_id=nil)
|
15
|
+
if http_response.is_a?(String)
|
16
|
+
http_response = HttpResponseFormat.new(nil, nil, nil, http_response)
|
17
17
|
end
|
18
|
-
|
19
|
-
|
18
|
+
item = Item.new(http_response, id, prev_id)
|
19
|
+
super_publish(channel, item)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
def publish_http_response_async(channel, http_response, id=nil,
|
23
23
|
prev_id=nil, callback=nil)
|
24
|
-
|
25
|
-
|
24
|
+
if http_response.is_a?(String)
|
25
|
+
http_response = HttpResponseFormat.new(nil, nil, nil, http_response)
|
26
26
|
end
|
27
|
-
|
28
|
-
|
27
|
+
item = Item.new(http_response, id, prev_id)
|
28
|
+
super_publish_async(channel, item, callback)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def publish_http_stream(channel, http_stream, id=nil, prev_id=nil)
|
32
|
+
if http_stream.is_a?(String)
|
33
|
+
http_stream = HttpStreamFormat.new(http_stream)
|
34
34
|
end
|
35
|
-
|
36
|
-
|
35
|
+
item = Item.new(http_stream, id, prev_id)
|
36
|
+
super_publish(channel, item)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
def publish_http_stream_async(channel, http_stream, id=nil,
|
40
40
|
prev_id=nil, callback=nil)
|
41
|
-
|
42
|
-
|
41
|
+
if http_stream.is_a?(String)
|
42
|
+
http_stream = HttpStreamFormat.new(http_stream)
|
43
43
|
end
|
44
|
-
|
45
|
-
|
44
|
+
item = Item.new(http_stream, id, prev_id)
|
45
|
+
super_publish_async(channel, item, callback)
|
46
46
|
end
|
47
47
|
end
|
data/lib/httpresponseformat.rb
CHANGED
@@ -14,36 +14,36 @@ class HttpResponseFormat < Format
|
|
14
14
|
attr_accessor :headers
|
15
15
|
attr_accessor :body
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def initialize(code=nil, reason=nil, headers=nil, body=nil)
|
18
|
+
@code = code
|
19
|
+
@reason = reason
|
20
|
+
@headers = headers
|
21
|
+
@body = body
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
def name
|
25
|
+
return 'http-response'
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def export
|
29
|
+
out = Hash.new
|
30
|
+
if !@code.nil?
|
31
|
+
out['code'] = @code
|
32
32
|
end
|
33
|
-
|
34
|
-
|
33
|
+
if !@reason.nil?
|
34
|
+
out['reason'] = @reason
|
35
35
|
end
|
36
|
-
|
37
|
-
|
36
|
+
if !@headers.nil? and @headers.length > 0
|
37
|
+
out['headers'] = @headers
|
38
38
|
end
|
39
|
-
|
39
|
+
if !@body.nil?
|
40
40
|
# REVIEW is this the right way to check for binary encoding?
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
if @body.encoding.name == 'ASCII-8BIT'
|
42
|
+
out['body-bin'] = Base64.encode64(@body)
|
43
|
+
else
|
44
|
+
out['body'] = @body
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
return out
|
48
48
|
end
|
49
49
|
end
|
data/lib/httpstreamformat.rb
CHANGED
@@ -12,30 +12,30 @@ class HttpStreamFormat < Format
|
|
12
12
|
attr_accessor :content
|
13
13
|
attr_accessor :close
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def initialize(content=nil, close=false)
|
16
|
+
@content = content
|
17
|
+
@close = close
|
18
|
+
if !@close and @content.nil?
|
19
|
+
raise 'Content not set'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
def name
|
24
|
+
return 'http-stream'
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def export
|
28
|
+
out = Hash.new
|
29
|
+
if @close
|
30
|
+
out['action'] = 'close'
|
31
|
+
else
|
32
|
+
if @content.encoding.name == 'ASCII-8BIT'
|
33
|
+
out['body-bin'] = Base64.encode64(@content)
|
34
|
+
else
|
35
|
+
out['body'] = @content
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
return out
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
data/lib/websocketevent.rb
CHANGED
@@ -11,22 +11,22 @@ require 'pubcontrol'
|
|
11
11
|
class WebSocketMessageFormat < Format
|
12
12
|
attr_accessor :content
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
def initialize(content)
|
15
|
+
@content = content
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
def name
|
19
|
+
return 'ws-message'
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def export
|
23
|
+
out = Hash.new
|
24
|
+
if @content.encoding.name == 'ASCII-8BIT'
|
25
|
+
out['body-bin'] = Base64.encode64(@content)
|
26
|
+
else
|
27
|
+
out['body'] = @content
|
28
28
|
end
|
29
|
-
|
29
|
+
return out
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gripcontrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Bokarius
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-01-04 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pubcontrol
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.5
|
13
27
|
description: A Ruby convenience library for using the GRIP protocol
|
14
28
|
email: bokarius@comcast.net
|
15
29
|
executables: []
|