Class: Jekyll::StandardSite::HttpClient
- Inherits:
-
Object
- Object
- Jekyll::StandardSite::HttpClient
- Defined in:
- lib/jekyll-standard-site/publisher.rb
Instance Method Summary collapse
Instance Method Details
#post_json(url, body, headers = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jekyll-standard-site/publisher.rb', line 11 def post_json(url, body, headers = {}) uri = URI(url) req = Net::HTTP::Post.new(uri) req["Content-Type"] = "application/json" headers.each { |k, v| req[k] = v } req.body = JSON.dump(body) res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(req) end parsed = res.body && !res.body.empty? ? JSON.parse(res.body) : {} [res.code.to_i, parsed] end |