Module: Filecoin::Http::ClassMethods

Included in:
Filecoin::Http
Defined in:
lib/filecoin/http.rb

Instance Method Summary collapse

Instance Method Details

#post(uri, token, data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/filecoin/http.rb', line 7

def post(uri, token, data)
  return if uri.nil?

  req = Net::HTTP::Post.new(uri)
  req["Content-Type"] = "application/json"
  req["Authorization"] = "Bearer #{token}" unless token.nil?
  req.body = data.to_json

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

#request(request) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/filecoin/http.rb', line 19

def request(request)
  uri = request.uri

  return if uri.nil?

  Net::HTTP.new(uri.host, uri.port).request(request)
end