silkroad 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/lib/silkroad/client.rb +24 -11
- data/lib/silkroad/version.rb +1 -1
- data/lib/silkroad.rb +2 -2
- data/silkroad.gemspec +0 -3
- data/test/client_test.rb +4 -4
- metadata +3 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12295a48d43500089e274ee57200ae3b69ee25a2
|
4
|
+
data.tar.gz: 7ccc5dd46d366fffe5b902568b265fcb3686408b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2ebedd62b7a978d9e7b285c9278c66b8d26a62fb90c78fc0ec2cd66271a27dd4a7351c3de92cef8ee3b8f34f1c5e80a4a348f98ef0ebc064e380c731607e12e
|
7
|
+
data.tar.gz: 122479eae9b1b55f1e2a9d75d34ce24f23695d6f6ed30cb698c53e7cc3c672bed0a975f5d93ba230e430a39256c9e4e2bd7e30135e778e040dff3c084d2ae631
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -29,7 +29,7 @@ You can set a custom url:
|
|
29
29
|
silkroad = Silkroad::Client.new 'rpcuser', 'rpcpass', url: 'https://yourbitcoinddaemon.com:31337'
|
30
30
|
```
|
31
31
|
|
32
|
-
Now you can make RPC API calls (see the [API calls list](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list)). Pass params as per the spec, and the result will be returned as
|
32
|
+
Now you can make RPC API calls (see the [API calls list](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list)). Pass params as per the spec, and the result will be returned as a primitive type (string, number, boolean, and nil) or structured type (hash, array), depending on the call:
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
silkroad.rpc 'getbalance', 'derp@example.com' # => 31337
|
data/lib/silkroad/client.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module Silkroad
|
2
2
|
class Client
|
3
3
|
class Error < StandardError; end
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
DEFAULT_RPC_PORT = 8332
|
6
|
+
TESTNET_RPC_PORT = 18332
|
7
|
+
JSONRPC_VERSION = '2.0'
|
6
8
|
|
7
9
|
def initialize(user, pass, opts={})
|
8
10
|
@user = user
|
9
11
|
@opts = opts
|
10
|
-
@
|
11
|
-
@
|
12
|
-
|
13
|
-
@
|
14
|
-
@http_client.set_auth @url.to_s, user, pass
|
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
|
15
16
|
end
|
16
17
|
|
17
18
|
def batch(requests=nil, &block)
|
@@ -23,7 +24,7 @@ module Silkroad
|
|
23
24
|
def rpc(meth, *params)
|
24
25
|
response = send jsonrpc: JSONRPC_VERSION, method: meth, params: params
|
25
26
|
|
26
|
-
if response.
|
27
|
+
if response.code != '200'
|
27
28
|
if response.body.nil?
|
28
29
|
raise Error.new "bitcoind returned HTTP status #{response.status} with no body: #{response.http_header.reason_phrase}"
|
29
30
|
else
|
@@ -35,12 +36,24 @@ module Silkroad
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
def send(
|
39
|
-
@
|
39
|
+
def send(formdata)
|
40
|
+
resp = Net::HTTP.start(@uri.host, @uri.port) do |http|
|
41
|
+
req = Net::HTTP::Post.new '/'
|
42
|
+
req.basic_auth @user, @pass
|
43
|
+
req.add_field 'Content-Type', 'application/json'
|
44
|
+
req.use_ssl = true if @uri.scheme == 'https'
|
45
|
+
req.body = formdata.to_json
|
46
|
+
http.request req
|
47
|
+
end
|
48
|
+
|
49
|
+
if resp.code == '403' && resp.body.empty?
|
50
|
+
raise Error, '403 Forbidden - check your user/pass and/or uri, and ensure IP is whitelisted for remote connections'
|
51
|
+
end
|
52
|
+
resp
|
40
53
|
end
|
41
54
|
|
42
55
|
def inspect
|
43
|
-
"#<#{self.class} user=\"#{@user}\" @
|
56
|
+
"#<#{self.class} user=\"#{@user}\" @uri=\"#{@uri.to_s}\">"
|
44
57
|
end
|
45
58
|
end
|
46
59
|
end
|
data/lib/silkroad/version.rb
CHANGED
data/lib/silkroad.rb
CHANGED
data/silkroad.gemspec
CHANGED
@@ -18,9 +18,6 @@ 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_dependency "addressable"
|
22
|
-
spec.add_dependency "httpclient"
|
23
|
-
|
24
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
22
|
spec.add_development_dependency "rake"
|
26
23
|
spec.add_development_dependency "minitest"
|
data/test/client_test.rb
CHANGED
@@ -11,14 +11,14 @@ end
|
|
11
11
|
|
12
12
|
def stub_with_body(body, response)
|
13
13
|
stub_request(:post, url).
|
14
|
-
|
15
|
-
|
16
|
-
to_return(response)
|
14
|
+
with(body: body, headers: {'Content-Type'=>'application/json'}).
|
15
|
+
to_return(response)
|
17
16
|
end
|
18
17
|
|
19
18
|
describe Silkroad::Client do
|
20
19
|
before do
|
21
20
|
@silkroad = Silkroad::Client.new('user', 'pass')
|
21
|
+
WebMock.reset!
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'makes a call' do
|
@@ -44,7 +44,7 @@ describe Silkroad::Client do
|
|
44
44
|
{method: 'getbalance', params: ['tyler@example.com'], jsonrpc: '2.0'},
|
45
45
|
{method: 'notworking', params: ['derp'], jsonrpc: '2.0'}
|
46
46
|
].to_json,
|
47
|
-
headers: {'
|
47
|
+
headers: {'Content-Type'=>'application/json'}).
|
48
48
|
to_return(
|
49
49
|
:body => [
|
50
50
|
{result: 31337, error: nil, id: nil},
|
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: silkroad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: addressable
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: httpclient
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: bundler
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
119
|
version: '0'
|
148
120
|
requirements: []
|
149
121
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.0.
|
122
|
+
rubygems_version: 2.0.3
|
151
123
|
signing_key:
|
152
124
|
specification_version: 4
|
153
125
|
summary: A fast, thread-safe, simple, lightweight, batchable, sober interface to the
|