Sha256: 4e29ec46d1c5483ba18cfba79f7e5d02429cc91cb5b3fa99d1685252095dc35d
Contents?: true
Size: 1.5 KB
Versions: 13
Compression:
Stored size: 1.5 KB
Contents
require 'net/http' require 'net/https' require 'multi_json' module Chillout class HttpClient class NotSent < StandardError attr_reader :original_exception def initialize(original_exception) @original_exception = original_exception end end class NotReceived < StandardError attr_reader :original_exception def initialize(original_exception) @original_exception = original_exception end end MEDIA_TYPE = "application/vnd.chillout.v1+json" def initialize(config, logger) @config = config @logger = logger end def post(path, data) http = Net::HTTP.new(@config.hostname, @config.port) http.use_ssl = @config.ssl request_spec = Net::HTTP::Post.new(path) request_spec.body = MultiJson.dump(data) request_spec.content_type = MEDIA_TYPE request_spec.basic_auth @config.authentication_user, @config.authentication_password http.start do http.request(request_spec) end rescue => e @logger.error("#{e.class}: #{e.message}") raise NotSent.new(e) end def get(path) http = Net::HTTP.new(@config.hostname, @config.port) http.use_ssl = @config.ssl request_spec = Net::HTTP::Get.new(path) request_spec.content_type = MEDIA_TYPE request_spec.basic_auth @config.authentication_user, @config.authentication_password http.start do http.request(request_spec) end rescue => e raise NotReceived.new(e) end end end
Version data entries
13 entries across 13 versions & 1 rubygems