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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7abc023fc0faffad3040b8ce12b0c4b1b4d20e58
4
- data.tar.gz: 5388924b9251ce2610310825114cb8b631d64b0d
3
+ metadata.gz: 3d9f6361417cf24e7e6adfd1113870404cf76d94
4
+ data.tar.gz: ff8e318986b9334a8f7942448447c3bcf0c5edff
5
5
  SHA512:
6
- metadata.gz: 8d48568f8e78f118e6528c1f6c0e73a64f717b849f7a9985078275c5b30fb7b2a4c2fd2a2b1ab18659fc4011097a35136ec2a24cd654b94b0fc5f984421cd582
7
- data.tar.gz: 0d19c9558e6b3c945d80f92b762f18a2e73307ff6fd02dd5c382a05063d2352426bfc3f7d70175a6c54d0f159c9bdc8bbd9738378bfcf879be4f5834d323fc27
6
+ metadata.gz: 57c6e2fd38ddd0e7284a4e69082699f1f2f2252de667165681eebea39c536656e45301b9d6f8c615c86873b730f0db1ddec68c215edcad3a40ed51ed6b1bcd7b
7
+ data.tar.gz: fe11ef3af7d180d7893d3ce0b753cc9e2cd2d181146567a9a40ff6e038e36356f8810071d213dd9aade7c7d6ce8fc5894da5be50eb3ac5f731aeda604229db8a
data/lib/channel.rb CHANGED
@@ -9,9 +9,9 @@ class Channel
9
9
  attr_accessor :name
10
10
  attr_accessor :prev_id
11
11
 
12
- def initialize(name, prev_id=nil)
13
- @name = name
14
- @prev_id = prev_id
12
+ def initialize(name, prev_id=nil)
13
+ @name = name
14
+ @prev_id = prev_id
15
15
  end
16
16
  end
17
17
 
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
- 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)]
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
- raise 'channels.length equal to 0' unless channels.length > 0
27
- ichannels = []
26
+ raise 'channels.length equal to 0' unless channels.length > 0
27
+ ichannels = []
28
28
  channels.each do |channel|
29
- if channel.is_a?(String)
30
- channel = Channel(channel)
29
+ if channel.is_a?(String)
30
+ channel = Channel(channel)
31
31
  end
32
- ichannel = Hash.new
33
- ichannel['name'] = channel.name
34
- if !channel.prev_id.nil?
35
- ichannel['prev-id'] = channel.prev_id
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
- ichannels.push(ichannel)
37
+ ichannels.push(ichannel)
38
38
  end
39
- hold['channels'] = ichannels
40
- iresponse = nil
41
- if !response.nil?
42
- if response.is_a?(String)
43
- response = Response(nil, nil, nil, response)
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
- iresponse = Hash.new
46
- if !response.code.nil?
47
- iresponse['code'] = response.code
45
+ iresponse = Hash.new
46
+ if !response.code.nil?
47
+ iresponse['code'] = response.code
48
48
  end
49
- if !response.reason.nil?
50
- iresponse['reason'] = response.reason
49
+ if !response.reason.nil?
50
+ iresponse['reason'] = response.reason
51
51
  end
52
- if !response.headers.nil? and response.headers.length > 0
53
- iresponse['headers'] = response.headers
52
+ if !response.headers.nil? and response.headers.length > 0
53
+ iresponse['headers'] = response.headers
54
54
  end
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)
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
- instruct = Hash.new
64
- instruct['hold'] = hold
65
- if !iresponse.nil?
66
- instruct['response'] = iresponse
63
+ instruct = Hash.new
64
+ instruct['hold'] = hold
65
+ if !iresponse.nil?
66
+ instruct['response'] = iresponse
67
67
  end
68
- return instruct.to_json
68
+ return instruct.to_json
69
69
  end
70
70
 
71
71
  def self.create_hold_response(channels, response=nil)
72
- return GripControl.create_hold('response', channels, response)
72
+ return GripControl.create_hold('response', channels, response)
73
73
  end
74
74
 
75
75
  def self.create_hold_stream(channels, response=nil)
76
- return create_hold('stream', channels, response)
76
+ return create_hold('stream', channels, response)
77
77
  end
78
78
 
79
79
  def self.validate_sig(token, key)
80
- token = token.encode('utf-8')
81
- begin
82
- claim = JWT.encode(claim, @auth_jwt_key).decode(token, key,
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
- rescue
85
- return false
84
+ rescue
85
+ return false
86
86
  end
87
- exp = claim.get('exp')
87
+ exp = claim.get('exp')
88
88
  if !claim.has_key?('exp')
89
89
  return false
90
90
  end
91
- if Time.now.utc.to_i >= claim['exp']
92
- return false
91
+ if Time.now.utc.to_i >= claim['exp']
92
+ return false
93
93
  end
94
- return true
94
+ return true
95
95
  end
96
96
 
97
97
  def self.decode_websocket_events(body)
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'
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
- 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)
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
- out.push(e)
117
+ out.push(e)
118
118
  end
119
- return out
119
+ return out
120
120
  end
121
121
 
122
122
  def self.encode_websocket_events(events)
123
- out = ''
123
+ out = ''
124
124
  events.each do |event|
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]
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
- return out
131
+ return out
132
132
  end
133
133
 
134
134
  def self.websocket_control_message(type, args=nil)
135
- if !args.nil?
135
+ if !args.nil?
136
136
  # REVIEW: is this deep copy workaround effective in this case?
137
- out = Marshal.load(Marshal.dump(args))
138
- else
139
- out = Hash.new
137
+ out = Marshal.load(Marshal.dump(args))
138
+ else
139
+ out = Hash.new
140
140
  end
141
- out['type'] = type
142
- return out.to_json
141
+ out['type'] = type
142
+ return out.to_json
143
143
  end
144
144
  end
@@ -11,37 +11,37 @@ class GripPubControl < PubControl
11
11
  alias super_publish publish
12
12
  alias super_publish_async publish_async
13
13
 
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)
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
- item = Item.new(http_response, id, prev_id)
19
- super_publish(channel, item)
18
+ item = Item.new(http_response, id, prev_id)
19
+ super_publish(channel, item)
20
20
  end
21
21
 
22
- def publish_http_response_async(channel, http_response, id=nil,
22
+ def publish_http_response_async(channel, http_response, id=nil,
23
23
  prev_id=nil, callback=nil)
24
- if http_response.is_a?(String)
25
- http_response = HttpResponseFormat.new(nil, nil, nil, http_response)
24
+ if http_response.is_a?(String)
25
+ http_response = HttpResponseFormat.new(nil, nil, nil, http_response)
26
26
  end
27
- item = Item.new(http_response, id, prev_id)
28
- super_publish_async(channel, item, callback)
27
+ item = Item.new(http_response, id, prev_id)
28
+ super_publish_async(channel, item, callback)
29
29
  end
30
30
 
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)
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
- item = Item.new(http_stream, id, prev_id)
36
- super_publish(channel, item)
35
+ item = Item.new(http_stream, id, prev_id)
36
+ super_publish(channel, item)
37
37
  end
38
38
 
39
- def publish_http_stream_async(channel, http_stream, id=nil,
39
+ def publish_http_stream_async(channel, http_stream, id=nil,
40
40
  prev_id=nil, callback=nil)
41
- if http_stream.is_a?(String)
42
- http_stream = HttpStreamFormat.new(http_stream)
41
+ if http_stream.is_a?(String)
42
+ http_stream = HttpStreamFormat.new(http_stream)
43
43
  end
44
- item = Item.new(http_stream, id, prev_id)
45
- super_publish_async(channel, item, callback)
44
+ item = Item.new(http_stream, id, prev_id)
45
+ super_publish_async(channel, item, callback)
46
46
  end
47
47
  end
@@ -14,36 +14,36 @@ class HttpResponseFormat < Format
14
14
  attr_accessor :headers
15
15
  attr_accessor :body
16
16
 
17
- def initialize(code=nil, reason=nil, headers=nil, body=nil)
18
- @code = code
19
- @reason = reason
20
- @headers = headers
21
- @body = body
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
- def name
25
- return 'http-response'
24
+ def name
25
+ return 'http-response'
26
26
  end
27
27
 
28
- def export
29
- out = Hash.new
30
- if !@code.nil?
31
- out['code'] = @code
28
+ def export
29
+ out = Hash.new
30
+ if !@code.nil?
31
+ out['code'] = @code
32
32
  end
33
- if !@reason.nil?
34
- out['reason'] = @reason
33
+ if !@reason.nil?
34
+ out['reason'] = @reason
35
35
  end
36
- if !@headers.nil? and @headers.length > 0
37
- out['headers'] = @headers
36
+ if !@headers.nil? and @headers.length > 0
37
+ out['headers'] = @headers
38
38
  end
39
- if !@body.nil?
39
+ if !@body.nil?
40
40
  # REVIEW is this the right way to check for binary encoding?
41
- if @body.encoding.name == 'ASCII-8BIT'
42
- out['body-bin'] = Base64.encode64(@body)
43
- else
44
- out['body'] = @body
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
- return out
47
+ return out
48
48
  end
49
49
  end
@@ -12,30 +12,30 @@ class HttpStreamFormat < Format
12
12
  attr_accessor :content
13
13
  attr_accessor :close
14
14
 
15
- def initialize(content=nil, close=false)
16
- @content = content
17
- @close = close
18
- if !@close and @content.nil?
19
- raise 'Content not set'
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
- def name
24
- return 'http-stream'
23
+ def name
24
+ return 'http-stream'
25
25
  end
26
26
 
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
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
- return out
38
+ return out
39
39
  end
40
40
  end
41
41
 
@@ -9,8 +9,8 @@ class WebSocketEvent
9
9
  attr_accessor :type
10
10
  attr_accessor :content
11
11
 
12
- def initialize(type, content=nil)
13
- @type = type
14
- @content = content
12
+ def initialize(type, content=nil)
13
+ @type = type
14
+ @content = content
15
15
  end
16
16
  end
@@ -11,22 +11,22 @@ require 'pubcontrol'
11
11
  class WebSocketMessageFormat < Format
12
12
  attr_accessor :content
13
13
 
14
- def initialize(content)
15
- @content = content
14
+ def initialize(content)
15
+ @content = content
16
16
  end
17
17
 
18
- def name
19
- return 'ws-message'
18
+ def name
19
+ return 'ws-message'
20
20
  end
21
21
 
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
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
- return out
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.1
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: []