electrb 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/electrb.rb +26 -1
- data/lib/electrb/client.rb +2 -8
- data/lib/electrb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dbcef324297f3e9533e9318322ba40c22e0383b60fde6bb3ae936c48e5d0bad
|
4
|
+
data.tar.gz: c7e0d512fc49f54920568ab47a7711cb7e1bab7c17982342bca9dc319b36daa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8a93b2cf4bee164eb5abaca891aab3bd9c961cabf14b839dc75ed2bb2e41685a404b3a51c3f53bff60a194a775857c46149c63a9c59419b8f041d12edb9732b
|
7
|
+
data.tar.gz: dfdd114d4cbb7d0a01cb84b700d37fca92661489df93a4ebe26a3dd3f6e909678fccee466abdc41ffffe9db270456cc2f737ad50333c07a5ca03bf5dd44c1122
|
data/lib/electrb.rb
CHANGED
@@ -1,8 +1,33 @@
|
|
1
1
|
require "electrb/version"
|
2
|
+
require 'jsonrpctcp'
|
2
3
|
|
3
4
|
module Electrb
|
4
|
-
|
5
|
+
|
6
|
+
class Error < StandardError
|
7
|
+
|
8
|
+
attr_accessor :id
|
9
|
+
attr_accessor :jsonrpc
|
10
|
+
|
11
|
+
# generate error form hash.
|
12
|
+
# @param [Hash] hash hash of error.
|
13
|
+
# @return [Electrb::Error]
|
14
|
+
def self.from(hash)
|
15
|
+
e = Electrb::Error.new(hash['error'])
|
16
|
+
e.id = hash['id']
|
17
|
+
e.jsonrpc = hash['jsonrpc']
|
18
|
+
e
|
19
|
+
end
|
20
|
+
end
|
5
21
|
|
6
22
|
autoload :Client, 'electrb/client'
|
7
23
|
|
24
|
+
|
25
|
+
class ::Jsonrpctcp::RPCError
|
26
|
+
|
27
|
+
def self.from_rpc_response(r)
|
28
|
+
Electrb::Error.from(r)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
8
33
|
end
|
data/lib/electrb/client.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'jsonrpctcp'
|
2
|
-
|
3
1
|
module Electrb
|
4
2
|
|
5
3
|
class Client
|
@@ -18,12 +16,8 @@ module Electrb
|
|
18
16
|
|
19
17
|
def send_request(method, *args)
|
20
18
|
method_name = method.to_s.gsub(/_/, '.')
|
21
|
-
|
22
|
-
|
23
|
-
response['result']
|
24
|
-
rescue Jsonrpctcp::RPCError => e
|
25
|
-
raise Electrb::Error, e.message
|
26
|
-
end
|
19
|
+
response = client.send(method_name, *args)
|
20
|
+
response['result']
|
27
21
|
end
|
28
22
|
|
29
23
|
end
|
data/lib/electrb/version.rb
CHANGED