Class: BBC::Redux::MediaUrl

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bbc/redux/media_url.rb

Overview

Redux API Asset URL Object

Each asset is available as various transcodes using the url function. The urls are key based and therefore generally have a lifetime of 24 hours #

Examples:

Properties of the url object


url = redux_client.asset('5966413090093319525').url(:mp3)

url.expired?   #=> Boolean
url.expires_at #=> DateTime
url.live?      #=> Boolean
url.ttl        #=> Integer
url.end_point  #=> String

generate a URL with a different filename


url = redux_client.asset('5966413090093319525').mp3_url

url.end_point('myfile.mp3') #=> String

Author:

Defined Under Namespace

Classes: UnknownTemplateType

Constant Summary collapse

TEMPLATES =

Known URL templates, these are the only valid options for the type attribute of MediaUrl.initialize.

See Also:

[
  :dvbsubs,
  :flv,
  :h264_hi,
  :h264_lo,
  :mp3,
  :ts,
  :ts_stripped
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, type, key) ⇒ MediaUrl

Returns a new instance of MediaUrl

Raises:

  • (UnknownTranscodeType)

    if type parameter is unknown

See Also:

  • MediaUrl.TYPES

89
90
91
92
93
94
95
96
97
98
# File 'lib/bbc/redux/media_url.rb', line 89

def initialize( identifier, type, key )

  unless TEMPLATES.include?(type)
    raise UnknownTemplateType.new("Unknown template type #{type}")
  end

  @identifier = identifier
  @type       = type
  @key        = key
end

Instance Attribute Details

#expires_atDateTime (readonly)


# File 'lib/bbc/redux/media_url.rb', line 48

#identifierString (readonly)


73
74
75
# File 'lib/bbc/redux/media_url.rb', line 73

def identifier
  @identifier
end

#keyBBC::Redux::Key (readonly)


82
83
84
# File 'lib/bbc/redux/media_url.rb', line 82

def key
  @key
end

#typeSymbol (readonly)

Returns the url's type

See Also:

  • MediaUrl.TYPES

78
79
80
# File 'lib/bbc/redux/media_url.rb', line 78

def type
  @type
end

Instance Method Details

#==(other_url) ⇒ Boolean Also known as: eql?


114
115
116
# File 'lib/bbc/redux/media_url.rb', line 114

def ==(other_url)
  self.class == other_url.class && self.end_point == other_url.end_point
end

#end_point(filename = nil) ⇒ String Also known as: to_s

Generate the end point to retreive media file


106
107
108
# File 'lib/bbc/redux/media_url.rb', line 106

def end_point(filename = nil)
  EndPoints.send(type, identifier, key.value, filename)
end

#expired?Boolean

Returns true if ttl <= 0, false otherwise

See Also:


# File 'lib/bbc/redux/media_url.rb', line 51

#live?Boolean

Returns true if ttl > 0, false otherwise

See Also:


# File 'lib/bbc/redux/media_url.rb', line 56

#ttlInteger

Returns url's time to live in seconds

See Also:


# File 'lib/bbc/redux/media_url.rb', line 61