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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5050de75e2288298be54325a2ff9428d98c9cde
4
- data.tar.gz: cf687338313a99fa297a2a5d532f67e66280bb00
3
+ metadata.gz: 12295a48d43500089e274ee57200ae3b69ee25a2
4
+ data.tar.gz: 7ccc5dd46d366fffe5b902568b265fcb3686408b
5
5
  SHA512:
6
- metadata.gz: aa2924a294708adde8b1e45fb25011d318d0af511b3633a61ab74d1750c30f80b067a7482233c620000a5ebf80244270933aaaa43adb40266b1fd6e8348ffffc
7
- data.tar.gz: aac2a971cfd4e06d27fe4b0b6cd821053ba8230921c6bc1254a6c9ed038c36a96a080c803b72a80b44266c1e8a7ba2712d7b1b61de84dad13b9ff3a14dddf300
6
+ metadata.gz: d2ebedd62b7a978d9e7b285c9278c66b8d26a62fb90c78fc0ec2cd66271a27dd4a7351c3de92cef8ee3b8f34f1c5e80a4a348f98ef0ebc064e380c731607e12e
7
+ data.tar.gz: 122479eae9b1b55f1e2a9d75d34ce24f23695d6f6ed30cb698c53e7cc3c672bed0a975f5d93ba230e430a39256c9e4e2bd7e30135e778e040dff3c084d2ae631
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in silkroad.gemspec
4
4
  gemspec
5
+ gem 'pry'
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 an array or hash (depending on the call):
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
@@ -1,17 +1,18 @@
1
1
  module Silkroad
2
2
  class Client
3
3
  class Error < StandardError; end
4
- DEFAULT_PORT = 8332
5
- JSONRPC_VERSION = '2.0'
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
- @url = Addressable::URI.parse @opts[:url] || "http://localhost:#{DEFAULT_PORT}"
11
- @url.port = DEFAULT_PORT if @url.port.nil?
12
-
13
- @http_client = HTTPClient.new
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.status != 200
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(request)
39
- @http_client.post @url, request.to_json, {'Content-Type' => 'application/json'}
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}\" @url=\"#{@url.to_s}\">"
56
+ "#<#{self.class} user=\"#{@user}\" @uri=\"#{@uri.to_s}\">"
44
57
  end
45
58
  end
46
59
  end
@@ -1,3 +1,3 @@
1
1
  module Silkroad
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/silkroad.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "httpclient"
2
- require "addressable/uri"
1
+ require "uri"
2
+ require "net/http"
3
3
  require "json"
4
4
  require "silkroad/batch"
5
5
  require "silkroad/client"
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
- with(body: body,
15
- headers: {'Authorization'=>'Basic dXNlcjpwYXNz'}).
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: {'Authorization'=>'Basic dXNlcjpwYXNz', 'Content-Type'=>'application/json'}).
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.1
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-05-15 00:00:00.000000000 Z
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.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