Class: KodiClient::Methods::Files

Inherits:
KodiMethod show all
Defined in:
lib/kodi_client/methods/files.rb

Overview

contains all Kodi Application methods

Constant Summary collapse

GET_DIRECTORY =
'Files.GetDirectory'
GET_FILE_DETAILS =
'Files.GetFileDetails'
GET_SOURCES =
'Files.GetSources'
PREPARE_DOWNLOAD =
'Files.PrepareDownload'
SET_FILE_DETAILS =
'Files.SetFileDetails'

Instance Method Summary collapse

Methods inherited from KodiMethod

#apply_options, #invoke_api

Instance Method Details

#get_directory(directory, media = Types::Files::Media::FILES, properties = Types::List::ListFieldFiles.all_properties, sort = Types::List::ListSort.new, limits = Types::List::ListLimits.new(0, 50), kodi_id = 1) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kodi_client/methods/files.rb', line 14

def get_directory(directory, media = Types::Files::Media::FILES,
                  properties = Types::List::ListFieldFiles.all_properties,
                  sort = Types::List::ListSort.new,
                  limits = Types::List::ListLimits.new(0, 50), kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_DIRECTORY,
                            {
                              'directory' => directory,
                              'media' => media,
                              'properties' => properties,
                              'sort' => sort.to_h,
                              'limits' => limits.to_h
                            })
  json = invoke_api(request)
  result = KodiClient::Types::Files::GetDirectoryReturned.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#get_file_details(file, media = Types::Files::Media::FILES, properties = Types::List::ListFieldFiles.all_properties, kodi_id = 1) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kodi_client/methods/files.rb', line 32

def get_file_details(file, media = Types::Files::Media::FILES,
                     properties = Types::List::ListFieldFiles.all_properties, kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_FILE_DETAILS,
                            {
                              'file' => file,
                              'media' => media,
                              'properties' => properties
                            })
  json = invoke_api(request)
  result = KodiClient::Types::List::ListItemFile.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#get_sources(media = Types::Files::Media::FILES, sort = Types::List::ListSort.new, limits = Types::List::ListLimits.new(0, 50), kodi_id = 1) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kodi_client/methods/files.rb', line 46

def get_sources(media = Types::Files::Media::FILES,
                sort = Types::List::ListSort.new,
                limits = Types::List::ListLimits.new(0, 50), kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_SOURCES,
                            {
                              'media' => media,
                              'sort' => sort.to_h,
                              'limits' => limits.to_h
                            })
  json = invoke_api(request)
  result = KodiClient::Types::Files::GetSourcesReturned.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#prepare_download(path, kodi_id = 1) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/kodi_client/methods/files.rb', line 61

def prepare_download(path, kodi_id = 1)
  request = KodiRequest.new(kodi_id, PREPARE_DOWNLOAD, { 'path' => path })
  json = invoke_api(request)
  result = KodiClient::Types::Files::PrepareDownloadReturned.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#set_file_details(file, media = Types::Files::Media::VIDEO, play_count = nil, last_played = nil, resume = nil, kodi_id = 1) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/kodi_client/methods/files.rb', line 69

def set_file_details(file, media = Types::Files::Media::VIDEO, play_count = nil, last_played = nil,
                     resume = nil, kodi_id = 1)
  params = { 'file' => file, 'media' => media}
  params['playcount'] = play_count unless play_count.nil?
  params['lastplayed'] = last_played unless last_played.nil?
  params['resume'] = resume unless resume.nil?
  request = KodiRequest.new(kodi_id, SET_FILE_DETAILS, params)
  json = invoke_api(request)
  KodiResponse.new(json)
end