Module: TronHttp::HTTP

Defined in:
lib/tron_http/http.rb

Overview

HTTP

Class Method Summary collapse

Class Method Details

.default_headers(request) ⇒ Object

Set request default_headers



36
37
38
39
# File 'lib/tron_http/http.rb', line 36

def self.default_headers(request)
  request["accept"] = "application/json"
  request["content-type"] = "application/json"
end

.get(uri, _params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tron_http/http.rb', line 10

def self.get(uri, _params = {})
  http = Net::HTTP.new(uri.host, 443)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri)

  default_headers(request)

  response = http.request(request)
  JSON.parse response.body
end

.post(uri, params = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tron_http/http.rb', line 22

def self.post(uri, params = {})
  http = Net::HTTP.new(uri.host, 443)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri)
  request.body = JSON.generate(params)

  default_headers(request)

  response = http.request(request)
  JSON.parse response.body
end