Class: Airplay::Viewer

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

Overview

Public: The class to handle image broadcast to a device

Constant Summary collapse

UnsupportedType =
Class.new(TypeError)
TRANSITIONS =
%w(None Dissolve SlideLeft SlideRight)

Instance Method Summary collapse

Constructor Details

#initialize(device) ⇒ Viewer

Returns a new instance of Viewer.



11
12
13
14
# File 'lib/airplay/viewer.rb', line 11

def initialize(device)
  @device = device
  @logger = Airplay::Logger.new("airplay::viewer")
end

Instance Method Details

#transitionsObject

Public: The list of transitions

Returns the list of trasitions



43
# File 'lib/airplay/viewer.rb', line 43

def transitions; TRANSITIONS end

#view(media_or_io, options = {}) ⇒ Object

Public: Broadcasts the content to the device

media_or_io - The url, file path or io of the image/s options - Options that include the device

* transition: the type of transition (Default: None)

Returns if the images was actually sent



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

def view(media_or_io, options = {})
  content = get_content(media_or_io)
  transition = options.fetch(:transition, "None")

  @logger.info "Fetched content (#{content.bytesize} bytes)"
  @logger.debug "PUT /photo with transition: #{transition}"

  response = connection.put("/photo", content, {
    "Content-Length" => content.bytesize.to_s,
    "X-Apple-Transition" => transition
  })

  response.response.status == 200
end