Class: OoyalaFb

Inherits:
Object
  • Object
show all
Defined in:
lib/ooyala_fb.rb

Overview

The logging level is set to INFO by default. Change it to Logger::ERROR if info messages about missing attribute values need not be logged in the file in the initialize method.

Constant Summary collapse

QUERY_EXPIRES_IN =
1000
FACEBOOK_MAX_WIDTH =

Maximum width allowed for facebook videos. If the video being uploaded has a width greater than this, it will be reduced to make the width the same as FACEBOOK_MAX_WIDTH while maintaining the same aspect ratio between height and width.

420

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OoyalaFb

Returns a new instance of OoyalaFb.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ooyala_fb.rb', line 30

def initialize (options = {})
  @partner_code = options[:partner_code]
  @secret_code  = options[:secret_code]
  @log = options[:log]
  @log_path = options[:log_path]
  
  # Create a logger which ages logfile once it reaches
  # a certain size. Leave 10 "old log files" and each file is about 1,024,000 bytes.
  # log disabled by default
  
  if @log
    log_path = options[:log_path] || 'ooyala_fb.log' 
    $LOG = Logger.new(log_path, 10, 1024000)

    # Set the default logging level to INFO. So it will print messages
    # about missing attribute values in the FacebookSharing.log file.
    # Change this to Logger:ERROR if the messages should not be logged.
    $LOG.sev_threshold = Logger::INFO 
  end
end

Instance Method Details

#header(embed_code) ⇒ Object

Returns the string containing meta tags required by videos being uploaded to facebook for the given embed code, partner code and secret code video.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ooyala_fb.rb', line 54

def header (embed_code)
  # Get the url for the passed in partner_code, secret_code and embed_code
  url = get_url('embedCode'=> embed_code)

  # Get the xml data for the url.
  xml_data = Net::HTTP.get_response(URI.parse(url)).body

  # Parse the xml document to get the values for creating meta tags
  doc = REXML::Document.new(xml_data)

  # Fill the hash map with the key value pairs for the required meta tags
  # by getting the values from the parsed xml
  tags     = ['title', 'description', 'thumbnail', 'height', 'width', 'embedCode']
   = {}
  tags.map{|tag| [tag] = get_node_value(doc, tag, embed_code)}

  # Adjust video width to max allowed by Facebook, if required.
  if ['width'] != nil
    if Integer(['width']) > FACEBOOK_MAX_WIDTH
      ['height'] = get_adjusted_height(Integer(['width']), Integer(['height']))
      ['width']  = FACEBOOK_MAX_WIDTH
    end
  end

  # Construct the meta tags string by substituting the values from the metadata hashmap.
  meta_tags = %Q{
    <meta name="medium" content="video" />
    <meta name="title" content="#{['title']}" />
    <meta name="description" content="#{['description']}" />
    <link rel="image_src" href="#{['thumbnail']}" />
    <link rel="video_src" href="http://player.ooyala.com/player.swf?\
embedCode=#{['embedCode']}&keepEmbedCode=true" />
    <meta name="video_height" content="#{['height']}" />
    <meta name="video_width" content="#{['width']}" />
    <meta name="video_type" content="application/x-shockwave-flash" />
  }

  # return the meta tags string with the values retrieved for the embedCode
  return meta_tags
end