#:main: README require 'VideoServiceDriver.rb' require 'VideoSearchServiceDriver.rb' module Fliqz # This is the Video Web Service wrapper class of the Fliqa API. class VideoAPI VIDEO_WEB_SERVICE_WSDL = 'http://services.fliqz.com/videoservice/080107/service.svc?wsdl' # Create a Fliqz Video Web Service caller object. # # Fliqz::VideoAPI.new # def initialize XSD::Charset.encoding = 'UTF8' end def method_missing(m, *args) #:nodoc: call_name = Fliqz::fix_case_up(m.id2name) # upper first character @callName = call_name.dup raise(Error::UnknownAPICall, "Unknown API Call: #{@call_name}", caller) unless valid_call?(call_name) service = IVideoService.new(VIDEO_WEB_SERVICE_WSDL) request = Object.module_eval("::#{call_name}", __FILE__, __LINE__).new args_hash = args[0] Fliqz::assign_args(request, args_hash) Fliqz::fix_case_down(call_name) begin resp = service.instance_eval("#{call_name}(request).#{call_name}Result", __FILE__, __LINE__) rescue SOAP::FaultError => err_string raise(Error::ApplicationError, "#{@callName} Call Failed: #{err_string}", caller) end return resp end private def valid_call?(call) call = Fliqz::fix_case_down(String.new(call)) # lower first character IVideoService::Methods.each { |defs| return true if defs[1] == call } return false end end # This is the Search Web Service wrapper class of the Fliqa API. class SearchAPI SEARCH_WEB_SERVICE_WSDL = 'http://services.fliqz.com/searchservice/20071001/service.svc?wsdl' # Create a Fliqz Search Web Service caller object. # # Fliqz::SearchAPI.new if you installed as a Rails Plugin # # Fliqz::SearchAPI.new(account_id) if you installed as a Ruby Gem # def initialize(account_id = nil) @account_id = account_id unless account_id.nil? if (@account_id.nil?) begin @@fliqz_config_path = RAILS_ROOT + '/config/fliqz_account.yml' @@fliqz_config = YAML.load_file(@@fliqz_config_path)[RAILS_ENV].symbolize_keys rescue raise ConfigFileNotFoundError.new('File %s not found' % @@fliqz_config_path) end begin @account_id = @@fliqz_config[:account_id] @account_id.empty? rescue raise FliqzConfigInfoNotDefinedError.new('Fliqz Account ID not defined') end end XSD::Charset.encoding = 'UTF8' end def getByUploadDate(*args) return handle_methods('getByUploadDate', 'OrderedSearchRequest', args) end def getByRating(*args) return handle_methods('getByRating', 'ThresholdSearchRequest', args) end def getByShares(*args) return handle_methods('getByShares', 'ThresholdSearchRequest', args) end def getByPlays(*args) return handle_methods('getByPlays', 'ThresholdSearchRequest', args) end def getByApprovalDate(*args) return handle_methods('getByApprovalDate', 'SearchRequest', args) end def getByAvailabilityDate(*args) return handle_methods('getByAvailabilityDate', 'SearchRequest', args) end def getNextPage(*args) return handle_methods('getNextPage', 'EnumRequest', args) end private def handle_methods(method_name, request_class, args) call_name = Fliqz::fix_case_up(method_name) args[0] = Hash.new if args.empty? args[0][:accountId] = @account_id service = IVideoSearchService.new(SEARCH_WEB_SERVICE_WSDL) request = request_class.constantize.new args_hash = args[0] Fliqz::assign_args(request, args_hash) req = Object.module_eval("::#{call_name}", __FILE__, __LINE__).new(request) Fliqz::fix_case_down(call_name) begin resp = service.instance_eval("#{call_name}(req).#{call_name}Result", __FILE__, __LINE__) rescue SOAP::FaultError => err_string raise(Error::ApplicationError, "#{@callName} Call Failed: #{err_string}", caller) end return resp end def valid_call?(call) call = Fliqz::fix_case_down(String.new(call)) # lower first character IVideoSearchService::Methods.each { |defs| return true if defs[1] == call } return false end end # Exception container class Error #:stopdoc: class Error < StandardError; end #:startdoc: # Raised if a call is made to a method that does not exist in the Fliqz SOAP API class UnknownAPICall < Error; end # Raised if an attempt is made to instantiate a type that does not exist in the Fliqz SOAP API class UnknownType < Error; end # Raised if a call returns SOAP::Fault. class ApplicationError < Error; end end #:enddoc: # Some helper functions for two api handlers class <