45 lines
1003 B
Ruby
45 lines
1003 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"].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
|
|
|
|
|
|
|
|
private
|
|
def valid_json? json_
|
|
JSON.parse(json_)
|
|
return true
|
|
rescue JSON::ParserError
|
|
return false
|
|
end
|
|
|
|
end
|