Class: Chillout::PlainHttpClient
- Inherits:
-
Object
- Object
- Chillout::PlainHttpClient
- Defined in:
- lib/chillout/server_side/plain_http_client.rb
Defined Under Namespace
Classes: CommunicationError, NotCreated
Constant Summary collapse
- MEDIA_TYPE =
"application/vnd.chillout.v1+json"
Instance Method Summary collapse
Instance Method Details
#post(path, data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chillout/server_side/plain_http_client.rb', line 27 def post(path, data) begin http = Net::HTTP.new("api.chillout.io", 443) http.use_ssl = true request_spec = Net::HTTP::Post.new(path) request_spec.body = MultiJson.dump(data) request_spec.content_type = MEDIA_TYPE response = http.start do http.request(request_spec) end raise NotCreated.new(response) if response.code != "201" MultiJson.load(response.body) rescue NotCreated raise rescue => e raise CommunicationError.new(e) end end |