factom-rb 1.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/config.rb +33 -0
  3. data/lib/jsonrpc.rb +35 -0
  4. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f22f411780bc86a64250ad3ca01b9ee214888fe
4
+ data.tar.gz: 603592bd887316da0d6006269ab1d7874ff0fefb
5
+ SHA512:
6
+ metadata.gz: 8c1a530567533eb77cc3aaaf769ffbabb77ca41178e2745b4d66abf266a7f7fb69563d478720b29f37f8420000f53674b4a938637efb70f02fb4d390303c2d44
7
+ data.tar.gz: 4d469e3e9d1b8bff80e38dea311f73efdbc9316b0fb7350f9f334e52a8f1364f94e2b472412ace78d0148118248afb505ac22ac11e9db2803f4a0e132a66b94c
@@ -0,0 +1,33 @@
1
+ class Config
2
+ def initialize
3
+ @h="http://localhost"
4
+ @port=8088
5
+ @walletPort=8089
6
+ end
7
+ def getHost
8
+ return @h
9
+ end
10
+
11
+ def getPort
12
+ return @port
13
+ end
14
+
15
+ def getWalletdPort
16
+ return @walletPort
17
+ end
18
+
19
+ def setHost(host)
20
+ @h=host
21
+ return @h
22
+ end
23
+
24
+ def setPort(port)
25
+ @port=port
26
+ return @port
27
+ end
28
+
29
+ def setWalletdPort(port)
30
+ @walletPort=port
31
+ return @walletPort
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ class JsonRPC
6
+ def initialize(service_url)
7
+ @uri = URI.parse(service_url)
8
+ end
9
+
10
+ def call(name, args)
11
+ post_body = { 'method' => name, 'params' => args, 'id' => 0, 'jsonrpc': '2.0' }.to_json
12
+ return http_post_request(post_body, name)
13
+ end
14
+
15
+ def http_post_request(post_body, name)
16
+ url = URI(@uri)
17
+ http = Net::HTTP.new(url.host, url.port)
18
+ request = Net::HTTP::Get.new(url)
19
+ request.body = post_body
20
+ resp = http.request(request).body
21
+ resp = JSON.parse(resp)
22
+ if resp.has_key? 'error'
23
+ if resp['error']['message']=="Method not found"
24
+ resp['error']['message']="#{name} method not found. Please check your URL you provide is correct (factomd API call to factomd, wallet API call to factom-walletd API URL).";
25
+ return resp
26
+ else
27
+ return resp
28
+ end
29
+ else
30
+ return resp
31
+ end
32
+ end
33
+
34
+ class JSONRPCError < RuntimeError; end
35
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factom-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kompendium
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A json-rpc client for the Factom protocol
14
+ email:
15
+ - sergey@kompendium.co
16
+ - mitchell@kompendium.co
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/config.rb
22
+ - lib/jsonrpc.rb
23
+ homepage: https://rubygems.org/gems/factom-rb
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.5.2.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: factom rpc client
47
+ test_files: []