coinrpc 1.0.1 → 2.0.0

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
  SHA256:
3
- metadata.gz: c8987e04a7a59aa0043ee842747c14bda284aad487742ccb5f1690ea079b613f
4
- data.tar.gz: e5bbffa5611d73c56f10e66df56d3e1ae452fc1da12a03cefa70a3fe786d99fc
3
+ metadata.gz: 10cff07aebe3b64ba01cd8c59f50f7db97d455954adaef5813514bb9a4352079
4
+ data.tar.gz: 19b5357773239877bed09865571389b1a6897e6f65de2302acfb62ad55c940c1
5
5
  SHA512:
6
- metadata.gz: 4efaf3a9198b7a94df3d49e75c66e4a2fd1374474241092e9481f62c9daf34a6f6e98fad6a3be88bcc77af1ee56c97b7cd7c1e07f563be627fe2642303327ae1
7
- data.tar.gz: 32cd9994824f7dca0c13900c82957f3aa8b8703544d3d24b32a3eb661498f49270e695efd26d54b0b8af8a401b442f58d69e646a4abecb2e247299302ece6cfb
6
+ metadata.gz: d95f608c8d69d345f2f72a83344afd6a43ef93d2cb121ae70f29039fe5358589e676c4d6a63c74dcf0e44688d4009f26a3f170d08c87baa4d7e844c21772328c
7
+ data.tar.gz: 6c9ca37fb9c28257037476754ef4fd9027191f9a7b48e82299b4e052c958569cb9363b558447b58070d58bac99776cda84e48a35fa60219593b028c3ba57bf62
data/coinrpc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'coinrpc/version'
3
+ require "coinrpc/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "coinrpc"
@@ -17,10 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.required_ruby_version = ">= 2.4", "< 3.1"
20
+ spec.required_ruby_version = ">= 2.6", "< 3.2"
21
21
 
22
22
  spec.add_development_dependency "bundler", ">= 1.6", "< 3.0"
23
23
  spec.add_development_dependency "rake", ">= 13.0", "< 14.0"
24
+ spec.add_runtime_dependency "json", "~> 2.0", ">= 2.3.1", "< 3.0"
24
25
  spec.add_runtime_dependency "oj", ">= 3.10", "< 4.0"
25
- spec.add_runtime_dependency "http", ">= 4.4", "< 5.1"
26
+ spec.add_runtime_dependency "http", ">= 4.4", "< 5.2"
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module CoinRPC
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/coinrpc.rb CHANGED
@@ -1,9 +1,17 @@
1
- require 'http'
2
- require 'oj'
3
- require 'coinrpc/version'
1
+ require "http"
2
+ require "oj"
3
+ require "json"
4
+ require "coinrpc/version"
5
+
6
+ # let OJ mimic JSON
7
+ Oj.mimic_JSON
4
8
 
5
9
  module CoinRPC
6
10
  class Client
11
+
12
+ JSONRPC_V1_1 = "1.1".freeze
13
+ JSONRPC_V2_0 = "2.0".freeze
14
+
7
15
  def initialize(url)
8
16
 
9
17
  urinfo = URI.parse(url)
@@ -15,34 +23,17 @@ module CoinRPC
15
23
 
16
24
  def method_missing(method, *args)
17
25
 
18
- @id += 1
19
-
20
26
  fixed_method = method.to_s.gsub(/\_/,"").freeze
21
-
22
27
  post_data = nil
23
28
 
24
- if args.first.is_a?(Array) and args.first.size > 0 then
29
+ if args[0].is_a?(Array) and args[0].size > 0 then
25
30
  # batch request
26
-
27
- post_data = []
28
-
29
- args.each do |arg|
30
- @id += 1
31
- post_data << ({:jsonrpc => "2.0", :method => fixed_method, :params => arg, :id => @id})
32
- end
33
-
31
+ post_data = args.map{|arg| {:jsonrpc => JSONRPC_V2_0, :method => fixed_method, :params => arg, :id => (@id += 1)} }
34
32
  else
35
-
36
- post_data = ({
37
- :method => fixed_method,
38
- :params => args,
39
- :jsonrpc => "1.1",
40
- :id => @id
41
- })
42
-
33
+ post_data = {:method => fixed_method, :params => args, :jsonrpc => JSONRPC_V1_1, :id => (@id += 1)}
43
34
  end
44
35
 
45
- return api_call(post_data)
36
+ api_call(post_data)
46
37
 
47
38
  end
48
39
 
@@ -51,14 +42,17 @@ module CoinRPC
51
42
 
52
43
  response = @client.post("/", :body => Oj.dump(params, mode: :compat)).to_s
53
44
 
45
+ # this won"t work without Oj.mimic_JSON
54
46
  result = Oj.strict_load(response, :decimal_class => BigDecimal)
55
47
 
56
- raise result['error']['message'] if !result.is_a?(Array) and result['error']
48
+ raise result["error"]["message"] if result.is_a?(Hash) and result.key?("error")
57
49
 
58
- return result['result'] if result.is_a?(Hash)
59
-
60
- # batch call
61
- return result.map{|r| r['result'] || r['error']}
50
+ if result.is_a?(Hash) then
51
+ result["result"]
52
+ else
53
+ # batch call
54
+ result.map{|r| r["result"] || r["error"]}
55
+ end
62
56
 
63
57
  end
64
58
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atif Nazir
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,6 +50,32 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '14.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.1
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: '3.0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.0'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.1
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '3.0'
53
79
  - !ruby/object:Gem::Dependency
54
80
  name: oj
55
81
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +105,7 @@ dependencies:
79
105
  version: '4.4'
80
106
  - - "<"
81
107
  - !ruby/object:Gem::Version
82
- version: '5.1'
108
+ version: '5.2'
83
109
  type: :runtime
84
110
  prerelease: false
85
111
  version_requirements: !ruby/object:Gem::Requirement
@@ -89,7 +115,7 @@ dependencies:
89
115
  version: '4.4'
90
116
  - - "<"
91
117
  - !ruby/object:Gem::Version
92
- version: '5.1'
118
+ version: '5.2'
93
119
  description: This Ruby Gem is a fast RPC client for Bitcoin Core style software, including
94
120
  Dogecoin, Litecoin, and other similar software that implements Bitcoin Core RPC
95
121
  interfaces.
@@ -111,7 +137,7 @@ homepage: https://github.com/doersf/coinrpc
111
137
  licenses:
112
138
  - MIT
113
139
  metadata: {}
114
- post_install_message:
140
+ post_install_message:
115
141
  rdoc_options: []
116
142
  require_paths:
117
143
  - lib
@@ -119,18 +145,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
145
  requirements:
120
146
  - - ">="
121
147
  - !ruby/object:Gem::Version
122
- version: '2.4'
148
+ version: '2.6'
123
149
  - - "<"
124
150
  - !ruby/object:Gem::Version
125
- version: '3.1'
151
+ version: '3.2'
126
152
  required_rubygems_version: !ruby/object:Gem::Requirement
127
153
  requirements:
128
154
  - - ">="
129
155
  - !ruby/object:Gem::Version
130
156
  version: '0'
131
157
  requirements: []
132
- rubygems_version: 3.0.3
133
- signing_key:
158
+ rubygems_version: 3.3.7
159
+ signing_key:
134
160
  specification_version: 4
135
161
  summary: A fast RPC client for Bitcoin Core style software.
136
162
  test_files: []