kodi_client 0.6.3 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/README.md +1 -0
  4. data/kodi_client.gemspec +2 -2
  5. data/lib/kodi_client/extensions/chainable.rb +73 -0
  6. data/lib/kodi_client/extensions/comparable.rb +29 -0
  7. data/lib/kodi_client/extensions/creatable.rb +132 -0
  8. data/lib/kodi_client/extensions/iterable.rb +14 -0
  9. data/lib/kodi_client/kodi_error.rb +14 -0
  10. data/lib/kodi_client/kodi_method.rb +34 -0
  11. data/lib/kodi_client/{options.rb → kodi_options.rb} +1 -1
  12. data/lib/kodi_client/kodi_request.rb +16 -0
  13. data/lib/kodi_client/kodi_response.rb +21 -0
  14. data/lib/kodi_client/{method → methods}/addons.rb +6 -6
  15. data/lib/kodi_client/{method → methods}/application.rb +2 -2
  16. data/lib/kodi_client/methods/audio_library.rb +334 -0
  17. data/lib/kodi_client/{method → methods}/favourites.rb +2 -2
  18. data/lib/kodi_client/{method → methods}/files.rb +6 -10
  19. data/lib/kodi_client/{method → methods}/gui.rb +2 -2
  20. data/lib/kodi_client/{method → methods}/input.rb +2 -2
  21. data/lib/kodi_client/{method → methods}/player.rb +2 -2
  22. data/lib/kodi_client/{method → methods}/profiles.rb +5 -7
  23. data/lib/kodi_client/{method → methods}/system.rb +2 -2
  24. data/lib/kodi_client/methods/video_library.rb +18 -0
  25. data/lib/kodi_client/types/addons/addon_content_type.rb +18 -0
  26. data/lib/kodi_client/types/addons/addon_dependency_type.rb +21 -0
  27. data/lib/kodi_client/types/addons/addon_details_type.rb +44 -0
  28. data/lib/kodi_client/types/addons/addon_extra_info_type.rb +20 -0
  29. data/lib/kodi_client/types/addons/addon_fields_type.rb +28 -0
  30. data/lib/kodi_client/types/addons/addon_types_type.rb +48 -0
  31. data/lib/kodi_client/types/addons/get_addon_returned_type.rb +21 -0
  32. data/lib/kodi_client/types/addons/get_addons_returned_type.rb +22 -0
  33. data/lib/kodi_client/types/application/property_name_type.rb +19 -0
  34. data/lib/kodi_client/types/application/property_value_type.rb +24 -0
  35. data/lib/kodi_client/types/application/version_type.rb +22 -0
  36. data/lib/kodi_client/types/audio/audio_album_release_type_type.rb +15 -0
  37. data/lib/kodi_client/types/audio/audio_artist_role_type.rb +21 -0
  38. data/lib/kodi_client/types/audio/audio_contributor_type.rb +22 -0
  39. data/lib/kodi_client/types/audio/audio_details_album_type.rb +58 -0
  40. data/lib/kodi_client/types/audio/audio_details_artist_type.rb +53 -0
  41. data/lib/kodi_client/types/audio/audio_details_base_type.rb +30 -0
  42. data/lib/kodi_client/types/audio/audio_details_media_type.rb +50 -0
  43. data/lib/kodi_client/types/audio/audio_details_role_type.rb +25 -0
  44. data/lib/kodi_client/types/audio/audio_details_song_type.rb +72 -0
  45. data/lib/kodi_client/types/audio/audio_fields_album_type.rb +50 -0
  46. data/lib/kodi_client/types/audio/audio_fields_artist_type.rb +39 -0
  47. data/lib/kodi_client/types/audio/audio_fields_role_type.rb +15 -0
  48. data/lib/kodi_client/types/audio/audio_fields_song_type.rb +61 -0
  49. data/lib/kodi_client/types/audio/available_art_type.rb +21 -0
  50. data/lib/kodi_client/types/audio/genre_type.rb +20 -0
  51. data/lib/kodi_client/types/audio/get_albums_returned_type.rb +22 -0
  52. data/lib/kodi_client/types/audio/get_artists_returned_type.rb +23 -0
  53. data/lib/kodi_client/types/audio/get_genres_returned_type.rb +24 -0
  54. data/lib/kodi_client/types/audio/get_roles_returned_type.rb +25 -0
  55. data/lib/kodi_client/types/audio/get_songs_returned_type.rb +25 -0
  56. data/lib/kodi_client/types/audio/get_sources_return_type.rb +25 -0
  57. data/lib/kodi_client/types/audio/property_name_type.rb +25 -0
  58. data/lib/kodi_client/types/audio/property_value_type.rb +33 -0
  59. data/lib/kodi_client/types/favourites/details_favourite_type.rb +24 -0
  60. data/lib/kodi_client/types/favourites/fields_favourite_type.rb +17 -0
  61. data/lib/kodi_client/types/favourites/get_favourite_returned_type.rb +22 -0
  62. data/lib/kodi_client/types/favourites/type_type.rb +18 -0
  63. data/lib/kodi_client/types/files/file_label_type.rb +20 -0
  64. data/lib/kodi_client/types/files/get_directory_returned_type.rb +22 -0
  65. data/lib/kodi_client/types/files/get_sources_returned_type.rb +22 -0
  66. data/lib/kodi_client/types/files/media_type.rb +18 -0
  67. data/lib/kodi_client/types/files/prepare_download_returned_type.rb +21 -0
  68. data/lib/kodi_client/types/global/direction_type.rb +17 -0
  69. data/lib/kodi_client/types/global/global_time_type.rb +22 -0
  70. data/lib/kodi_client/types/global/id_label_type.rb +20 -0
  71. data/lib/kodi_client/types/global/id_name_type.rb +20 -0
  72. data/lib/kodi_client/types/global/increment_decrement_type.rb +15 -0
  73. data/lib/kodi_client/types/global/next_prev_type.rb +17 -0
  74. data/lib/kodi_client/types/global/password_encryption_type.rb +16 -0
  75. data/lib/kodi_client/types/global/rotate_type.rb +15 -0
  76. data/lib/kodi_client/types/global/toggle_type.rb +16 -0
  77. data/lib/kodi_client/types/gui/gui_window_type.rb +124 -0
  78. data/lib/kodi_client/types/gui/property_name_type.rb +18 -0
  79. data/lib/kodi_client/types/gui/property_value_type.rb +26 -0
  80. data/lib/kodi_client/types/gui/stereoscopy_mode_type.rb +31 -0
  81. data/lib/kodi_client/types/input/input_action_type.rb +212 -0
  82. data/lib/kodi_client/types/{item_types.rb → items/item_details_base_type.rb} +2 -4
  83. data/lib/kodi_client/types/library/library_details_genre_type.rb +27 -0
  84. data/lib/kodi_client/types/library/library_details_source_type.rb +26 -0
  85. data/lib/kodi_client/types/library/library_fields_genre_type.rb +17 -0
  86. data/lib/kodi_client/types/library/library_fields_source_type.rb +17 -0
  87. data/lib/kodi_client/types/list/list_field_files_type.rb +83 -0
  88. data/lib/kodi_client/types/list/list_fields_all_type.rb +96 -0
  89. data/lib/kodi_client/types/list/list_item_all_type.rb +70 -0
  90. data/lib/kodi_client/types/list/list_item_base_type.rb +141 -0
  91. data/lib/kodi_client/types/list/list_item_file_type.rb +66 -0
  92. data/lib/kodi_client/types/list/list_limits_returned_type.rb +23 -0
  93. data/lib/kodi_client/types/list/list_limits_type.rb +23 -0
  94. data/lib/kodi_client/types/list/list_sort_method_type.rb +54 -0
  95. data/lib/kodi_client/types/list/list_sort_type.rb +28 -0
  96. data/lib/kodi_client/types/list/sort_order_type.rb +15 -0
  97. data/lib/kodi_client/types/media/media_artwork_type.rb +26 -0
  98. data/lib/kodi_client/types/media/media_details_base_type.rb +29 -0
  99. data/lib/kodi_client/types/media/media_type_type.rb +16 -0
  100. data/lib/kodi_client/types/player/audio_stream_type.rb +29 -0
  101. data/lib/kodi_client/types/player/player_position_time_type.rb +22 -0
  102. data/lib/kodi_client/types/player/player_repeat_type.rb +17 -0
  103. data/lib/kodi_client/types/player/player_speed_type.rb +26 -0
  104. data/lib/kodi_client/types/player/player_type.rb +24 -0
  105. data/lib/kodi_client/types/player/player_type_type.rb +16 -0
  106. data/lib/kodi_client/types/player/player_view_mode_type.rb +23 -0
  107. data/lib/kodi_client/types/player/player_visibility_type.rb +16 -0
  108. data/lib/kodi_client/types/player/property_name_type.rb +38 -0
  109. data/lib/kodi_client/types/player/property_value_type.rb +60 -0
  110. data/lib/kodi_client/types/player/seek_jump_type.rb +17 -0
  111. data/lib/kodi_client/types/player/seek_returned_type.rb +23 -0
  112. data/lib/kodi_client/types/player/subtitle_type.rb +24 -0
  113. data/lib/kodi_client/types/player/video_stream_type.rb +26 -0
  114. data/lib/kodi_client/types/player/view_mode_type.rb +22 -0
  115. data/lib/kodi_client/types/player/zoom_type.rb +15 -0
  116. data/lib/kodi_client/types/profiles/details_profile_type.rb +24 -0
  117. data/lib/kodi_client/types/profiles/fields_profile_type.rb +15 -0
  118. data/lib/kodi_client/types/profiles/get_profiles_returned_type.rb +22 -0
  119. data/lib/kodi_client/types/profiles/profile_password_type.rb +20 -0
  120. data/lib/kodi_client/types/{pvr_type.rb → pvr/channel_type_type.rb} +2 -4
  121. data/lib/kodi_client/types/system/property_name_type.rb +17 -0
  122. data/lib/kodi_client/types/{system_types.rb → system/property_value_type.rb} +2 -13
  123. data/lib/kodi_client/types/video/stream_details_type.rb +24 -0
  124. data/lib/kodi_client/types/video/video_cast_type.rb +22 -0
  125. data/lib/kodi_client/types/video/video_content_type_type.rb +18 -0
  126. data/lib/kodi_client/types/video/video_details_base_type.rb +29 -0
  127. data/lib/kodi_client/types/video/video_details_file_type.rb +37 -0
  128. data/lib/kodi_client/types/video/video_details_item_type.rb +32 -0
  129. data/lib/kodi_client/types/video/video_details_media_type.rb +28 -0
  130. data/lib/kodi_client/types/video/video_resume_type.rb +20 -0
  131. data/lib/kodi_client.rb +160 -49
  132. metadata +132 -38
  133. data/lib/kodi_client/Chainable.rb +0 -48
  134. data/lib/kodi_client/kodi_module.rb +0 -80
  135. data/lib/kodi_client/method/audio_library.rb +0 -46
  136. data/lib/kodi_client/types/addon_types.rb +0 -177
  137. data/lib/kodi_client/types/application_types.rb +0 -52
  138. data/lib/kodi_client/types/audio_types.rb +0 -221
  139. data/lib/kodi_client/types/favourites_types.rb +0 -61
  140. data/lib/kodi_client/types/files_types.rb +0 -63
  141. data/lib/kodi_client/types/global_types.rb +0 -102
  142. data/lib/kodi_client/types/gui_types.rb +0 -179
  143. data/lib/kodi_client/types/input_types.rb +0 -214
  144. data/lib/kodi_client/types/list_types.rb +0 -542
  145. data/lib/kodi_client/types/media_types.rb +0 -53
  146. data/lib/kodi_client/types/player_type.rb +0 -294
  147. data/lib/kodi_client/types/profiles_types.rb +0 -65
  148. data/lib/kodi_client/types/video_types.rb +0 -150
  149. data/lib/kodi_client/util/comparable.rb +0 -20
  150. data/lib/kodi_client/util/creatable.rb +0 -106
  151. data/lib/kodi_client/util/iterable.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23953ca4422d697b3b13a223f63b339acc5d4d4fdb8c7accccdc5f0b7f85f9cb
4
- data.tar.gz: 92e3d514686cdddddcc16a1be9046ba56a8d31e039316fb98ab98dca45a864db
3
+ metadata.gz: 7963176234a4fca33e9f5cc70fc67839692434cb5f04e891f83ea8a93060e709
4
+ data.tar.gz: 727944649072314329aff155764d4cb2cdbc9f6ce506c9376a23b45cab233a8c
5
5
  SHA512:
6
- metadata.gz: 734b5574d16a2deac4a88f81f6d3b94f4a5cd9c769fbda34034a6f3b614c4a03b5c44f40060ad100d24e1a2e032de8ceb35107f6922a51fdc396d19db4207204
7
- data.tar.gz: 1cbb33466f364232765025183bb4336c03913ff1f1ff9887a18cd7f221b4cd5fac2640671a3213e2049533888044b551b5a4738ce7c2f0219b1fe21b6c15d3b6
6
+ metadata.gz: c2ff87b673fcde9ce38d543d6462412c9de1868c3ed2771145a90c515894af1822576259e5a81b6e531e6beceaa43dc3175e0ff7009fd427d033bee3d3d7aac0
7
+ data.tar.gz: a0b4e7461155e031e5ed9c5b2f2e1ece7afbd273ef1639b07b9a12222e51fe5670aa61641291197aff4ffa018fa9d4df4d36b28e3bc57ec3d3324856c1ac16a7
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/README.md CHANGED
@@ -5,6 +5,7 @@ RubyKodiClient is a work-in-progress client for [Kodi JSON API v12](https://kodi
5
5
  Currently implemented are the following Methods:
6
6
  * Addons
7
7
  * Application
8
+ * AudioLibrary
8
9
  * Favourites
9
10
  * Files
10
11
  * GUI
data/kodi_client.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'kodi_client'
5
- spec.version = '0.6.3'
5
+ spec.version = '0.7.2'
6
6
  spec.authors = ['Christian Feier']
7
7
  spec.email = ['christian.feier@gmail.com']
8
8
 
9
9
  spec.summary = 'A work-in-progress client for Kodi JSON API v2.'
10
- spec.description = 'A client for the Kodi JSON API v12, currently implemented methods are Addons, Application, '\
10
+ spec.description = 'A client for the Kodi JSON API v12, currently implemented methods are Addons, Application, AudioLibrary '\
11
11
  'Favourites, Files, GUI, Input, Player, Profiles and System (more will be added with the time). '\
12
12
  'For more information how to use it and how to activate Remote Control in Kodi, '\
13
13
  'please check the github page https://github.com/cfe86/RubyKodiClient'
@@ -0,0 +1,73 @@
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
+ raise ArgumentError, 'ip or port can\'t be nil.' if ip.nil? || port.nil?
17
+
18
+ @client = KodiClient::Client.new
19
+ merge_options(->(options) { options.with_connection(ip, port) })
20
+ end
21
+
22
+ # sets username and password if required
23
+ # @param username [String] the username
24
+ # @param password [String] the password
25
+ # @return [Client] the existing, or if not existed, a new created client
26
+ def auth(username, password)
27
+ raise ArgumentError, 'username or password can\'t be nil.' if username.nil? || password.nil?
28
+
29
+ merge_options(->(options) { options.with_auth(username, password) })
30
+ end
31
+
32
+ # enables/disables the use of TLS
33
+ # @param enabled [Boolean] true to enable it, false to disable
34
+ # @return [Client] the existing, or if not existed, a new created client
35
+ def use_tls(enabled: true)
36
+ merge_options(->(options) { options.with_tls(enabled) })
37
+ end
38
+
39
+ # merges the existing options with the new options
40
+ # @param [Proc] set_command so command to execute on the existing options to merge them
41
+ # @return [Client] the existing, or if not existed, a new created client
42
+ def merge_options(set_command)
43
+ client = def_client
44
+ options = def_options
45
+ set_command.call(options)
46
+ client.apply_options_to_methods(options)
47
+ client
48
+ end
49
+
50
+ # Creates a new, or if one already exists, returns the existing client
51
+ # @return [Client] the new or existing client
52
+ def def_client
53
+ if @client.nil?
54
+ @client = KodiClient::Client.new
55
+ @client.client = @client
56
+ end
57
+ @client
58
+ end
59
+
60
+ # Creates a new, or if one already exists, returns the existing Options
61
+ # @return [KodiOptions] the new or existing Options
62
+ def def_options
63
+ if @options.nil?
64
+ @options ||= KodiClient::KodiOptions.new
65
+ @client.options = @options
66
+ end
67
+ @options
68
+ end
69
+
70
+ private :def_client, :def_options, :merge_options
71
+ end
72
+ end
73
+ 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,132 @@
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.arr_to_mapping(it) }
24
+ end
25
+
26
+ def self.arr_to_mapping(arr)
27
+ Creatable::CreateMap.new(arr[1], arr[2].nil? ? false : arr[2])
28
+ end
29
+
30
+ # expects the given hash is a list of hashes and calls #create on each element
31
+ # @param [Array<Hash>] hash given list of hashes
32
+ # @return [Array] empty if hash is nil, otherwise array containing the elements
33
+ def create_list(hash)
34
+ hash.nil? ? [] : hash.map { |it| create(it) }.reject(&:nil?)
35
+ end
36
+
37
+ # creates a Creatable using the provided hash and the attr_reader fields, or if given #fields_to_map instead
38
+ # The parameters will be passed to initialize the object in the same order as they are passed to attr_reader
39
+ # or #fields_to_map
40
+ # @param hash [Hash, nil] the given hash to convert to an object
41
+ # @return the created object, or nil if the given hash is nil
42
+ def create(hash)
43
+ return nil if hash.nil?
44
+
45
+ if @fields_to_map.nil? || @fields_to_map.empty?
46
+ fields = @kodi_fields
47
+ return nil if @kodi_fields.none? { |it| !hash[it.to_s.gsub('_', '')].nil? }
48
+ else
49
+ fields = @fields_to_map
50
+ end
51
+
52
+ mapping = @type_mapping.nil? ? {} : @type_mapping
53
+ args = fields.map do |it|
54
+ field = it.to_s.gsub('_', '')
55
+ Creatable.extract_field_from_hash(field, hash, mapping)
56
+ end
57
+
58
+ new(*args)
59
+ end
60
+
61
+ # takes a hash and a list of strings and an optional mapping and creates a new array with the created objects
62
+ # of the hash and fields. If no mapping is provided, the value of this field is returned, otherwise the mapping is
63
+ # used
64
+ # @param hash [Hash] the given hash
65
+ # @param fields [Array<String>] the fields to extract
66
+ # @param mapping [Hash<String>, Array<Array<String>>] optional mapping if a field contains a complex type
67
+ # @return [Array] an array containing the values of hash[field] in the given field order
68
+ def self.hash_to_arr(hash, fields, mapping = {})
69
+ return nil if hash.nil?
70
+
71
+ mapping = mapping.map { |it| arr_to_mapping(it) } unless mapping.is_a?(Hash)
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
+ # extracts the given field from the given hash and optionally applies mapping if given
80
+ # @param field [String] the field name
81
+ # @param hash [Hash, nil] the hash where to extract the field from
82
+ # @param mapping [Hash<String, CreateMap>] optional mapping for complex types
83
+ # @return the extracted object or nil, if the hash is empty, or [] if the expected value was a list and was nil
84
+ def self.extract_field_from_hash(field, hash, mapping)
85
+ map = mapping[field]
86
+ return nil if hash[field].nil? && map.nil?
87
+
88
+ return hash[field] if map.nil?
89
+
90
+ return map.type.create_list(hash[field]) if map.is_list
91
+
92
+ map.type.create(hash[field])
93
+ end
94
+
95
+ def attr_accessor(*args)
96
+ attr_reader(*args)
97
+ attr_writer(*args)
98
+ end
99
+
100
+ def attr_reader(*args)
101
+ @kodi_fields = args.map { |it| it.to_s.gsub('_', '') }
102
+
103
+ args.each do |it|
104
+ inst_variable_name = "@#{it}".to_sym
105
+ define_method it do
106
+ instance_variable_get(inst_variable_name)
107
+ end
108
+ end
109
+ end
110
+
111
+ def attr_writer(*args)
112
+ args.each do |it|
113
+ inst_variable_name = "@#{it}".to_sym
114
+ define_method "#{it}=" do |new_value|
115
+ instance_variable_set(inst_variable_name, new_value)
116
+ end
117
+ end
118
+ end
119
+
120
+ # mapping class with the type and if it is a list field or not
121
+ class CreateMap
122
+
123
+ attr_reader :type, :is_list
124
+
125
+ def initialize(type, is_list = false)
126
+ @type = type
127
+ @is_list = is_list
128
+ end
129
+ end
130
+ end
131
+ end
132
+ 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,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KodiClient
4
- module Method
4
+ module Methods
5
5
  # contains all Kodi Application methods
6
- class Addons < KodiModule
6
+ class Addons < KodiMethod
7
7
 
8
8
  EXECUTE_ADDON = 'Addons.ExecuteAddon'
9
9
  GET_ADDON_DETAILS = 'Addons.GetAddonDetails'
@@ -13,18 +13,18 @@ module KodiClient
13
13
  def get_addons(type = Types::Addons::AddonTypes::UNKNOWN,
14
14
  content = Types::Addons::AddonContent::UNKNOWN,
15
15
  enabled = nil, properties = [],
16
- limit = Types::List::ListLimits.new(0, 50), installed = nil, kodi_id = 1)
16
+ limits = Types::List::ListLimits.new(0, 50), installed = nil, kodi_id = 1)
17
17
  request = KodiRequest.new(kodi_id, GET_ADDONS,
18
18
  {
19
19
  'type' => type,
20
20
  'content' => content,
21
21
  'enabled' => enabled.nil? || !enabled ? 'all' : 'enabled',
22
22
  'properties' => properties,
23
- 'limits' => { 'start' => limit.list_start, 'end' => limit.list_end },
23
+ 'limits' => limits.to_h,
24
24
  'installed' => installed.nil? || !installed ? 'all' : 'installed'
25
25
  })
26
26
  json = invoke_api(request)
27
- result = Types::Addons::Addons.create(json['result'])
27
+ result = Types::Addons::GetAddonsReturned.create(json['result'])
28
28
  json['result'] = result
29
29
  KodiResponse.new(json)
30
30
  end
@@ -34,7 +34,7 @@ module KodiClient
34
34
  'properties' => properties })
35
35
  json = invoke_api(request)
36
36
 
37
- result = Types::Addons::Addon.create(json['result'])
37
+ result = Types::Addons::GetAddonReturned.create(json['result'])
38
38
  json['result'] = result
39
39
  KodiResponse.new(json)
40
40
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KodiClient
4
- module Method
4
+ module Methods
5
5
  # contains all Kodi Application methods
6
- class Application < KodiModule
6
+ class Application < KodiMethod
7
7
 
8
8
  QUIT = 'Application.Quit'
9
9
  SET_MUTE = 'Application.SetMute'