Class: ChocolateRain::YVideo

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

Constant Summary collapse

@@y_creds =
{}
@@y_conn =
YouTubeIt::Client.new(:username => @@y_creds[:username] , :password => @@y_creds[:password] , :dev_key => @@y_creds[:dev_key])
@@s3_creds =
YAML.load(File.open("config/s3.yml"))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeYVideo

Returns a new instance of YVideo.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chocolate_rain/y_video.rb', line 23

def initialize
  @filename = nil
  @title = ""
  @description = "Testimonial Video"
  @category = "Entertainment"
  @keywords = %w[herman cain whyhermancain republican politics testimonal donate donation]
  @list = "denied"
  @comments = "denied"
  @rate = "denied"
  @commentVote = "denied"
  @videoRespond = "denied"
  @embed = "denied"
  @syndicate = "denied"
  @private = true
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def category
  @category
end

#commentsObject

Returns the value of attribute comments.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def comments
  @comments
end

#commentVoteObject

Returns the value of attribute commentVote.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def commentVote
  @commentVote
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def description
  @description
end

#embedObject

Returns the value of attribute embed.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def embed
  @embed
end

#file_objectObject

Returns the value of attribute file_object.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def file_object
  @file_object
end

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def filename
  @filename
end

#keywordsObject

Returns the value of attribute keywords.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def keywords
  @keywords
end

#listObject

Returns the value of attribute list.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def list
  @list
end

#rateObject

Returns the value of attribute rate.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def rate
  @rate
end

#syndicateObject

Returns the value of attribute syndicate.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def syndicate
  @syndicate
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def title
  @title
end

#videoRespondObject

Returns the value of attribute videoRespond.



6
7
8
# File 'lib/chocolate_rain/y_video.rb', line 6

def videoRespond
  @videoRespond
end

Instance Method Details

#saveObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chocolate_rain/y_video.rb', line 56

def save
  begin
    AWS::S3::S3Object.store(self.filename, self.file_object, @@s3_creds[(Rails.env)]["bucket"], :access => :public_read)
    begin 
      self.upload
      return true
    rescue Exception => e
      puts "Upload Failed. #{e.message}"
    end
  rescue Exception => e
    puts "Could not complete save. #{e.message}"
    return false
  end
end

#to_hashObject



39
40
41
# File 'lib/chocolate_rain/y_video.rb', line 39

def to_hash
  self.instance_variables.inject({}) { |hash,var| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var); hash } 
end

#to_upload_options_hashObject



43
44
45
# File 'lib/chocolate_rain/y_video.rb', line 43

def to_upload_options_hash
  self.instance_variables.inject({}) { |hash,var| (hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var) unless (["filename", "file_object"].include?(var.to_s.delete("@")))); hash } 
end

#uploadObject



47
48
49
50
51
52
53
54
# File 'lib/chocolate_rain/y_video.rb', line 47

def upload
  resp = @@y_conn.video_upload(self.file_object, self.to_upload_options_hash
  )
  puts "Response: #{resp.inspect}"
  puts "***"
  puts "ID: #{resp.video_id.split(":").last}"
  return true
end