Class: Sorenson::ThreeSixty::Uploader
- Defined in:
- lib/sorenson/threesixty/uploader.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#account ⇒ Object
Attributes.
-
#application ⇒ Object
Attributes.
-
#audioBitRateMode ⇒ Object
Attributes.
-
#audioCodec ⇒ Object
Attributes.
-
#audioDataRate ⇒ Object
Attributes.
-
#authorName ⇒ Object
Attributes.
-
#description ⇒ Object
Attributes.
-
#displayName ⇒ Object
Attributes.
-
#fileType ⇒ Object
Attributes.
-
#filter ⇒ Object
Attributes.
-
#frameRate ⇒ Object
Attributes.
-
#height ⇒ Object
Attributes.
-
#pathToAsset ⇒ Object
Attributes.
-
#pathToMainThumbnail ⇒ Object
Attributes.
-
#pathToShortPreview ⇒ Object
Attributes.
-
#pathToSummaryThumbnails ⇒ Object
Attributes.
-
#presetXML ⇒ Object
Attributes.
-
#sourceAudioBitRateMode ⇒ Object
Attributes.
-
#sourceAudioCodec ⇒ Object
Attributes.
-
#sourceAudioDataRate ⇒ Object
Attributes.
-
#sourceFileName ⇒ Object
Attributes.
-
#sourceFileType ⇒ Object
Attributes.
-
#sourceFrameRate ⇒ Object
Attributes.
-
#sourceHeight ⇒ Object
Attributes.
-
#sourceVideoBitRateMode ⇒ Object
Attributes.
-
#sourceVideoCodec ⇒ Object
Attributes.
-
#sourceVideoDataRate ⇒ Object
Attributes.
-
#sourceWidth ⇒ Object
Attributes.
-
#videoBitRateMode ⇒ Object
Attributes.
-
#videoCodec ⇒ Object
Attributes.
-
#videoDataRate ⇒ Object
Attributes.
-
#videoDuration ⇒ Object
Attributes.
-
#width ⇒ Object
Attributes.
Instance Method Summary collapse
- #getMD5Hash ⇒ Object
-
#initialize(account, options = {}) ⇒ Uploader
constructor
Instance Methods.
- #uploadAsset ⇒ Object
Methods inherited from Base
debug=, debug?, host, #post_to, post_to, protocol, token_for, use_ssl=, use_ssl?
Constructor Details
#initialize(account, options = {}) ⇒ Uploader
Instance Methods
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sorenson/threesixty/uploader.rb', line 11 def initialize(account, = {}) self.account = account defaults = { 'application' => 'Unknown', 'frameRate' => '1:1', 'width' => 320, 'height' => 240, 'audioDataRate' => '19000', 'videoDataRate' => '23222', 'audioBitRateMode' => 'VBR_STEREO', 'videoBitRateMode' => 'VBR_TWO_PASS', 'videoDuration' => 0, 'fileType' => 'Flash', 'audioCodec' => 'unknown', 'videoCodec' => 'unknown', 'authorName' => 'unknown', 'sourceFileName' => 'unknown', 'sourceAudioCodec' => 'unknown', 'sourceVideoCodec' => 'unknown', 'sourceFrameRate' => '1:1', 'sourceWidth' => 0, 'sourceHeight' => 0, 'sourceAudioBitRateMode' => 'unknown', 'sourceVideoDataRate' => '23222', 'sourceVideoBitRateMode' => 'unknown' } attributes = defaults.merge() attributes.each do |k,v| method = "#{k}=".to_sym self.send(method, v) if self.respond_to?(method) end end |
Instance Attribute Details
#account ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def account @account end |
#application ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def application @application end |
#audioBitRateMode ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def audioBitRateMode @audioBitRateMode end |
#audioCodec ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def audioCodec @audioCodec end |
#audioDataRate ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def audioDataRate @audioDataRate end |
#authorName ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def @authorName end |
#description ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def description @description end |
#displayName ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def displayName @displayName end |
#fileType ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def fileType @fileType end |
#filter ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def filter @filter end |
#frameRate ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def frameRate @frameRate end |
#height ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def height @height end |
#pathToAsset ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def pathToAsset @pathToAsset end |
#pathToMainThumbnail ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def pathToMainThumbnail @pathToMainThumbnail end |
#pathToShortPreview ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def pathToShortPreview @pathToShortPreview end |
#pathToSummaryThumbnails ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def pathToSummaryThumbnails @pathToSummaryThumbnails end |
#presetXML ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def presetXML @presetXML end |
#sourceAudioBitRateMode ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceAudioBitRateMode @sourceAudioBitRateMode end |
#sourceAudioCodec ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceAudioCodec @sourceAudioCodec end |
#sourceAudioDataRate ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceAudioDataRate @sourceAudioDataRate end |
#sourceFileName ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceFileName @sourceFileName end |
#sourceFileType ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceFileType @sourceFileType end |
#sourceFrameRate ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceFrameRate @sourceFrameRate end |
#sourceHeight ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceHeight @sourceHeight end |
#sourceVideoBitRateMode ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceVideoBitRateMode @sourceVideoBitRateMode end |
#sourceVideoCodec ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceVideoCodec @sourceVideoCodec end |
#sourceVideoDataRate ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceVideoDataRate @sourceVideoDataRate end |
#sourceWidth ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def sourceWidth @sourceWidth end |
#videoBitRateMode ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def videoBitRateMode @videoBitRateMode end |
#videoCodec ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def videoCodec @videoCodec end |
#videoDataRate ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def videoDataRate @videoDataRate end |
#videoDuration ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def videoDuration @videoDuration end |
#width ⇒ Object
Attributes
6 7 8 |
# File 'lib/sorenson/threesixty/uploader.rb', line 6 def width @width end |
Instance Method Details
#getMD5Hash ⇒ Object
46 47 48 49 50 51 52 53 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 94 |
# File 'lib/sorenson/threesixty/uploader.rb', line 46 def getMD5Hash md5 = Digest::MD5.new return false unless File.exist?(pathToAsset) length = File.size(pathToAsset) fp = File.open(pathToAsset) totalRead = 0 numRead = 0 numSamples = 100 sampleSize = 1024 bytes = 1024 puts length puts numSamples * sampleSize # # if (length <= numSamples * sampleSize) # while (totalRead < length) # totalRead += bytes # data = fp.read(bytes) # md5.update(data); # end # else # skipBlockSize = length / numSamples - sampleSize # # long skipBlockSize = length / numSamples - sampleSize; # # while (length - totalRead > sampleSize + skipBlockSize) # { # numRead = 0; # # while (numRead < sampleSize) # { # numRead = is.read(bytes, 0, Math.min(bytes.length, sampleSize - numRead)); # md5.update(bytes, 0, numRead); # totalRead += numRead; # } # # is.skip(skipBlockSize); # totalRead += skipBlockSize; # } # # # end md5.hexdigest end |
#uploadAsset ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sorenson/threesixty/uploader.rb', line 96 def uploadAsset # url = URI.parse('http://www.example.com/upload') # File.open("./image.jpg") do |jpg| # req = Net::HTTP::Post::Multipart.new url.path, # "file" => UploadIO.new(jpg, "image/jpeg", "image.jpg") # res = Net::HTTP.start(url.host, url.port) do |http| # http.request(req) # end # end # end |