startcoin-client 0.0.3 → 0.0.4
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 +4 -4
- data/.gitignore +1 -0
- data/README.rdoc +18 -33
- data/lib/startcoin_client/api.rb +4 -1
- data/lib/startcoin_client/client.rb +2 -0
- data/lib/startcoin_client/dsl.rb +8 -0
- data/lib/startcoin_client/rpc.rb +10 -2
- data/lib/startcoin_client/version.rb +1 -1
- data/spec/lib/startcoin_client/api_spec.rb +11 -3
- data/spec/lib/startcoin_client/client_spec.rb +1 -0
- data/startcoin-client.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bde3485c1c709cfb9529a751a981ec6dc265d76c
|
4
|
+
data.tar.gz: bb4bca71ededf287c427be0a0a896340782b1979
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ccde8a5828afdbff9ec9acf486ec86dbc0f5d46a225cf06a71b51354276a78df51d2d3bb3c5d8afc9a952a55aec5697af0568b03ed1e34cbc50275937733a5
|
7
|
+
data.tar.gz: 07d0ff28b67a6748304bf9557f8865ea7ef680b82d815192df59c776401ff208ea47eeb8b51061100d4ec53334443ecf0a9fdd4a9d0680da40808a44e795c6ad
|
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -6,19 +6,17 @@ Also supports customizing the host and port number to connect to.
|
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
|
9
|
-
|
9
|
+
To install gem just add this entry to your Gemfile
|
10
10
|
|
11
|
-
gem
|
11
|
+
gem 'startcoin-client'
|
12
|
+
gem 'json', '~> 1.5.3' # For Ruby < 1.9
|
12
13
|
|
13
|
-
Or, if you're using Bundler (and you should be), just add it to the Gemfile:
|
14
|
-
|
15
|
-
gem 'json', '~> 1.5.3'
|
16
14
|
|
17
15
|
== Usage
|
18
16
|
|
19
17
|
As with most Ruby gems, you first need to require the library into your project:
|
20
18
|
|
21
|
-
require '
|
19
|
+
require 'startcoin_client'
|
22
20
|
|
23
21
|
After doing this, the simplest possible usage looks like this:
|
24
22
|
|
@@ -32,47 +30,34 @@ same task:
|
|
32
30
|
client.balance
|
33
31
|
# => 0.001
|
34
32
|
|
35
|
-
The third and final way to use the library is by taking advantage of a simple DSL:
|
36
|
-
|
37
|
-
include StartcoinClient
|
38
|
-
|
39
|
-
# set up credentials
|
40
|
-
username 'username'
|
41
|
-
password 'password'
|
42
|
-
|
43
|
-
balance
|
44
|
-
# => 0.001
|
45
|
-
|
46
|
-
accounts
|
47
|
-
# => {"account" => 0.001}
|
48
|
-
|
49
33
|
The RPC method names available to you are exactly the same as those listed on the Startcoin wiki
|
50
34
|
(again, that's {https://en.bitcoin.it/wiki/Original_Startcoin_client/API_Calls_list}[https://en.bitcoin.it/wiki/Original_Startcoin_client/API_Calls_list]). Some aliases
|
51
35
|
have been added to make them more "ruby-ish," but none of the original names have been changed.
|
52
36
|
|
37
|
+
== Host, Port, SSL, Proxy
|
53
38
|
|
54
|
-
|
39
|
+
Here are several examples of how you can change the host and proxy information:
|
55
40
|
|
56
|
-
|
57
|
-
|
58
|
-
StartcoinClient('username', 'password', :host => 'example.com', :port => 38332, :ssl => true)
|
41
|
+
StartcoinClient('username', 'password', :host => 'example.com', :port => 38332, :ssl => true, :proxy => 'http://someproxy.com')
|
59
42
|
|
60
43
|
client = StartcoinClient::Client.new('username', 'password', :host => 'example.com')
|
61
44
|
client.port = 38332
|
45
|
+
client.proxy = 'http://someproxy.com'
|
62
46
|
client.ssl = true
|
63
47
|
client.ssl?
|
64
48
|
# => true
|
65
49
|
|
66
|
-
include StartcoinClient
|
67
|
-
host 'example.com'
|
68
|
-
port 38332
|
69
|
-
ssl?
|
70
|
-
# => false
|
71
|
-
ssl true
|
72
|
-
ssl?
|
73
|
-
# => true
|
74
|
-
|
75
50
|
You should see the StartcoinClient::Client class documentation if you'd like to see the other options and methods
|
76
51
|
that are made available.
|
77
52
|
|
53
|
+
== Test environment
|
54
|
+
|
55
|
+
It's highly recommended to not connect StartcoinClient to live network, but instead use local testnet. One possibility is to use docker image called **bitcoin-testnet-box** (https://github.com/freewil/bitcoin-testnet-box). For installation process please follow instructions on its wiki page.
|
56
|
+
|
57
|
+
After successful instalation you can connect to wallets with following commands
|
58
|
+
|
59
|
+
StartcoinClient('admin1', '123', :host => '127.0.0.1', :port => 19001)
|
60
|
+
StartcoinClient('admin2', '123', :host => '127.0.0.1', :port => 19011)
|
61
|
+
|
62
|
+
At this point you can use regular RPC methods provided in API
|
78
63
|
|
data/lib/startcoin_client/api.rb
CHANGED
@@ -8,17 +8,20 @@ class StartcoinClient::API
|
|
8
8
|
def port; options[:port]; end
|
9
9
|
def ssl; options[:ssl]; end
|
10
10
|
def ssl?; options[:ssl]; end
|
11
|
+
def proxy; options[:proxy]; end
|
11
12
|
def user=(a); options[:user] = a; end
|
12
13
|
def pass=(a); options[:pass] = a; end
|
13
14
|
def host=(a); options[:host] = a; end
|
14
15
|
def port=(a); options[:port] = a; end
|
15
16
|
def ssl=(a); options[:ssl] = a; end
|
17
|
+
def proxy=(a); options[:proxy] = a; end
|
16
18
|
|
17
19
|
def initialize(options = {})
|
18
20
|
@options = {
|
19
21
|
:host => 'localhost',
|
20
22
|
:port => 8332,
|
21
|
-
:ssl => false
|
23
|
+
:ssl => false,
|
24
|
+
:proxy => nil
|
22
25
|
}.merge(options)
|
23
26
|
end
|
24
27
|
|
@@ -5,12 +5,14 @@ class StartcoinClient::Client
|
|
5
5
|
def host; api.host; end
|
6
6
|
def port; api.port; end
|
7
7
|
def ssl; api.ssl; end
|
8
|
+
def proxy; api.proxy; end
|
8
9
|
def ssl?; api.ssl?; end
|
9
10
|
def user=(a); api.user = a; end
|
10
11
|
def pass=(a); api.pass = a; end
|
11
12
|
def host=(a); api.host = a; end
|
12
13
|
def port=(a); api.port = a; end
|
13
14
|
def ssl=(a); api.ssl = a; end
|
15
|
+
def proxy=(a); api.proxy = a; end
|
14
16
|
|
15
17
|
def options
|
16
18
|
api.options
|
data/lib/startcoin_client/dsl.rb
CHANGED
@@ -27,6 +27,10 @@ module StartcoinClient::DSL
|
|
27
27
|
bitcoin.ssl = value
|
28
28
|
end
|
29
29
|
|
30
|
+
def proxy=(value)
|
31
|
+
bitcoin.proxy = value
|
32
|
+
end
|
33
|
+
|
30
34
|
def username(value = nil)
|
31
35
|
value ? bitcoin.user = value : bitcoin.user
|
32
36
|
end
|
@@ -47,6 +51,10 @@ module StartcoinClient::DSL
|
|
47
51
|
value.nil? ? bitcoin.ssl : bitcoin.ssl = value
|
48
52
|
end
|
49
53
|
|
54
|
+
def proxy(value = nil)
|
55
|
+
value.nil? ? bitcoin.proxy : bitcoin.proxy = value
|
56
|
+
end
|
57
|
+
|
50
58
|
def ssl?
|
51
59
|
bitcoin.ssl?
|
52
60
|
end
|
data/lib/startcoin_client/rpc.rb
CHANGED
@@ -4,7 +4,7 @@ class StartcoinClient::RPC
|
|
4
4
|
def initialize(options)
|
5
5
|
@user, @pass = options[:user], options[:pass]
|
6
6
|
@host, @port = options[:host], options[:port]
|
7
|
-
@ssl = options[:ssl]
|
7
|
+
@ssl, @proxy = options[:ssl], options[:proxy]
|
8
8
|
end
|
9
9
|
|
10
10
|
def credentials
|
@@ -23,11 +23,19 @@ class StartcoinClient::RPC
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def dispatch(request)
|
26
|
-
|
26
|
+
process_response = lambda do |respdata, _request, _result|
|
27
27
|
response = JSON.parse(respdata)
|
28
28
|
raise StartcoinClient::Errors::RPCError, response['error'] if response['error']
|
29
29
|
response['result']
|
30
30
|
end
|
31
|
+
RestClient::Request.execute(method: :post,
|
32
|
+
url: service_url,
|
33
|
+
payload: request.to_post_data,
|
34
|
+
proxy: @proxy,
|
35
|
+
headers: { content_type: :json },
|
36
|
+
&process_response)
|
37
|
+
|
38
|
+
end
|
31
39
|
end
|
32
40
|
|
33
41
|
private
|
@@ -3,16 +3,23 @@ require 'spec_helper'
|
|
3
3
|
describe StartcoinClient::API do
|
4
4
|
subject { StartcoinClient::API.new(:user => $user, :pass => $pass) }
|
5
5
|
|
6
|
-
it "should have default host, port, ssl" do
|
6
|
+
it "should have default host, port, ssl, proxy" do
|
7
7
|
subject.host.should == 'localhost'
|
8
8
|
subject.port.should == 8332
|
9
9
|
subject.ssl?.should be_false
|
10
|
+
subject.proxy.should be_nil
|
10
11
|
end
|
11
12
|
|
12
|
-
it "should accept host, port, ssl options" do
|
13
|
-
req = StartcoinClient::API.new(:user => $user,
|
13
|
+
it "should accept host, port, ssl, proxy options" do
|
14
|
+
req = StartcoinClient::API.new(:user => $user,
|
15
|
+
:pass => $pass,
|
16
|
+
:host => 'example.com',
|
17
|
+
:port => 1234,
|
18
|
+
:ssl => true,
|
19
|
+
:proxy => 'proxy.com')
|
14
20
|
req.host.should == 'example.com'
|
15
21
|
req.port.should == 1234
|
22
|
+
req.proxy.should == 'proxy.com'
|
16
23
|
req.ssl?.should be_true
|
17
24
|
end
|
18
25
|
|
@@ -23,6 +30,7 @@ describe StartcoinClient::API do
|
|
23
30
|
:host => 'localhost',
|
24
31
|
:port => 8332,
|
25
32
|
:ssl => false,
|
33
|
+
:proxy => nil
|
26
34
|
}
|
27
35
|
end
|
28
36
|
end
|
data/startcoin-client.gemspec
CHANGED
@@ -28,5 +28,5 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency "rspec", '~> 2.6'
|
29
29
|
s.add_development_dependency "fakeweb", '~> 1.3'
|
30
30
|
s.add_development_dependency "coveralls"
|
31
|
-
s.add_runtime_dependency "rest-client"
|
31
|
+
s.add_runtime_dependency "rest-client", '~> 2.0'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startcoin-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin MacKenzie IV
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -85,16 +85,16 @@ dependencies:
|
|
85
85
|
name: rest-client
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
90
|
+
version: '2.0'
|
91
91
|
type: :runtime
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
97
|
+
version: '2.0'
|
98
98
|
description: Provides a Ruby library to the complete Startcoin JSON-RPC API. Implements
|
99
99
|
all methods listed at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
|
100
100
|
which is the same as Startcoin API. Lets you set options such as the host and port
|