silkroad 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/silkroad/client.rb +8 -9
- data/lib/silkroad/version.rb +1 -1
- data/test/client_test.rb +12 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 418db557c865c75cb14484e2abf1774a352d9adb
|
4
|
+
data.tar.gz: 94db88ee449808a5298e04422f0ca3c4bede9250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f3155bc47b4dfaf5cf0629ec36b6ed61226c3886a6d271335d77f12b2125da708c589ebb46481f17c1638a6a59e4c31b2e3cace29617ca9e39871e099d2afee
|
7
|
+
data.tar.gz: 2c96cf231a68dd4d17e10a46b0eabe55d59a68c4273d885726a15775cd0fc667e18b487e39a84161668ee88c89db1e218a9eebf35ace04c127c38fee9c2291a0
|
data/lib/silkroad/client.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Silkroad
|
2
2
|
class Client
|
3
3
|
class Error < StandardError; end
|
4
|
+
attr_reader :uri
|
4
5
|
|
5
6
|
DEFAULT_RPC_PORT = 8332
|
6
7
|
TESTNET_RPC_PORT = 18332
|
7
8
|
JSONRPC_VERSION = '2.0'
|
8
9
|
|
9
|
-
def initialize(
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@uri
|
13
|
-
@uri.port
|
14
|
-
@user = user
|
15
|
-
@pass = pass
|
10
|
+
def initialize(uri, opts={})
|
11
|
+
@opts = opts
|
12
|
+
@uri = URI uri
|
13
|
+
raise Error, 'user and password required' unless @uri.user && @uri.password
|
14
|
+
@uri.port = DEFAULT_RPC_PORT if @uri.port.nil? || (@uri.port == 80 && !uri.match(/:80/))
|
16
15
|
end
|
17
16
|
|
18
17
|
def batch(requests=nil, &block)
|
@@ -39,7 +38,7 @@ module Silkroad
|
|
39
38
|
def send(formdata)
|
40
39
|
resp = Net::HTTP.start(@uri.host, @uri.port) do |http|
|
41
40
|
req = Net::HTTP::Post.new '/'
|
42
|
-
req.basic_auth @user, @
|
41
|
+
req.basic_auth @uri.user, @uri.password
|
43
42
|
req.add_field 'Content-Type', 'application/json'
|
44
43
|
req.use_ssl = true if @uri.scheme == 'https'
|
45
44
|
req.body = formdata.to_json
|
@@ -56,4 +55,4 @@ module Silkroad
|
|
56
55
|
"#<#{self.class} user=\"#{@user}\" @uri=\"#{@uri.to_s}\">"
|
57
56
|
end
|
58
57
|
end
|
59
|
-
end
|
58
|
+
end
|
data/lib/silkroad/version.rb
CHANGED
data/test/client_test.rb
CHANGED
@@ -17,10 +17,21 @@ end
|
|
17
17
|
|
18
18
|
describe Silkroad::Client do
|
19
19
|
before do
|
20
|
-
@silkroad = Silkroad::Client.new
|
20
|
+
@silkroad = Silkroad::Client.new 'http://user:pass@localhost'
|
21
21
|
WebMock.reset!
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'sets url defaults correctly' do
|
25
|
+
Proc.new { Silkroad::Client.new 'http://localhost' }.must_raise Silkroad::Client::Error
|
26
|
+
|
27
|
+
|
28
|
+
silkroad = Silkroad::Client.new 'http://user:pass@localhost'
|
29
|
+
silkroad.uri.to_s.must_equal 'http://user:pass@localhost:8332'
|
30
|
+
|
31
|
+
silkroad = Silkroad::Client.new 'https://user:pass@example.org:1234'
|
32
|
+
silkroad.uri.to_s.must_equal 'https://user:pass@example.org:1234'
|
33
|
+
end
|
34
|
+
|
24
35
|
it 'makes a call' do
|
25
36
|
stub_with_body(
|
26
37
|
{jsonrpc: "2.0", method: "getbalance", params: ["tyler@example.com"]},
|