silkroad 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: 418db557c865c75cb14484e2abf1774a352d9adb
4
- data.tar.gz: 94db88ee449808a5298e04422f0ca3c4bede9250
2
+ SHA256:
3
+ metadata.gz: c1a6b37fb9a99b76044b3d0929be27188bf0e9ed46890ad8bd2eb5c6197b9504
4
+ data.tar.gz: fff1515809b4a8e7c3006cabdb937b4c8a28dd886e463c6097db225d522f82c8
5
5
  SHA512:
6
- metadata.gz: 4f3155bc47b4dfaf5cf0629ec36b6ed61226c3886a6d271335d77f12b2125da708c589ebb46481f17c1638a6a59e4c31b2e3cace29617ca9e39871e099d2afee
7
- data.tar.gz: 2c96cf231a68dd4d17e10a46b0eabe55d59a68c4273d885726a15775cd0fc667e18b487e39a84161668ee88c89db1e218a9eebf35ace04c127c38fee9c2291a0
6
+ metadata.gz: 67e1ea9a7165af2f822b7ea40fe4c83ac1781f0b19ac7e9469f3b9ae8ec4775d39c3dd93549c02fbeddb638fb16405a89ce47dbacfd8878000dde02f67c828f0
7
+ data.tar.gz: e4fa7699c5aa35bbc46a100afafec6f63629b6abb94f97d174b10807369090cbdc66bdc5c7508fae29fe8b23fe5c35ffea08043ea237d111d35923d2b3630a75
@@ -4,11 +4,11 @@ module Silkroad
4
4
 
5
5
  def initialize(&block)
6
6
  @requests = []
7
- instance_eval &block
7
+ instance_eval(&block)
8
8
  end
9
9
 
10
10
  def rpc(meth, *params)
11
11
  @requests << {method: meth, params: params}
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -36,11 +36,13 @@ module Silkroad
36
36
  end
37
37
 
38
38
  def send(formdata)
39
- resp = Net::HTTP.start(@uri.host, @uri.port) do |http|
39
+ http = Net::HTTP.new(@uri.host, @uri.port)
40
+ http.use_ssl = true if @uri.scheme == 'https'
41
+
42
+ resp = http.start do
40
43
  req = Net::HTTP::Post.new '/'
41
44
  req.basic_auth @uri.user, @uri.password
42
45
  req.add_field 'Content-Type', 'application/json'
43
- req.use_ssl = true if @uri.scheme == 'https'
44
46
  req.body = formdata.to_json
45
47
  http.request req
46
48
  end
@@ -1,3 +1,3 @@
1
1
  module Silkroad
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/silkroad.gemspec CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest"
24
24
  spec.add_development_dependency "webmock"
25
25
  spec.add_development_dependency "yard"
26
- end
26
+ end
data/test/client_test.rb CHANGED
@@ -2,16 +2,24 @@
2
2
  require 'rubygems'
3
3
  require './lib/silkroad.rb'
4
4
  require 'minitest/autorun'
5
- require 'webmock'
5
+ require 'webmock/minitest'
6
6
  include WebMock::API
7
+ WebMock.disable_net_connect!
7
8
 
8
- def url
9
- 'http://user:pass@localhost:8332/'
9
+ def http_uri
10
+ 'http://localhost:8332/'
10
11
  end
11
12
 
12
- def stub_with_body(body, response)
13
- stub_request(:post, url).
14
- with(body: body, headers: {'Content-Type'=>'application/json'}).
13
+ def https_uri
14
+ 'https://localhost:8332/'
15
+ end
16
+
17
+ def stub_with_body(body, response, use_ssl=false)
18
+ stub_request(:post, (use_ssl ? https_uri : http_uri)).
19
+ with(body: body, headers: {
20
+ 'Content-Type' =>'application/json',
21
+ 'Authorization' =>'Basic dXNlcjpwYXNz'
22
+ }).
15
23
  to_return(response)
16
24
  end
17
25
 
@@ -23,8 +31,7 @@ describe Silkroad::Client do
23
31
 
24
32
  it 'sets url defaults correctly' do
25
33
  Proc.new { Silkroad::Client.new 'http://localhost' }.must_raise Silkroad::Client::Error
26
-
27
-
34
+
28
35
  silkroad = Silkroad::Client.new 'http://user:pass@localhost'
29
36
  silkroad.uri.to_s.must_equal 'http://user:pass@localhost:8332'
30
37
 
@@ -41,6 +48,17 @@ describe Silkroad::Client do
41
48
  @silkroad.rpc('getbalance', 'tyler@example.com').must_equal 31337
42
49
  end
43
50
 
51
+ it 'works with ssl' do
52
+ stub_with_body(
53
+ {jsonrpc: "2.0", method: "getbalance", params: ["tyler@example.com"]},
54
+ {status: 200, body: {result: 31337}.to_json},
55
+ true
56
+ )
57
+
58
+ silkroad = Silkroad::Client.new 'https://user:pass@localhost:8332'
59
+ silkroad.rpc('getbalance', 'tyler@example.com').must_equal 31337
60
+ end
61
+
44
62
  it 'fails with error' do
45
63
  stub_with_body(
46
64
  {jsonrpc: "2.0", method: "failbalance", params: ["tyler@example.com"]},
@@ -49,7 +67,7 @@ describe Silkroad::Client do
49
67
  end
50
68
 
51
69
  it 'makes a batch call' do
52
- stub_request(:post, url).
70
+ stub_request(:post, http_uri).
53
71
  with(
54
72
  body: [
55
73
  {method: 'getbalance', params: ['tyler@example.com'], jsonrpc: '2.0'},
@@ -72,4 +90,4 @@ describe Silkroad::Client do
72
90
  response.first['result'].must_equal 31337
73
91
  response.last['error']['message'].must_equal 'Method not found'
74
92
  end
75
- end
93
+ end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silkroad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Drake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-13 00:00:00.000000000 Z
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: A fast, thread-safe, simple, lightweight, batchable, sober interface
@@ -88,7 +88,7 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
91
+ - ".gitignore"
92
92
  - Gemfile
93
93
  - LICENSE.txt
94
94
  - README.md
@@ -109,21 +109,19 @@ require_paths:
109
109
  - lib
110
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - '>='
112
+ - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - '>='
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.0.3
121
+ rubygems_version: 3.0.3
123
122
  signing_key:
124
123
  specification_version: 4
125
124
  summary: A fast, thread-safe, simple, lightweight, batchable, sober interface to the
126
125
  bitcoind JSON-RPC api. Uses HTTPClient for high performance (http://bibwild.wordpress.com/2012/04/30/ruby-http-performance-shootout-redux).
127
126
  test_files:
128
127
  - test/client_test.rb
129
- has_rdoc: