Class: RKD::Query::HTTP
- Inherits:
-
Object
- Object
- RKD::Query::HTTP
- Defined in:
- lib/r_k_d/query/http.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Class Method Details
.post_json(url, data) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/r_k_d/query/http.rb', line 7 def post_json(url, data) uri = URI(url) headers = {"Content-Type" => "application/json; charset=utf-8", "Accept-Charset" => "utf-8"} req = Net::HTTP::Post.new(uri, headers) req.body = data.to_json res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end if [200, 201].include? res.code.to_i res.body.force_encoding("utf-8") else raise Error, res.code end end |