Class: Plex::Client
- Inherits:
-
Object
- Object
- Plex::Client
- Defined in:
- lib/plex-ruby/client.rb
Constant Summary collapse
- NAV_METHODS =
%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
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(server, node) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#nav ⇒ True?
Navigation methods Sends a movement command to the client to move around menus and such.
- #play_file ⇒ Object
-
#play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil) ⇒ True?
Plays a video that is in the library.
-
#playback ⇒ True?
Playback methods Sends a playback command to the client to play / pause videos and such.
-
#screenshot(width, height, quality) ⇒ True?
Take a screenshot of whats on the Plex Client.
-
#send_key(code) ⇒ True?
Sends a key code to the Plex Client.
-
#send_string(text) ⇒ True?
Sends a string message to the Plex Client.
-
#send_virtual_key(code) ⇒ True?
Sends a key code to the Plex Client.
- #url ⇒ Object
Constructor Details
#initialize(server, node) ⇒ Client
Returns a new instance of Client.
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
#server ⇒ Object (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
#inspect ⇒ Object
129 130 131 |
# File 'lib/plex-ruby/client.rb', line 129 def inspect #:nodoc: "#<Plex::Client: name=\"#{name}\" host=\"#{host}\" port=\"#{port}\">" end |
#nav ⇒ True?
Navigation methods Sends a movement command to the client to move around menus and such
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_file ⇒ Object
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
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, = 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=#{}" if url += "&viewOffset=#{view_offset}" if view_offset ping url end |
#playback ⇒ True?
Playback methods Sends a playback command to the client to play / pause videos and such
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
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.
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
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.
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 |
#url ⇒ Object
124 125 126 |
# File 'lib/plex-ruby/client.rb', line 124 def url #:nodoc: server.url end |