require 'net/http' require 'uri' require 'json' class BetterVideo def initialize(options={}) @addvideo_url = options.fetch(:url, ENV['BETTER_VIDEO_URL']) end def addVideo(campaign) uri = URI.parse("#{@addvideo_url}/addVideo") header = {} http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = campaign[:campaign] response = http.request(request) resp = JSON.parse(response.body) if resp["errorcode"].to_i == 0 resp[:success] = true resp[:message] = "Successfully submitted to BetterVideo, Please wait." else resp[:message] = "Error Code #{resp["errorcode"]}: #{resp["errormessage"]}" if resp["errorcode"].to_i == 1 resp[:message] += "Please Contact Dev" end end resp end end