Module: XBMC_JSONRPC
- Defined in:
- lib/xbmc-jsonrpc.rb
Overview
The XBMC_JSONRPC module is a namespace / wrapper
Defined Under Namespace
Classes: APIBase, AudioLibrary, AudioPlayer, AudioPlaylist, Connection, Files, JSONRPC, PicturePlayer, Player, Playlist, System, VideoLibrary, VideoPlayer, VideoPlaylist, XBMC
Class Method Summary collapse
-
.apropos(find) ⇒ Object
finds and prettily prints appropriate commands based on provided keyword.
-
.command(method, args = {}) ⇒ Object
Make an API call to the instance XBMC server.
-
.commands ⇒ Object
returns all available commands returned by JSON.Introspect.
-
.get_commands ⇒ Object
nicely print out all available commands.
-
.new(options = {}) ⇒ Object
Attempt to create connection with xbmc server, and retrieve available commands.
-
.pp_command(command) ⇒ Object
prettily print out requested command.
Class Method Details
.apropos(find) ⇒ Object
finds and prettily prints appropriate commands based on provided keyword
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xbmc-jsonrpc.rb', line 57 def self.apropos(find) regexp = /#{find}/im matches = [] @commands.each do |k,v| matches.push(k) if k =~ regexp || v['description'] =~ regexp end if matches.empty? puts "\n\nNo commands found, try being less specific\n\n" else matches.each {|command| self.pp_command command } end return nil end |
.command(method, args = {}) ⇒ Object
Make an API call to the instance XBMC server
40 41 42 |
# File 'lib/xbmc-jsonrpc.rb', line 40 def self.command(method,args = {}) @connection.command(method, args) end |
.commands ⇒ Object
returns all available commands returned by JSON.Introspect
45 46 47 |
# File 'lib/xbmc-jsonrpc.rb', line 45 def self.commands @commands end |
.get_commands ⇒ Object
nicely print out all available commands. useful at command line / irb / etc
51 52 53 54 |
# File 'lib/xbmc-jsonrpc.rb', line 51 def self.get_commands @commands.each {|k,v| self.pp_command k } return nil end |
.new(options = {}) ⇒ Object
Attempt to create connection with xbmc server, and retrieve available commands. Accepts connection information arguments and if successful returns a new connection
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xbmc-jsonrpc.rb', line 24 def self.new( = {}) @connection = XBMC_JSONRPC::Connection.new() if @connection.command('JSONRPC.Ping') commands = @connection.command('JSONRPC.Introspect')['result']['commands'] @commands = {} commands.each do |command| command_name = command.shift[1] @commands[command_name] = command end return self end return false end |
.pp_command(command) ⇒ Object
prettily print out requested command
72 73 74 75 76 77 78 |
# File 'lib/xbmc-jsonrpc.rb', line 72 def self.pp_command(command) description = @commands[command]['description'] description = "<no description exists for #{command}>" unless !description.empty? puts "\n\t#{command}" puts "\t\t#{description}\n\n" end |