kodi_client 0.6.0 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/kodi_client.gemspec +1 -1
  4. data/lib/kodi_client/extensions/chainable.rb +71 -0
  5. data/lib/kodi_client/extensions/comparable.rb +29 -0
  6. data/lib/kodi_client/extensions/creatable.rb +137 -0
  7. data/lib/kodi_client/extensions/iterable.rb +14 -0
  8. data/lib/kodi_client/kodi_error.rb +14 -0
  9. data/lib/kodi_client/kodi_method.rb +34 -0
  10. data/lib/kodi_client/{options.rb → kodi_options.rb} +1 -1
  11. data/lib/kodi_client/kodi_request.rb +16 -0
  12. data/lib/kodi_client/kodi_response.rb +21 -0
  13. data/lib/kodi_client/{method → methods}/addons.rb +9 -24
  14. data/lib/kodi_client/{method → methods}/application.rb +2 -5
  15. data/lib/kodi_client/methods/audio_library.rb +46 -0
  16. data/lib/kodi_client/{method → methods}/favourites.rb +2 -5
  17. data/lib/kodi_client/{method → methods}/files.rb +2 -6
  18. data/lib/kodi_client/{method → methods}/gui.rb +2 -5
  19. data/lib/kodi_client/{method → methods}/input.rb +2 -6
  20. data/lib/kodi_client/{method → methods}/player.rb +2 -7
  21. data/lib/kodi_client/{method → methods}/profiles.rb +2 -5
  22. data/lib/kodi_client/{method → methods}/system.rb +2 -6
  23. data/lib/kodi_client/types/addons/addon_content_type.rb +18 -0
  24. data/lib/kodi_client/types/addons/addon_dependency_type.rb +21 -0
  25. data/lib/kodi_client/types/addons/addon_details_type.rb +44 -0
  26. data/lib/kodi_client/types/addons/addon_extra_info_type.rb +20 -0
  27. data/lib/kodi_client/types/addons/addon_fields_type.rb +28 -0
  28. data/lib/kodi_client/types/addons/addon_types_type.rb +48 -0
  29. data/lib/kodi_client/types/addons/get_addon_returned_type.rb +21 -0
  30. data/lib/kodi_client/types/addons/get_addons_returned_type.rb +22 -0
  31. data/lib/kodi_client/types/application/property_name_type.rb +19 -0
  32. data/lib/kodi_client/types/application/property_value_type.rb +24 -0
  33. data/lib/kodi_client/types/application/version_type.rb +22 -0
  34. data/lib/kodi_client/types/audio/audio_album_release_type_type.rb +15 -0
  35. data/lib/kodi_client/types/audio/audio_contributor_type.rb +22 -0
  36. data/lib/kodi_client/types/audio/audio_details_base_type.rb +31 -0
  37. data/lib/kodi_client/types/audio/audio_details_media_type.rb +45 -0
  38. data/lib/kodi_client/types/audio/audio_fields_album_type.rb +51 -0
  39. data/lib/kodi_client/types/audio/details_album_type.rb +58 -0
  40. data/lib/kodi_client/types/audio/genre_type.rb +20 -0
  41. data/lib/kodi_client/types/audio/get_albums_returned_type.rb +22 -0
  42. data/lib/kodi_client/types/favourites/details_favourite_type.rb +24 -0
  43. data/lib/kodi_client/types/favourites/fields_favourite_type.rb +17 -0
  44. data/lib/kodi_client/types/favourites/get_favourite_returned_type.rb +22 -0
  45. data/lib/kodi_client/types/favourites/type_type.rb +18 -0
  46. data/lib/kodi_client/types/files/file_label_type.rb +20 -0
  47. data/lib/kodi_client/types/files/get_directory_returned_type.rb +22 -0
  48. data/lib/kodi_client/types/files/get_sources_returned_type.rb +22 -0
  49. data/lib/kodi_client/types/files/media_type.rb +18 -0
  50. data/lib/kodi_client/types/files/prepare_download_returned_type.rb +21 -0
  51. data/lib/kodi_client/types/global/direction_type.rb +17 -0
  52. data/lib/kodi_client/types/global/global_time_type.rb +22 -0
  53. data/lib/kodi_client/types/global/id_label_type.rb +20 -0
  54. data/lib/kodi_client/types/global/id_name_type.rb +20 -0
  55. data/lib/kodi_client/types/global/increment_decrement_type.rb +15 -0
  56. data/lib/kodi_client/types/global/next_prev_type.rb +17 -0
  57. data/lib/kodi_client/types/global/password_encryption_type.rb +16 -0
  58. data/lib/kodi_client/types/global/rotate_type.rb +15 -0
  59. data/lib/kodi_client/types/global/toggle_type.rb +16 -0
  60. data/lib/kodi_client/types/gui/gui_window_type.rb +124 -0
  61. data/lib/kodi_client/types/gui/property_name_type.rb +18 -0
  62. data/lib/kodi_client/types/gui/property_value_type.rb +26 -0
  63. data/lib/kodi_client/types/gui/stereoscopy_mode_type.rb +31 -0
  64. data/lib/kodi_client/types/input/input_action_type.rb +212 -0
  65. data/lib/kodi_client/{global_types/item_types.rb → types/items/item_details_base_type.rb} +5 -3
  66. data/lib/kodi_client/types/list/list_field_files_type.rb +83 -0
  67. data/lib/kodi_client/types/list/list_fields_all_type.rb +96 -0
  68. data/lib/kodi_client/types/list/list_item_all_type.rb +73 -0
  69. data/lib/kodi_client/types/list/list_item_base_type.rb +138 -0
  70. data/lib/kodi_client/types/list/list_item_file_type.rb +68 -0
  71. data/lib/kodi_client/types/list/list_limits_returned_type.rb +23 -0
  72. data/lib/kodi_client/types/list/list_limits_type.rb +19 -0
  73. data/lib/kodi_client/types/list/list_sort_method_type.rb +54 -0
  74. data/lib/kodi_client/types/list/list_sort_type.rb +22 -0
  75. data/lib/kodi_client/types/list/sort_order_type.rb +15 -0
  76. data/lib/kodi_client/types/media/media_artwork_type.rb +22 -0
  77. data/lib/kodi_client/types/media/media_details_base_type.rb +28 -0
  78. data/lib/kodi_client/types/media/media_type_type.rb +16 -0
  79. data/lib/kodi_client/types/player/audio_stream_type.rb +29 -0
  80. data/lib/kodi_client/types/player/player_position_time_type.rb +22 -0
  81. data/lib/kodi_client/types/player/player_repeat_type.rb +17 -0
  82. data/lib/kodi_client/types/player/player_speed_type.rb +26 -0
  83. data/lib/kodi_client/types/player/player_type.rb +24 -0
  84. data/lib/kodi_client/types/player/player_type_type.rb +16 -0
  85. data/lib/kodi_client/types/player/player_view_mode_type.rb +23 -0
  86. data/lib/kodi_client/types/player/player_visibility_type.rb +16 -0
  87. data/lib/kodi_client/types/player/property_name_type.rb +38 -0
  88. data/lib/kodi_client/types/player/property_value_type.rb +60 -0
  89. data/lib/kodi_client/types/player/seek_jump_type.rb +17 -0
  90. data/lib/kodi_client/types/player/seek_returned_type.rb +23 -0
  91. data/lib/kodi_client/types/player/subtitle_type.rb +24 -0
  92. data/lib/kodi_client/types/player/video_stream_type.rb +26 -0
  93. data/lib/kodi_client/types/player/view_mode_type.rb +22 -0
  94. data/lib/kodi_client/types/player/zoom_type.rb +15 -0
  95. data/lib/kodi_client/types/profiles/details_profile_type.rb +24 -0
  96. data/lib/kodi_client/types/profiles/fields_profile_type.rb +15 -0
  97. data/lib/kodi_client/types/profiles/get_profiles_returned_type.rb +22 -0
  98. data/lib/kodi_client/types/profiles/profile_password_type.rb +20 -0
  99. data/lib/kodi_client/{global_types/pvr_type.rb → types/pvr/channel_type_type.rb} +2 -6
  100. data/lib/kodi_client/types/system/property_name_type.rb +17 -0
  101. data/lib/kodi_client/{global_types/system_types.rb → types/system/property_value_type.rb} +2 -16
  102. data/lib/kodi_client/types/video/stream_details_type.rb +24 -0
  103. data/lib/kodi_client/types/video/video_cast_type.rb +22 -0
  104. data/lib/kodi_client/types/video/video_details_base_type.rb +29 -0
  105. data/lib/kodi_client/types/video/video_details_file_type.rb +37 -0
  106. data/lib/kodi_client/types/video/video_details_item_type.rb +32 -0
  107. data/lib/kodi_client/types/video/video_details_media_type.rb +28 -0
  108. data/lib/kodi_client/types/video/video_resume_type.rb +20 -0
  109. data/lib/kodi_client.rb +137 -23
  110. metadata +107 -33
  111. data/lib/kodi_client/Chainable.rb +0 -49
  112. data/lib/kodi_client/global_types/addon_types.rb +0 -194
  113. data/lib/kodi_client/global_types/application_types.rb +0 -61
  114. data/lib/kodi_client/global_types/audio_types.rb +0 -88
  115. data/lib/kodi_client/global_types/favourites_types.rb +0 -70
  116. data/lib/kodi_client/global_types/files_types.rb +0 -82
  117. data/lib/kodi_client/global_types/global_types.rb +0 -106
  118. data/lib/kodi_client/global_types/gui_types.rb +0 -191
  119. data/lib/kodi_client/global_types/input_types.rb +0 -216
  120. data/lib/kodi_client/global_types/list_types.rb +0 -569
  121. data/lib/kodi_client/global_types/media_types.rb +0 -55
  122. data/lib/kodi_client/global_types/player_type.rb +0 -319
  123. data/lib/kodi_client/global_types/profiles_types.rb +0 -80
  124. data/lib/kodi_client/global_types/video_types.rb +0 -145
  125. data/lib/kodi_client/kodi_module.rb +0 -87
  126. data/lib/kodi_client/util/comparable.rb +0 -20
  127. data/lib/kodi_client/util/creatable.rb +0 -52
  128. data/lib/kodi_client/util/iterable.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5686743b785e5b591798992689064cec6c1e0d48a54721b97d9d28ae5a97ded3
4
- data.tar.gz: fc7516af1d65c10ef63897253979bdb67b8d74f6f11bb74c959ccc942f8c026e
3
+ metadata.gz: a3459e42458d3c4ec86456bd1e5ab18261a636ca9a61a48b6d2db3dbb0706b72
4
+ data.tar.gz: a1c20cd980f8c5c63fe69652e737495313110268b184cf2b58cf88ff850908b4
5
5
  SHA512:
6
- metadata.gz: ed6fbc05813a0f0a606c08c2e18606603af576e06f4af5941912097b477ad0a622a5ea7f47c7ce52062188b38522d60522337a06261d23f6894f5e1fbb6480c6
7
- data.tar.gz: fb200b6342ff5a29d291d60e8c8e61d53de6012bcc5b29058e16ae2eee8d3df9583ed7e8f6f78a72a2da02481d74e9e48d6dbc945dbad73ed85526e711220532
6
+ metadata.gz: 707936b7399a44bb81e2a8efe79700c4267f74ed9f1307503d7f073ac1111b929169cb90bf412cfd615881cd0d92e06e044d4acb09930a059d3b09cfcfd3b215
7
+ data.tar.gz: 0c5779c4534c5b8a65d571764d0ecfb4cfb1defbc868c499cc977a98783f095fcd96ecf2a829e0fa278565c46e91eb312647b2ab5933f92e4fe19d4a257f7898
data/.rubocop.yml CHANGED
@@ -12,5 +12,7 @@ Metrics/MethodLength:
12
12
  Enabled: false
13
13
  Metrics/PerceivedComplexity:
14
14
  Enabled: false
15
+ Metrics/ModuleLength:
16
+ Enabled: false
15
17
  Style/OptionalBooleanParameter:
16
18
  Enabled: false
data/kodi_client.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'kodi_client'
5
- spec.version = '0.6.0'
5
+ spec.version = '0.6.4'
6
6
  spec.authors = ['Christian Feier']
7
7
  spec.email = ['christian.feier@gmail.com']
8
8
 
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Extensions
5
+ # Offers methods like connect, auth and tls to be chained together
6
+ module Chainable
7
+
8
+ attr_accessor :options, :client
9
+
10
+ # Creates a new Client instance and sets the given ip and port to connect to it
11
+ # @param ip [String] the ip to use
12
+ # @param port [Integer] the port to connect to
13
+ # @raise [ArgumentError] thrown if ip or port is nil
14
+ # @return [Client] the created client
15
+ def connect(ip, port)
16
+ throw ArgumentError('ip or port can\'t be nil.') if ip.nil? || port.nil?
17
+ @client = KodiClient::Client.new
18
+ merge_options(->(options) { options.with_connection(ip, port) })
19
+ end
20
+
21
+ # sets username and password if required
22
+ # @param username [String] the username
23
+ # @param password [String] the password
24
+ # @return [Client] the existing, or if not existed, a new created client
25
+ def auth(username, password)
26
+ throw ArgumentError('username or password can\'t be nil.') if username.nil? || password.nil?
27
+ merge_options(->(options) { options.with_auth(username, password) })
28
+ end
29
+
30
+ # enables/disables the use of TLS
31
+ # @param enabled [Boolean] true to enable it, false to disable
32
+ # @return [Client] the existing, or if not existed, a new created client
33
+ def use_tls(enabled: true)
34
+ merge_options(->(options) { options.with_tls(enabled) })
35
+ end
36
+
37
+ # merges the existing options with the new options
38
+ # @param [Proc] set_command so command to execute on the existing options to merge them
39
+ # @return [Client] the existing, or if not existed, a new created client
40
+ def merge_options(set_command)
41
+ client = def_client
42
+ options = def_options
43
+ set_command.call(options)
44
+ client.apply_options_to_methods(options)
45
+ client
46
+ end
47
+
48
+ # Creates a new, or if one already exists, returns the existing client
49
+ # @return [Client] the new or existing client
50
+ def def_client
51
+ if @client.nil?
52
+ @client = KodiClient::Client.new
53
+ @client.client = @client
54
+ end
55
+ @client
56
+ end
57
+
58
+ # Creates a new, or if one already exists, returns the existing Options
59
+ # @return [KodiOptions] the new or existing Options
60
+ def def_options
61
+ if @options.nil?
62
+ @options ||= KodiClient::KodiOptions.new
63
+ @client.options = @options
64
+ end
65
+ @options
66
+ end
67
+
68
+ private :def_client, :def_options, :merge_options
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Extensions
5
+ # offers compare methods
6
+ module Comparable
7
+
8
+ # compares the instance variables of 2 objects for equality
9
+ # @param obj1 object 1
10
+ # @param obj2 object 2
11
+ # @return [Boolean] true if both instance variables are the same, else false
12
+ def compare(obj1, obj2)
13
+ is_same = true
14
+ obj1.instance_variables.each do |it|
15
+ is_same = false if obj1.instance_variable_get(it) != obj2.instance_variable_get(it)
16
+ end
17
+
18
+ is_same
19
+ end
20
+
21
+ # compares all Comparables using the defined compare method
22
+ # @param other [Object] the object to compare with
23
+ # @return [Boolean] true if equal, else false
24
+ def ==(other)
25
+ compare(self, other)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Extensions
5
+ # creates a create and create_list method by hash
6
+ module Creatable
7
+
8
+ # sets the fields to fetch from the given hash for the #create method. This is optional and only to use, if
9
+ # more fields should be fetched than are provided using attr_reader
10
+ # @param [Array<String>] fields the fields given as a string array
11
+ def fields_to_map(fields)
12
+ @fields_to_map = fields
13
+ end
14
+
15
+ # defines mappings in case an attribute in the hash is not primitive and requires further processing. The argument
16
+ # is an Array of Arrays. Each array contains ['field_name', [type_to_map_to], [opt if field is a list]]
17
+ # @param args [Array<Array>] mappings. Example mapping ['art', Media::ArtWork, true], in this case
18
+ # Media::ArtWork.create_list will be called
19
+ def type_mapping(*args)
20
+ return if args.nil?
21
+
22
+ @type_mapping = {}
23
+ args.map { |it| @type_mapping[it[0]] = Creatable::CreateMap.new(it[1], it[2].nil? ? false : it[2]) }
24
+ end
25
+
26
+ # if @type_mapping is nil, it tries to fetch the mapping from here instead
27
+ # @return [Hash<String, CreateMap>] an hash containing all the mappings
28
+ def lazy_type_mapping
29
+ {}
30
+ end
31
+
32
+ # expects the given hash is a list of hashes and calls #create on each element
33
+ # @param [Array<Hash>] hash given list of hashes
34
+ # @return [Array] empty if hash is nil, otherwise array containing the elements
35
+ def create_list(hash)
36
+ hash.nil? ? [] : hash.map { |it| create(it) }.reject(&:nil?)
37
+ end
38
+
39
+ # creates a Creatable using the provided hash and the attr_reader fields, or if given #fields_to_map instead
40
+ # The parameters will be passed to initialize the object in the same order as they are passed to attr_reader
41
+ # or #fields_to_map
42
+ # @param hash [Hash] the given hash to convert to an object
43
+ # @return the created object, or nil if the given hash is nil
44
+ def create(hash)
45
+ return nil if hash.nil?
46
+
47
+ if @fields_to_map.nil? || @fields_to_map.empty?
48
+ fields = @kodi_fields
49
+ return nil if @kodi_fields.none? { |it| !hash[it.to_s.gsub('_', '')].nil? }
50
+ else
51
+ fields = @fields_to_map
52
+ end
53
+
54
+ mapping = @type_mapping.nil? ? lazy_type_mapping : @type_mapping
55
+ args = fields.map do |it|
56
+ field = it.to_s.gsub('_', '')
57
+ Creatable.extract_field_from_hash(field, hash, mapping)
58
+ end
59
+
60
+ new(*args)
61
+ end
62
+
63
+ # takes a hash and a list of strings and an optional mapping and creates a new array with the created objects
64
+ # of the hash and fields. If no mapping is provided, the value of this field is returned, otherwise the mapping is
65
+ # used
66
+ # @param hash [Hash] the given hash
67
+ # @param fields [Array<String>] the fields to extract
68
+ # @param mapping [Hash<String, CreateMap>] optional mapping if a field contains a complex type
69
+ # @return [Array] an array containing the values of hash[field] in the given field order
70
+ def self.hash_to_arr(hash, fields, mapping = {})
71
+ return nil if hash.nil?
72
+
73
+ fields.map do |it|
74
+ field = it.to_s.gsub('_', '')
75
+ extract_field_from_hash(field, hash, mapping)
76
+ end
77
+ end
78
+
79
+ # map to self.hash_to_arr. The mapping is taken from #type_mapping
80
+ def hash_to_arr(hash, fields)
81
+ Creatable.hash_to_arr(hash, fields, @type_mapping.nil? ? {} : @type_mapping)
82
+ end
83
+
84
+ # extracts the given field from the given hash and optionally applies mapping if given
85
+ # @param field [String] the field name
86
+ # @param hash [Hash] the hash where to extract the field from
87
+ # @param mapping [Hash<String, CreateMap>] optional mapping for complex types
88
+ # @return the extracted object or nil, if the hash is empty, or [] if the expected value was a list and was nil
89
+ def self.extract_field_from_hash(field, hash, mapping)
90
+ map = mapping[field]
91
+ return nil if hash[field].nil? && map.nil?
92
+
93
+ return hash[field] if map.nil?
94
+
95
+ return map.type.create_list(hash[field]) if map.is_list
96
+
97
+ map.type.create(hash[field])
98
+ end
99
+
100
+ def attr_accessor(*args)
101
+ attr_reader(*args)
102
+ attr_writer(*args)
103
+ end
104
+
105
+ def attr_reader(*args)
106
+ @kodi_fields = args.map { |it| it.to_s.gsub('_', '') }
107
+
108
+ args.each do |it|
109
+ inst_variable_name = "@#{it}".to_sym
110
+ define_method it do
111
+ instance_variable_get(inst_variable_name)
112
+ end
113
+ end
114
+ end
115
+
116
+ def attr_writer(*args)
117
+ args.each do |it|
118
+ inst_variable_name = "@#{it}".to_sym
119
+ define_method "#{it}=" do |new_value|
120
+ instance_variable_set(inst_variable_name, new_value)
121
+ end
122
+ end
123
+ end
124
+
125
+ # mapping class with the type and if it is a list field or not
126
+ class CreateMap
127
+
128
+ attr_reader :type, :is_list
129
+
130
+ def initialize(type, is_list = false)
131
+ @type = type
132
+ @is_list = is_list
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Extensions
5
+ # offers iterable methods
6
+ module Iterable
7
+
8
+ # @return [Array<String>] returns all constant values if sorted order
9
+ def all_properties
10
+ constants.map { |it| const_get(it) }.sort!
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ # represents an error response
5
+ class KodiError
6
+ include Extensions::Comparable
7
+ attr_reader :code, :message
8
+
9
+ def initialize(hash)
10
+ @code = hash['code']
11
+ @message = hash['message']
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+
5
+ # the client that stores
6
+ class KodiMethod
7
+
8
+ def apply_options(options)
9
+ @endpoint_url = "#{options.tls ? 'https://' : 'http://'}#{options.ip}:#{options.port}/jsonrpc"
10
+ @options = options
11
+ end
12
+
13
+ def invoke_api(request)
14
+ h = request.instance_variables.each_with_object({}) do |var, hash|
15
+ hash[var.to_s.delete('@')] = request.instance_variable_get(var)
16
+ end
17
+
18
+ @http_client ||= build_client
19
+ response = @http_client.post(@endpoint_url, json: h).to_s
20
+ JSON.parse(response)
21
+ end
22
+
23
+ def build_client
24
+ client = HTTP.headers(Content_Type: 'application/json')
25
+ if !@options.username.nil? && !@options.password.nil?
26
+ client = client.basic_auth({ user: @options.username, pass: @options.password })
27
+ end
28
+
29
+ client
30
+ end
31
+
32
+ private :build_client
33
+ end
34
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module KodiClient
4
4
  # holds all options like ip, port, credentials
5
- class Options
5
+ class KodiOptions
6
6
 
7
7
  attr_accessor :ip, :port, :username, :password, :tls
8
8
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ # represents a kodi requests
5
+ class KodiRequest
6
+
7
+ attr_accessor :id, :jsonrpc, :method, :params
8
+
9
+ def initialize(kodi_id, method, params = {}, jsonrpc = '2.0')
10
+ @id = kodi_id
11
+ @jsonrpc = jsonrpc
12
+ @method = method
13
+ @params = params
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ # represents a kodi response
5
+ class KodiResponse
6
+ include Extensions::Comparable
7
+
8
+ attr_reader :id, :jsonrpc, :result, :error
9
+
10
+ def initialize(hash)
11
+ @id = hash['id']
12
+ @jsonrpc = hash['jsonrpc']
13
+ @result = hash['result']
14
+ @error = KodiError.new(hash['error']) unless hash['error'].nil?
15
+ end
16
+
17
+ def error?
18
+ !@error.nil?
19
+ end
20
+ end
21
+ end
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/kodi_module'
4
- require 'kodi_client/global_types/addon_types'
5
- require 'kodi_client/global_types/list_types'
6
-
7
3
  module KodiClient
8
- module Modules
4
+ module Methods
9
5
  # contains all Kodi Application methods
10
- class Addons < KodiModule
6
+ class Addons < KodiMethod
11
7
 
12
8
  EXECUTE_ADDON = 'Addons.ExecuteAddon'
13
9
  GET_ADDON_DETAILS = 'Addons.GetAddonDetails'
@@ -28,41 +24,30 @@ module KodiClient
28
24
  'installed' => installed.nil? || !installed ? 'all' : 'installed'
29
25
  })
30
26
  json = invoke_api(request)
31
- result = Types::Addons::Addons.create(json['result'])
27
+ result = Types::Addons::GetAddonsReturned.create(json['result'])
32
28
  json['result'] = result
33
29
  KodiResponse.new(json)
34
30
  end
35
31
 
36
32
  def get_addon_details(addon_id = nil, properties = [], kodi_id = 1)
37
- request = KodiRequest.new(kodi_id, GET_ADDON_DETAILS,
38
- {
39
- 'addonid' => addon_id,
40
- 'properties' => properties
41
- })
33
+ request = KodiRequest.new(kodi_id, GET_ADDON_DETAILS, { 'addonid' => addon_id,
34
+ 'properties' => properties })
42
35
  json = invoke_api(request)
43
36
 
44
- result = Types::Addons::Addon.create(json['result'])
37
+ result = Types::Addons::GetAddonReturned.create(json['result'])
45
38
  json['result'] = result
46
39
  KodiResponse.new(json)
47
40
  end
48
41
 
49
42
  def execute_addon(addon_id = nil, params = '', wait = false, kodi_id = 1)
50
- request = KodiRequest.new(kodi_id, EXECUTE_ADDON,
51
- {
52
- 'addonid' => addon_id,
53
- 'params' => params,
54
- 'wait' => wait
55
- })
43
+ request = KodiRequest.new(kodi_id, EXECUTE_ADDON, { 'addonid' => addon_id, 'params' => params,
44
+ 'wait' => wait })
56
45
  json = invoke_api(request)
57
46
  KodiResponse.new(json)
58
47
  end
59
48
 
60
49
  def set_addon_enabled(addon_id = nil, enabled = Types::Global::Toggle::TOGGLE, kodi_id = 1)
61
- request = KodiRequest.new(kodi_id, SET_ADDON_ENABLED,
62
- {
63
- 'addonid' => addon_id,
64
- 'enabled' => enabled
65
- })
50
+ request = KodiRequest.new(kodi_id, SET_ADDON_ENABLED, { 'addonid' => addon_id, 'enabled' => enabled })
66
51
  json = invoke_api(request)
67
52
  KodiResponse.new(json)
68
53
  end
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/kodi_module'
4
- require 'kodi_client/global_types/application_types'
5
-
6
3
  module KodiClient
7
- module Modules
4
+ module Methods
8
5
  # contains all Kodi Application methods
9
- class Application < KodiModule
6
+ class Application < KodiMethod
10
7
 
11
8
  QUIT = 'Application.Quit'
12
9
  SET_MUTE = 'Application.SetMute'
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Methods
5
+ # contains all Kodi Application methods
6
+ class AudioLibrary < KodiMethod
7
+
8
+ CLEAN = 'AudioLibrary.Clean'
9
+ EXPORT = 'AudioLibrary.Export'
10
+ GET_ALBUM_DETAILS = 'AudioLibrary.GetAlbumDetails'
11
+ GET_ALBUMS = 'AudioLibrary.GetAlbums'
12
+
13
+ def clean(show_dialogs = true, kodi_id = 1)
14
+ request = KodiRequest.new(kodi_id, CLEAN, { 'showdialogs' => show_dialogs })
15
+ json = invoke_api(request)
16
+ KodiResponse.new(json)
17
+ end
18
+
19
+ def export(path, kodi_id = 1)
20
+ request = KodiRequest.new(kodi_id, EXPORT, { 'options' => { 'path' => path } })
21
+ json = invoke_api(request)
22
+ KodiResponse.new(json)
23
+ end
24
+
25
+ def get_album_details(album_id, properties = Types::Audio::AudioFieldsAlbum.all_properties, kodi_id = 1)
26
+ request = KodiRequest.new(kodi_id, GET_ALBUM_DETAILS, { 'albumid' => album_id, 'properties' => properties })
27
+ json = invoke_api(request)
28
+ KodiResponse.new(json)
29
+ end
30
+
31
+ def get_albums(properties = Types::Audio::AudioFieldsAlbum.all_properties,
32
+ limits = Types::List::ListLimits.new(0, 50),
33
+ sort = Types::List::ListSort.new, include_singles = false, all_roles = false, kodi_id = 1)
34
+ request = KodiRequest.new(kodi_id, GET_ALBUMS,
35
+ { 'properties' => properties,
36
+ 'limits' => { 'start' => limits.list_start, 'end' => limits.list_end },
37
+ 'sort' => { 'ignorearticle' => sort.ignore_article, 'method' => sort.method,
38
+ 'order' => sort.order,
39
+ 'useartistsortname' => sort.use_artist_sort_name },
40
+ 'includesingles' => include_singles, 'allroles' => all_roles })
41
+ json = invoke_api(request)
42
+ KodiResponse.new(json)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/kodi_module'
4
- require 'kodi_client/global_types/favourites_types'
5
-
6
3
  module KodiClient
7
- module Modules
4
+ module Methods
8
5
  # contains all Kodi Application methods
9
- class Favourites < KodiModule
6
+ class Favourites < KodiMethod
10
7
 
11
8
  ADD_FAVOURITE = 'Favourites.AddFavourite'
12
9
  GET_FAVOURITES = 'Favourites.GetFavourites'
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/kodi_module'
4
- require 'kodi_client/global_types/files_types'
5
- require 'kodi_client/global_types/list_types'
6
-
7
3
  module KodiClient
8
- module Modules
4
+ module Methods
9
5
  # contains all Kodi Application methods
10
- class Files < KodiModule
6
+ class Files < KodiMethod
11
7
 
12
8
  GET_DIRECTORY = 'Files.GetDirectory'
13
9
  GET_FILE_DETAILS = 'Files.GetFileDetails'
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/global_types/gui_types'
4
- require 'kodi_client/kodi_module'
5
-
6
3
  module KodiClient
7
- module Modules
4
+ module Methods
8
5
  # contains all Kodi GUI methods
9
- class GUI < KodiModule
6
+ class GUI < KodiMethod
10
7
 
11
8
  ACTIVATE_WINDOW = 'GUI.ActivateWindow'
12
9
  GET_PROPERTIES = 'GUI.GetProperties'
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/global_types/gui_types'
4
- require 'kodi_client/kodi_module'
5
- require 'kodi_client/global_types/input_types'
6
-
7
3
  module KodiClient
8
- module Modules
4
+ module Methods
9
5
  # contains all Kodi Input methods
10
- class Input < KodiModule
6
+ class Input < KodiMethod
11
7
 
12
8
  BACK = 'Input.Back'
13
9
  CONTEXT_MENU = 'Input.ContextMenu'
@@ -1,14 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/kodi_module'
4
- require 'kodi_client/global_types/addon_types'
5
- require 'kodi_client/global_types/list_types'
6
- require 'kodi_client/global_types/player_type'
7
-
8
3
  module KodiClient
9
- module Modules
4
+ module Methods
10
5
  # contains all Kodi Application methods
11
- class Player < KodiModule
6
+ class Player < KodiMethod
12
7
 
13
8
  ADD_SUBTITLE = 'Player.AddSubtitle'
14
9
  OPEN = 'Player.Open'
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/kodi_module'
4
- require 'kodi_client/global_types/profiles_types'
5
-
6
3
  module KodiClient
7
- module Modules
4
+ module Methods
8
5
  # contains all Kodi Application methods
9
- class Profiles < KodiModule
6
+ class Profiles < KodiMethod
10
7
 
11
8
  GET_CURRENT_PROFILE = 'Profiles.GetCurrentProfile'
12
9
  GET_PROFILES = 'Profiles.GetProfiles'
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/global_types/gui_types'
4
- require 'kodi_client/kodi_module'
5
- require 'kodi_client/global_types/system_types'
6
-
7
3
  module KodiClient
8
- module Modules
4
+ module Methods
9
5
  # contains all Kodi System methods
10
- class System < KodiModule
6
+ class System < KodiMethod
11
7
 
12
8
  EJECT_OPTICAL_DRIVE = 'System.EjectOpticalDrive'
13
9
  GET_PROPERTIES = 'System.GetProperties'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Types
5
+ module Addons
6
+ # Addon.Content https://kodi.wiki/view/JSON-RPC_API/v12#Addon.Content
7
+ module AddonContent
8
+ extend Extensions::Iterable
9
+
10
+ UNKNOWN = 'unknown'
11
+ AUDIO = 'audio'
12
+ EXECUTABLE = 'executable'
13
+ IMAGE = 'image'
14
+ VIDEO = 'video'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ module Types
5
+ module Addons
6
+ # Addon.Details.dependencies https://kodi.wiki/view/JSON-RPC_API/v12#Addon.Details
7
+ class AddonDependency
8
+ include Extensions::Comparable
9
+ extend Extensions::Creatable
10
+
11
+ attr_reader :addon_id, :optional, :version
12
+
13
+ def initialize(addon_id, optional, version)
14
+ @addon_id = addon_id
15
+ @optional = optional
16
+ @version = version
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end