silkroad 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12295a48d43500089e274ee57200ae3b69ee25a2
4
- data.tar.gz: 7ccc5dd46d366fffe5b902568b265fcb3686408b
3
+ metadata.gz: 418db557c865c75cb14484e2abf1774a352d9adb
4
+ data.tar.gz: 94db88ee449808a5298e04422f0ca3c4bede9250
5
5
  SHA512:
6
- metadata.gz: d2ebedd62b7a978d9e7b285c9278c66b8d26a62fb90c78fc0ec2cd66271a27dd4a7351c3de92cef8ee3b8f34f1c5e80a4a348f98ef0ebc064e380c731607e12e
7
- data.tar.gz: 122479eae9b1b55f1e2a9d75d34ce24f23695d6f6ed30cb698c53e7cc3c672bed0a975f5d93ba230e430a39256c9e4e2bd7e30135e778e040dff3c084d2ae631
6
+ metadata.gz: 4f3155bc47b4dfaf5cf0629ec36b6ed61226c3886a6d271335d77f12b2125da708c589ebb46481f17c1638a6a59e4c31b2e3cace29617ca9e39871e099d2afee
7
+ data.tar.gz: 2c96cf231a68dd4d17e10a46b0eabe55d59a68c4273d885726a15775cd0fc667e18b487e39a84161668ee88c89db1e218a9eebf35ace04c127c38fee9c2291a0
@@ -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(user, pass, opts={})
10
- @user = user
11
- @opts = opts
12
- @uri = URI.parse @opts[:url] || "http://localhost:#{DEFAULT_RPC_PORT}"
13
- @uri.port = DEFAULT_RPC_PORT if @opts[:url].nil? || !@opts[:url].match(/:80/)
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, @pass
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
@@ -1,3 +1,3 @@
1
1
  module Silkroad
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
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('user', 'pass')
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"]},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silkroad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Drake