Skip to content

Commit

Permalink
add http request
Browse files Browse the repository at this point in the history
  • Loading branch information
songky authored and songky committed Mar 14, 2022
1 parent 9921b91 commit 1fe9bd0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
40 changes: 25 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
PATH
remote: .
specs:
scale.rb (0.2.19)
scale.rb (0.2.38)
base58
blake2b_rs (~> 0.1.2)
blake2b
faye-websocket
json (~> 2.3.0)
thor (~> 1.0)
rest-client
thor (~> 0.19)
xxhash

GEM
remote: https://rubygems.org/
specs:
base58 (0.2.3)
blake2b_rs (0.1.2)
ffi (= 1.15.0)
thermite (~> 0)
blake2b (0.10.0)
coderay (1.1.3)
diff-lcs (1.4.4)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
eventmachine (1.2.7)
faye-websocket (0.11.0)
faye-websocket (0.11.1)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1)
ffi (1.15.0)
http-accept (1.7.0)
http-cookie (1.0.4)
domain_name (~> 0.5)
json (2.3.1)
method_source (1.0.0)
minitar (0.9)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
netrc (0.11.0)
pry (0.14.0)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.3)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -43,13 +55,11 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
thermite (0.13.0)
minitar (~> 0.5)
rake (>= 10)
tomlrb (~> 1.2)
thor (1.1.0)
tomlrb (1.3.0)
websocket-driver (0.7.3)
thor (0.20.3)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.1)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xxhash (0.4.0)
Expand Down
8 changes: 8 additions & 0 deletions lib/substrate_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ def ws_request(url, payload)
end
end

result = http_request(url, payload) if result.nil?
result
end

def http_request(url, payload)
r = RestClient.post(url, payload.to_json, { content_type: :json, accept: :json })
JSON.parse(r.body)
rescue => ex
{ "error": ex.message }
end

class SubstrateClient
class WebsocketError < StandardError; end
class RpcError < StandardError; end
Expand Down
1 change: 1 addition & 0 deletions scale.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "json", "~> 2.3.0"
spec.add_dependency "faye-websocket"
spec.add_dependency "thor", '~> 0.19'
spec.add_dependency "rest-client"

spec.add_development_dependency "bundler"
spec.add_development_dependency "pry"
Expand Down

0 comments on commit 1fe9bd0

Please sign in to comment.