Class: DbchainClient::RestLib
- Inherits:
-
Object
- Object
- DbchainClient::RestLib
- Defined in:
- lib/dbchain_client/rest_lib.rb
Instance Method Summary collapse
-
#initialize(base_url) ⇒ RestLib
constructor
A new instance of RestLib.
- #rest_get(url) ⇒ Object
- #rest_post(url, data) ⇒ Object
Constructor Details
#initialize(base_url) ⇒ RestLib
Returns a new instance of RestLib.
8 9 10 |
# File 'lib/dbchain_client/rest_lib.rb', line 8 def initialize(base_url) @base_url = base_url end |
Instance Method Details
#rest_get(url) ⇒ Object
12 13 14 15 16 |
# File 'lib/dbchain_client/rest_lib.rb', line 12 def rest_get(url) uri = URI(@base_url + url) res = Net::HTTP.get_response(uri) res end |
#rest_post(url, data) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/dbchain_client/rest_lib.rb', line 18 def rest_post(url, data) uri = URI(@base_url + url) req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json') req.body = data http = Net::HTTP.new(uri.host, uri.port) res = http.request(req) res.body end |