class Kodi::NamespaceBuilder
Public Instance Methods
build_namespaces(method_groups = nil)
click to toggle source
Params
method_groups
(optional)-
A Hash where the key is the name of the created namespace and the value is an Array of the desired methods. A valid hash could be: {
'AudioLibrary' => ['GetArtists'], 'Input' => ['Up', 'Down', 'Left', 'Right', 'Select', 'Back'], 'Player' => ['GetActivePlayers', 'PlayPause']
} If left empty, the complete API will be requested from the server. This will cost an extra second or two, but ensures that you have all methods available.
# File lib/kodi/namespace_builder.rb, line 15 def build_namespaces(method_groups = nil) method_groups = to_structs(method_groups) if method_groups namespaces = (method_groups || api_method_groups).map do |name, methods| Namespace.new(uri, name, *methods) end namespaces.index_by(&:name) end
Private Instance Methods
api_introspect()
click to toggle source
# File lib/kodi/namespace_builder.rb, line 42 def api_introspect @api_introspect ||= RPC.new(uri).dispatch('JSONRPC.Introspect') end
api_method_groups()
click to toggle source
# File lib/kodi/namespace_builder.rb, line 32 def api_method_groups api_methods.group_by(&:namespace) end
api_methods()
click to toggle source
# File lib/kodi/namespace_builder.rb, line 36 def api_methods api_introspect['methods'].keys.map do |path| Struct.new(:namespace, :name).new(*path.split('.', 2)) end end
to_structs(method_groups)
click to toggle source
# File lib/kodi/namespace_builder.rb, line 26 def to_structs(method_groups) Hash[method_groups.map do |namespace, methods| [namespace, methods.map { |method| Struct.new(:namespace, :name).new(namespace, method) }] end] end