Class: Coinex::Request
Class Method Summary collapse
Methods inherited from Base
Class Method Details
.get_method(name:, uri:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/coinex/resources/request.rb', line 20 def get_method(name:, uri:) case name when 'GET' req = Net::HTTP::Get.new(uri) when 'POST' req = Net::HTTP::Post.new(uri) when 'DELETE' req = Net::HTTP::Delete.new(uri) end req end |
.request(uri:, method:, signature: nil, params: {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/coinex/resources/request.rb', line 6 def request(uri:, method:, signature: nil, params: {}) req = get_method(name: method, uri: uri) req['Authorization'] = signature unless signature.nil? req['Content-Type'] = 'application/json' req.body = JSON.dump(params) unless params.empty? res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(req) end JSON.parse(res.body) end |