vidpush/app/models/better_video.rb
2014-04-30 14:41:57 -04:00

45 lines
993 B
Ruby

require 'net/http'
require 'uri'
require 'json'
class BetterVideo
def initialize(options={})
@addvideo_url = options.fetch(:url, "http://servicestest.bettervideo.com/orders/MDS.OrdersWS.svc/addVideo")
end
def addVideo(campaign)
uri = URI.parse(@addvideo_url)
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)
puts resp
if resp["errorcode"] == 0
resp[:success] = true
resp[:message] = "Successfully submitted to BetterVideo, Please wait."
else
resp[:message] = "Error Code #{resp["errorcode"]}: #{resp["errormessage"]}"
if resp["errorcode"] == 1
resp[:message] += "Please Contact Dev"
end
end
resp
end
private
def valid_json? json_
JSON.parse(json_)
return true
rescue JSON::ParserError
return false
end
end