bixby-common 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -4
- data/Gemfile.lock +6 -10
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bixby-common.gemspec +7 -5
- data/lib/bixby-common/util/debug.rb +26 -0
- data/lib/bixby-common/util/log/logger.rb +21 -0
- data/lib/bixby-common/util/log.rb +3 -1
- data/lib/bixby-common/websocket/api_channel.rb +11 -8
- data/lib/bixby-common/websocket/async_response.rb +17 -3
- data/lib/bixby-common/websocket/message.rb +13 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d655ba4c5a8200586b435768668f60b2e0a6809e
|
4
|
+
data.tar.gz: 5e9d2be246830d38aef93bd079257052145d52e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ff9e4a9b966d0a40701ec04d8fcec8125b0d523126e6da6dcae414f5e72fc84b0a92d48e70b255e7f1c76723e45c1ea4f212cff4aa26f2e4f57c347e353b963
|
7
|
+
data.tar.gz: e53209d266c816916f4841a82f267494aaf3d115694eb730188d523697ab3280c450cb1a5458ffd5719b840ea6620dd4962acc67ee37c7c136ad3c8381587349
|
data/Gemfile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gem "faye-websocket"
|
4
|
-
gem "api-auth", :git => "https://github.com/chetan/api_auth.git", :branch => "bixby"
|
5
4
|
gem "multi_json"
|
6
|
-
gem "httpi"
|
7
|
-
:branch => "chunked_responses"
|
8
|
-
|
5
|
+
gem "httpi"
|
9
6
|
gem "logging"
|
10
7
|
|
8
|
+
gem "api-auth", :git => "https://github.com/chetan/api_auth.git", :branch => "bixby"
|
9
|
+
|
11
10
|
group :development do
|
12
11
|
gem "yard", "~> 0.8"
|
13
12
|
gem "bundler", "~> 1.1"
|
data/Gemfile.lock
CHANGED
@@ -5,17 +5,9 @@ GIT
|
|
5
5
|
specs:
|
6
6
|
api-auth (1.0.3)
|
7
7
|
|
8
|
-
GIT
|
9
|
-
remote: https://github.com/chetan/httpi.git
|
10
|
-
revision: f6e49303fee6778c714bcc556fa5f9247bc3a3f3
|
11
|
-
branch: chunked_responses
|
12
|
-
specs:
|
13
|
-
httpi (2.0.0)
|
14
|
-
rack
|
15
|
-
|
16
8
|
GIT
|
17
9
|
remote: https://github.com/chetan/jeweler.git
|
18
|
-
revision:
|
10
|
+
revision: c83ba18b074e82415052e80499a770bff87bf944
|
19
11
|
branch: bixby
|
20
12
|
specs:
|
21
13
|
jeweler (1.8.7)
|
@@ -98,6 +90,9 @@ GEM
|
|
98
90
|
hirb (0.7.1)
|
99
91
|
httpauth (0.2.0)
|
100
92
|
httpclient (2.3.4.1)
|
93
|
+
httpi (2.1.0)
|
94
|
+
rack
|
95
|
+
rubyntlm (~> 0.3.2)
|
101
96
|
jruby-openssl (0.8.8)
|
102
97
|
bouncy-castle-java (>= 1.5.0147)
|
103
98
|
json (1.8.0)
|
@@ -151,6 +146,7 @@ GEM
|
|
151
146
|
rcov (1.0.0)
|
152
147
|
rdoc (4.0.1)
|
153
148
|
json (~> 1.4)
|
149
|
+
rubyntlm (0.3.4)
|
154
150
|
safe_yaml (0.9.5)
|
155
151
|
simplecov-console (0.1.1)
|
156
152
|
colorize
|
@@ -182,7 +178,7 @@ DEPENDENCIES
|
|
182
178
|
curb
|
183
179
|
faye-websocket
|
184
180
|
httpclient
|
185
|
-
httpi
|
181
|
+
httpi
|
186
182
|
jeweler!
|
187
183
|
jruby-openssl
|
188
184
|
json
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/bixby-common.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bixby-common"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chetan Sarva"]
|
12
|
-
s.date = "2013-08-
|
12
|
+
s.date = "2013-08-29"
|
13
13
|
s.description = "Bixby Common files/libs"
|
14
14
|
s.email = "chetan@pixelcop.net"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
|
|
45
45
|
"lib/bixby-common/util/jsonify.rb",
|
46
46
|
"lib/bixby-common/util/log.rb",
|
47
47
|
"lib/bixby-common/util/log/filtering_layout.rb",
|
48
|
+
"lib/bixby-common/util/log/logger.rb",
|
48
49
|
"lib/bixby-common/websocket/api_channel.rb",
|
49
50
|
"lib/bixby-common/websocket/async_response.rb",
|
50
51
|
"lib/bixby-common/websocket/client.rb",
|
@@ -65,6 +66,7 @@ Gem::Specification.new do |s|
|
|
65
66
|
"test/util/log_test.rb"
|
66
67
|
]
|
67
68
|
s.homepage = "http://github.com/chetan/bixby-common"
|
69
|
+
s.licenses = ["MIT"]
|
68
70
|
s.require_paths = ["lib"]
|
69
71
|
s.rubygems_version = "2.0.3"
|
70
72
|
s.summary = "Bixby Common"
|
@@ -74,10 +76,10 @@ Gem::Specification.new do |s|
|
|
74
76
|
|
75
77
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
76
78
|
s.add_runtime_dependency(%q<faye-websocket>, [">= 0"])
|
77
|
-
s.add_runtime_dependency(%q<api-auth>, [">= 0"])
|
78
79
|
s.add_runtime_dependency(%q<multi_json>, [">= 0"])
|
79
80
|
s.add_runtime_dependency(%q<httpi>, [">= 0"])
|
80
81
|
s.add_runtime_dependency(%q<logging>, [">= 0"])
|
82
|
+
s.add_runtime_dependency(%q<api-auth>, [">= 0"])
|
81
83
|
s.add_development_dependency(%q<yard>, ["~> 0.8"])
|
82
84
|
s.add_development_dependency(%q<bundler>, ["~> 1.1"])
|
83
85
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
@@ -100,10 +102,10 @@ Gem::Specification.new do |s|
|
|
100
102
|
s.add_development_dependency(%q<jruby-openssl>, [">= 0"])
|
101
103
|
else
|
102
104
|
s.add_dependency(%q<faye-websocket>, [">= 0"])
|
103
|
-
s.add_dependency(%q<api-auth>, [">= 0"])
|
104
105
|
s.add_dependency(%q<multi_json>, [">= 0"])
|
105
106
|
s.add_dependency(%q<httpi>, [">= 0"])
|
106
107
|
s.add_dependency(%q<logging>, [">= 0"])
|
108
|
+
s.add_dependency(%q<api-auth>, [">= 0"])
|
107
109
|
s.add_dependency(%q<yard>, ["~> 0.8"])
|
108
110
|
s.add_dependency(%q<bundler>, ["~> 1.1"])
|
109
111
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
@@ -127,10 +129,10 @@ Gem::Specification.new do |s|
|
|
127
129
|
end
|
128
130
|
else
|
129
131
|
s.add_dependency(%q<faye-websocket>, [">= 0"])
|
130
|
-
s.add_dependency(%q<api-auth>, [">= 0"])
|
131
132
|
s.add_dependency(%q<multi_json>, [">= 0"])
|
132
133
|
s.add_dependency(%q<httpi>, [">= 0"])
|
133
134
|
s.add_dependency(%q<logging>, [">= 0"])
|
135
|
+
s.add_dependency(%q<api-auth>, [">= 0"])
|
134
136
|
s.add_dependency(%q<yard>, ["~> 0.8"])
|
135
137
|
s.add_dependency(%q<bundler>, ["~> 1.1"])
|
136
138
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
@@ -15,5 +15,31 @@ module Bixby
|
|
15
15
|
end
|
16
16
|
end # :nocov:
|
17
17
|
|
18
|
+
# Pretty print a hash
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# {
|
22
|
+
# content-md5 => "Rb0qo2Ae7KGcS5TDulOjYw==",
|
23
|
+
# date => "Thu, 29 Aug 2013 13:49:53 GMT",
|
24
|
+
# authorization => "APIAuth c61ca57b8d7b3e95fba06a",
|
25
|
+
# }
|
26
|
+
#
|
27
|
+
# @param [Hash] hash
|
28
|
+
# @return [String]
|
29
|
+
def self.pretty_hash(hash)
|
30
|
+
return "{}" if hash.empty?
|
31
|
+
|
32
|
+
s = [ "\n\t{" ]
|
33
|
+
l = hash.keys.max_by{ |k| k.length }.length + 1 # length of longest key so we can align values
|
34
|
+
hash.keys.each{ |k| s << (" %s%s=> %s," % [k, " "*(l-k.length), hash[k].inspect]) }
|
35
|
+
s << "}"
|
36
|
+
|
37
|
+
return s.join("\n\t")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.indent_lines(str, indent="\t")
|
41
|
+
str.gsub(/\n/, "\n#{indent}")
|
42
|
+
end
|
43
|
+
|
18
44
|
end # Debug
|
19
45
|
end # Bixby
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
# Patch Logging::Logger so that :trace becomes an inherited flag
|
3
|
+
|
4
|
+
module Logging
|
5
|
+
class Logger
|
6
|
+
|
7
|
+
# Override to pass trace flag from parent to child
|
8
|
+
def initialize( name )
|
9
|
+
case name
|
10
|
+
when String
|
11
|
+
raise(ArgumentError, "logger must have a name") if name.empty?
|
12
|
+
else raise(ArgumentError, "logger name must be a String") end
|
13
|
+
|
14
|
+
repo = ::Logging::Repository.instance
|
15
|
+
parent = repo.parent(name)
|
16
|
+
_setup(name, :parent => parent, :trace => parent.trace)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require "logging"
|
3
3
|
|
4
4
|
require "bixby-common/util/log/filtering_layout"
|
5
|
+
require "bixby-common/util/log/logger"
|
5
6
|
|
6
7
|
module Bixby
|
7
8
|
|
@@ -40,7 +41,7 @@ module Bixby
|
|
40
41
|
opts[:level] = :debug if ENV["BIXBY_DEBUG"]
|
41
42
|
opts[:level] ||= :warn
|
42
43
|
|
43
|
-
pattern = opts.delete(:pattern) || '%.1l, [%d] %5l -- %c: %m\n'
|
44
|
+
pattern = opts.delete(:pattern) || '%.1l, [%d] %5l -- %c:%L: %m\n'
|
44
45
|
layout = Logging.layouts.pattern(:pattern => pattern)
|
45
46
|
|
46
47
|
opts[:filename] ||= Bixby.path("var", "bixby-agent.log")
|
@@ -79,6 +80,7 @@ module Bixby
|
|
79
80
|
|
80
81
|
Logging::Logger.root.add_appenders("file")
|
81
82
|
Logging::Logger.root.level = opts[:level]
|
83
|
+
Logging::Logger.root.trace = true
|
82
84
|
end
|
83
85
|
|
84
86
|
end # Log
|
@@ -36,10 +36,12 @@ module Bixby
|
|
36
36
|
# @param [JsonRequest] json_request
|
37
37
|
#
|
38
38
|
# @return [String] request id
|
39
|
-
def execute_async(json_request)
|
39
|
+
def execute_async(json_request, &block)
|
40
|
+
logger.debug { "execute_async:\n#{json_request.to_s}" }
|
41
|
+
|
40
42
|
request = Request.new(json_request)
|
41
43
|
id = request.id
|
42
|
-
@responses[id] = AsyncResponse.new(id)
|
44
|
+
@responses[id] = AsyncResponse.new(id, &block)
|
43
45
|
|
44
46
|
EM.next_tick {
|
45
47
|
ws.send(request.to_wire)
|
@@ -67,8 +69,6 @@ module Bixby
|
|
67
69
|
|
68
70
|
# Open
|
69
71
|
def open(event)
|
70
|
-
# TODO extract Agent ID, if Agent
|
71
|
-
logger.debug "new channel opened"
|
72
72
|
@connected = true
|
73
73
|
end
|
74
74
|
|
@@ -77,7 +77,6 @@ module Bixby
|
|
77
77
|
# Can be fired either due to disconnection or failure to connect
|
78
78
|
def close(event)
|
79
79
|
if @connected then
|
80
|
-
logger.debug "client disconnected"
|
81
80
|
@connected = false
|
82
81
|
@handler.new(nil).disconnect(self)
|
83
82
|
end
|
@@ -87,12 +86,14 @@ module Bixby
|
|
87
86
|
#
|
88
87
|
# Fired whenever a message is received on the channel
|
89
88
|
def message(event)
|
90
|
-
logger.debug "got a message:\n#{event.data}"
|
91
89
|
req = Message.from_wire(event.data)
|
90
|
+
logger.debug { "new '#{req.type}' message" }
|
92
91
|
|
93
92
|
if req.type == "rpc" then
|
94
93
|
# Execute the requested method and return the result
|
95
|
-
|
94
|
+
json_req = req.json_request
|
95
|
+
logger.debug { json_req.to_s }
|
96
|
+
json_response = @handler.new(req).handle(json_req)
|
96
97
|
|
97
98
|
# result = { :type => "rpc_result", :id => req.id, :data => json_response }
|
98
99
|
# ws.send(MultiJson.dump(result))
|
@@ -100,7 +101,9 @@ module Bixby
|
|
100
101
|
|
101
102
|
elsif req.type == "rpc_result" then
|
102
103
|
# Pass the result back to the caller
|
103
|
-
|
104
|
+
res = req.json_response
|
105
|
+
logger.debug { res.to_s }
|
106
|
+
@responses[req.id].response = res
|
104
107
|
|
105
108
|
elsif req.type == "connect" then
|
106
109
|
@handler.new(req).connect(req.json_request, self)
|
@@ -4,20 +4,30 @@ require 'thread'
|
|
4
4
|
module Bixby
|
5
5
|
module WebSocket
|
6
6
|
|
7
|
-
# Asynchronously receive a response via
|
7
|
+
# Asynchronously receive a response via some channel
|
8
8
|
class AsyncResponse
|
9
9
|
|
10
10
|
attr_reader :id
|
11
11
|
|
12
|
-
|
12
|
+
# Create a new AsyncResponse. Optionally pass a callback block which will
|
13
|
+
# be fired when the response is set.
|
14
|
+
#
|
15
|
+
# @param [String] id
|
16
|
+
#
|
17
|
+
# @yieldparam [JsonResponse] response
|
18
|
+
#
|
19
|
+
# @return [AsyncResponse]
|
20
|
+
def initialize(id, &block)
|
13
21
|
@id = id
|
22
|
+
@block = block
|
14
23
|
@mutex = Mutex.new
|
15
24
|
@cond = ConditionVariable.new
|
16
25
|
@response = nil
|
17
26
|
@completed = false
|
18
27
|
end
|
19
28
|
|
20
|
-
# Set the response and signal any blocking threads
|
29
|
+
# Set the response and signal any blocking threads. Triggers callback, if
|
30
|
+
# one was set.
|
21
31
|
#
|
22
32
|
# @param [Object] obj result of request, usually a JsonResponse
|
23
33
|
def response=(obj)
|
@@ -26,6 +36,10 @@ module Bixby
|
|
26
36
|
@response = obj
|
27
37
|
@cond.signal
|
28
38
|
}
|
39
|
+
|
40
|
+
if not @block.nil? then
|
41
|
+
@block.call(@response)
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
# Has the request completed?
|
@@ -42,6 +42,19 @@ module Bixby
|
|
42
42
|
@body
|
43
43
|
end
|
44
44
|
|
45
|
+
# Convert object to String, useful for debugging
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
def to_s # :nocov:
|
49
|
+
s = []
|
50
|
+
s << "#{self.class}:#{self.object_id}"
|
51
|
+
s << " id: #{self.id}"
|
52
|
+
s << " type: #{self.type}"
|
53
|
+
s << " headers: " + Debug.pretty_hash(self.headers)
|
54
|
+
s << " body: " + Debug.pretty_hash(MultiJson.load(self.body))
|
55
|
+
s.join("\n")
|
56
|
+
end # :nocov:
|
57
|
+
|
45
58
|
end
|
46
59
|
|
47
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bixby-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chetan Sarva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: httpi
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: logging
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: api-auth
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '>='
|
@@ -396,6 +396,7 @@ files:
|
|
396
396
|
- lib/bixby-common/util/jsonify.rb
|
397
397
|
- lib/bixby-common/util/log.rb
|
398
398
|
- lib/bixby-common/util/log/filtering_layout.rb
|
399
|
+
- lib/bixby-common/util/log/logger.rb
|
399
400
|
- lib/bixby-common/websocket/api_channel.rb
|
400
401
|
- lib/bixby-common/websocket/async_response.rb
|
401
402
|
- lib/bixby-common/websocket/client.rb
|
@@ -415,7 +416,8 @@ files:
|
|
415
416
|
- test/util/jsonify_test.rb
|
416
417
|
- test/util/log_test.rb
|
417
418
|
homepage: http://github.com/chetan/bixby-common
|
418
|
-
licenses:
|
419
|
+
licenses:
|
420
|
+
- MIT
|
419
421
|
metadata: {}
|
420
422
|
post_install_message:
|
421
423
|
rdoc_options: []
|