Class: Ralyxa::ResponseEntities::Directives::Audio::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/ralyxa/response_entities/directives/audio/stream.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, token, offset_in_milliseconds = 0, expected_previous_token = nil) ⇒ Stream

Returns a new instance of Stream.



6
7
8
9
10
11
12
13
# File 'lib/ralyxa/response_entities/directives/audio/stream.rb', line 6

def initialize(url, token, offset_in_milliseconds = 0, expected_previous_token = nil)
  raise Ralyxa::UnsecureUrlError, "Audio streams must be served from at an SSL-enabled (HTTPS) endpoint. Your current stream url is: #{url}" unless secure?(url)

  @url                     = url
  @token                   = token
  @offset_in_milliseconds  = offset_in_milliseconds
  @expected_previous_token = expected_previous_token
end

Class Method Details

.as_hash(url, token, offset_in_milliseconds = 0, expected_previous_token = nil) ⇒ Object



24
25
26
# File 'lib/ralyxa/response_entities/directives/audio/stream.rb', line 24

def self.as_hash(url, token, offset_in_milliseconds = 0, expected_previous_token = nil)
  new(url, token, offset_in_milliseconds, expected_previous_token).to_h
end

Instance Method Details

#to_hObject



15
16
17
18
19
20
21
22
# File 'lib/ralyxa/response_entities/directives/audio/stream.rb', line 15

def to_h
  {}.tap do |stream|
    stream['url']                   = @url
    stream['token']                 = @token
    stream['offsetInMilliseconds']  = @offset_in_milliseconds
    stream['expectedPreviousToken'] = @expected_previous_token if @expected_previous_token
  end
end