vidpush/app/models/better_video.rb
2014-05-09 14:17:00 -04:00

34 lines
948 B
Ruby

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['errormessage'].sub!("VPA", "Customer Service Rep") # fix for Customer Service Reps being called VPA in BV
resp[:message] = "Error Code #{resp["errorcode"]}: #{resp['errormessage']}"
if resp["errorcode"].to_i == 1
resp[:message] += "Please Contact Dev"
end
end
resp
end
end