class EyeQ

Attributes

eyeq_clientid[R]
eyeq_url[R]
eyeq_userid[R]

Public Class Methods

new(clientid, clientid_tag, opts = {}) click to toggle source
# File lib/eyeq_metadata.rb, line 7
def initialize(clientid, clientid_tag, opts = {})
  @eyeq_url = "https://c#{clientid}.ipg.web.cddbp.net/webapi/xml/1.0/"
  @eyeq_clientid = "#{clientid}-#{clientid_tag}"
  HTTPI.log = false if opts[:logging] == false

  register_query = "<QUERIES><QUERY CMD='REGISTER'><CLIENT>#{@eyeq_clientid}</CLIENT></QUERY></QUERIES>"
  response = HTTPI.post(construct_request(register_query))

  response_xml = Nokogiri::XML(response.body)

  raise 'Invalid clientid or clientid_tag. Query returned an ERROR.' if response_xml.css('RESPONSE').attr('STATUS').text == 'ERROR'
  @eyeq_userid = response_xml.css('USER').text
end

Public Instance Methods

request(options) click to toggle source
# File lib/eyeq_metadata.rb, line 21
def request(options)
  query = construct_query(options)
  response = HTTPI.post(construct_request(query))
  Nokogiri::XML(response.body)
end

Private Instance Methods

auth() click to toggle source
# File lib/eyeq_metadata.rb, line 84
def auth
  "<AUTH><CLIENT>#{@eyeq_clientid}</CLIENT><USER>#{@eyeq_userid}</USER></AUTH>"
end
avwork_fetch(gnid) click to toggle source
# File lib/eyeq_metadata.rb, line 133
def avwork_fetch(gnid)
  "<QUERY CMD='AV_WORK_FETCH'><GN_ID>#{gnid}</GN_ID></QUERY>"
end
construct_query(options) click to toggle source
# File lib/eyeq_metadata.rb, line 35
def construct_query(options)
  query = '<QUERIES>'
  query += options[:lang].nil? ? lang : lang(options[:lang])
  query += options[:country].nil? ? country : country(options[:country])
  query + "#{auth}#{get_query_type(options)}</QUERIES>"
end
construct_request(query) click to toggle source
# File lib/eyeq_metadata.rb, line 29
def construct_request(query)
  request = HTTPI::Request.new(url: @eyeq_url, body: query)
  request.headers['Content-Type'] = 'text/xml'
  request
end
country(country = 'usa') click to toggle source
# File lib/eyeq_metadata.rb, line 80
def country(country = 'usa')
  "<COUNTRY>#{country}</COUNTRY>"
end
get_query_type(options) click to toggle source
# File lib/eyeq_metadata.rb, line 42
def get_query_type(options)
  query_type = nil

  case options[:query_type].downcase
  when 'tvchannel_fetch'
    throw new Error(':gnid option required') if options[:gnid].nil?
    query_type = tvchannel_fetch(options[:gnid])
  when 'tvchannel_lookup_by_provider'
    throw new Error(':gnid option required') if options[:gnid].nil?
    query_type = tvchannel_lookup_by_provider(options[:gnid])
  when 'tvprovider_na'
    throw new Error(':zipcode option required') if options[:zipcode].nil?
    query_type = tvprovider_na(options[:zipcode])
  when 'tvprovider_or'
    throw new Error(':tvregion option required') if options[:tvregion].nil?
    query_type = tvprovider_or(options[:tvregion])
  when 'tvprogram_fetch'
    throw new Error(':gnid option required') if options[:gnid].nil?
    query_type = tvprogram_fetch(options[:gnid])
  when 'tvgrid_search'
    throw new Error(':program_title option required') if options[:program_title].nil?
    throw new Error(':tvchannel_gnid option required') if options[:tvchannel_gnid].nil?
    query_type = tvgrid_search(options)
  when 'tvgrid_lookup'
    throw new Error(':tvchannel_gnid option required') if options[:tvchannel_gnid].nil?
    query_type = tvgrid_lookup(options)
  when 'avwork_fetch'
    throw new Error(':gnid option required') if options[:gnid].nil?
    query_type = avwork_fetch(options[:gnid])
  end

  query_type
end
insert_date_time(options) click to toggle source
# File lib/eyeq_metadata.rb, line 137
def insert_date_time(options)
  date_start = options[:date_start] unless options[:date_start].nil?
  date_end = options[:date_end] unless options[:date_end].nil?

  date = "<DATE TYPE='START'>#{date_start}</DATE>" unless options[:date_start].nil?
  date << "<DATE TYPE='END'>#{date_end}</DATE>" unless options[:date_end].nil?
end
lang(lang = 'eng') click to toggle source
# File lib/eyeq_metadata.rb, line 76
def lang(lang = 'eng')
  "<LANG>#{lang}</LANG>"
end
tvchannel_fetch(gnid) click to toggle source
# File lib/eyeq_metadata.rb, line 88
def tvchannel_fetch(gnid)
  "<QUERY CMD='TVCHANNEL_FETCH'><GN_ID>#{gnid}</GN_ID></QUERY>"
end
tvchannel_lookup_by_provider(gnid) click to toggle source
# File lib/eyeq_metadata.rb, line 92
def tvchannel_lookup_by_provider(gnid)
  "<QUERY CMD='TVCHANNEL_LOOKUP'><MODE>TVPROVIDER</MODE><GN_ID>#{gnid}</GN_ID></QUERY>"
end
tvgrid_lookup(options) click to toggle source
# File lib/eyeq_metadata.rb, line 121
def tvgrid_lookup(options)
  tvchannel_gnid = options[:tvchannel_gnid]

  query = "<QUERY CMD='TVGRID_LOOKUP'><TVCHANNEL>"
  return query << "<GN_ID>#{tvchannel_gnid}</GN_ID></TVCHANNEL>#{insert_date_time(options)}</QUERY>" unless tvchannel_gnid.is_a? Array

  tvchannel_gnid.each do |gnid|
    query << "<GN_ID>#{gnid}</GN_ID>"
  end
  query << "</TVCHANNEL>#{insert_date_time(options)}</QUERY>"
end
tvprogram_fetch(gnid) click to toggle source
# File lib/eyeq_metadata.rb, line 104
def tvprogram_fetch(gnid)
  "<QUERY CMD='TVPROGRAM_FETCH'><GN_ID>#{gnid}</GN_ID></QUERY>"
end
tvprovider_na(zipcode) click to toggle source
# File lib/eyeq_metadata.rb, line 96
def tvprovider_na(zipcode)
  "<QUERY CMD='TVPROVIDER_LOOKUP'><POSTALCODE>#{zipcode}</POSTALCODE></QUERY>"
end
tvprovider_or(tvregion) click to toggle source
# File lib/eyeq_metadata.rb, line 100
def tvprovider_or(tvregion)
  "<QUERY CMD='TVPROVIDER_LOOKUP'><TVREGION>#{tvregion}</TVREGION></QUERY>"
end