Class: Plex::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/plex-ruby/client.rb

Constant Summary collapse

%w(moveUp moveDown moveLeft moveRight pageUp pageDown nextLetter
previousLetter select back contextMenu toggleOSD)
PLAYBACK_METHODS =
%w(play pause stop rewind fastForward stepForward
bigStepForward stepBack bigStepBack skipNext skipPrevious)
ATTRIBUTES =
%w(name host address port machineIdentifier version)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, node) ⇒ Client

Returns a new instance of Client.

Parameters:

  • server (Server)

    this client belongs to

  • nokogiri (Nokogiri::XML::Element)

    element to build from



18
19
20
21
22
23
# File 'lib/plex-ruby/client.rb', line 18

def initialize(server, node)
  @server = server
  ATTRIBUTES.each { |e|
    instance_variable_set("@#{Plex.underscore(e)}", node.attr(e))
  }
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



13
14
15
# File 'lib/plex-ruby/client.rb', line 13

def server
  @server
end

Instance Method Details

#inspectObject



129
130
131
# File 'lib/plex-ruby/client.rb', line 129

def inspect #:nodoc:
  "#<Plex::Client: name=\"#{name}\" host=\"#{host}\" port=\"#{port}\">"
end

Navigation methods Sends a movement command to the client to move around menus and such

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



30
31
32
33
34
35
36
# File 'lib/plex-ruby/client.rb', line 30

NAV_METHODS.each { |nav|
  class_eval %(
    def #{Plex.underscore(nav)}
      ping player_url+'/navigation/#{nav}'
    end
  )
}

#play_fileObject



51
52
53
# File 'lib/plex-ruby/client.rb', line 51

def play_file
  ping player_url+"/application/playFile"
end

#play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil) ⇒ True?

Plays a video that is in the library

Parameters:

  • the (String, Object)

    key of the video that we want to play. Or an Object that responds to :key (see Episode#key) (see Movie#key)

  • no (String)

    clue what this does, its the Plex Remote Command API though

  • no (String)

    clue what this does, its the Plex Remote Command API though

  • no (String)

    clue what this does, its the Plex Remote Command API though

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/plex-ruby/client.rb', line 64

def play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil)

  if !key.is_a?(String) && key.respond_to?(:key)
    key = key.key
  end

  url = player_url+'/application/playMedia?'
  url += "path=#{CGI::escape(server.url+key)}"
  url += "&key=#{CGI::escape(key)}"
  url += "&userAgent=#{user_agent}" if user_agent
  url += "&httpCookies=#{http_cookies}" if http_cookies
  url += "&viewOffset=#{view_offset}" if view_offset

  ping url
end

#playbackTrue?

Playback methods Sends a playback command to the client to play / pause videos and such

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



43
44
45
46
47
48
49
# File 'lib/plex-ruby/client.rb', line 43

PLAYBACK_METHODS.each { |playback|
  class_eval %(
    def #{Plex.underscore(playback)}
      ping player_url+'/playback/#{playback}'
    end
  )
}

#screenshot(width, height, quality) ⇒ True?

Take a screenshot of whats on the Plex Client

Parameters:

  • width (String, Fixnum)

    of the screenshot

  • height (String, Fixnum)

    of the screenshot

  • quality (String, Fixnum)

    of the screenshot

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



87
88
89
90
91
92
93
94
# File 'lib/plex-ruby/client.rb', line 87

def screenshot(width, height, quality)
  url = player_url+'/application/screenshot?'
  url += "width=#{width}"
  url += "&height=#{height}"
  url += "&quality=#{quality}"

  ping url
end

#send_key(code) ⇒ True?

Sends a key code to the Plex Client. Key codes represent key presses on a keyboard. Codes are the ASCII value of the letter one wants pressed. It should be noted that the Plex devs have told people to try and avoid using this method when writing plugins, as different users can have different key mappings.

Parameters:

  • key (String, Fixnum)

    code to send

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



114
115
116
# File 'lib/plex-ruby/client.rb', line 114

def send_key(code)
  ping player_url+"/application/sendKey?code=#{CGI::escape(code.to_s)}"
end

#send_string(text) ⇒ True?

Sends a string message to the Plex Client

Parameters:

  • message (String)

    to send

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



101
102
103
# File 'lib/plex-ruby/client.rb', line 101

def send_string(text)
  ping player_url+"/application/sendString?text=#{CGI::escape(text.to_s)}"
end

#send_virtual_key(code) ⇒ True?

Sends a key code to the Plex Client. Key codes represent key presses on a keyboard. Codes are the ASCII value of the letter one wants pressed. It should be noted that the Plex devs have told people to try and avoid using this method when writing plugins, as different users can have different key mappings.

Parameters:

  • key (String, Fixnum)

    code to send

Returns:

  • (True, nil)

    true if it worked, nil if something went wrong check the console for the error message



119
120
121
# File 'lib/plex-ruby/client.rb', line 119

def send_virtual_key(code)
  ping player_url+"/application/sendVirtualKey?code=#{CGI::escape(code.to_s)}"
end

#urlObject



124
125
126
# File 'lib/plex-ruby/client.rb', line 124

def url #:nodoc:
  server.url
end