Module: SonyCameraRemoteAPI::Client::ConfigUtils
Class Method Summary collapse
-
.default_camera(file) ⇒ Object
Get default selected camera.
-
.read_config_file(file, assert: true) ⇒ Hash
Read config file.
-
.save_ssdp_config(file, endpoints) ⇒ Object
Save endpoint information to config file if exists.
-
.write_config_file(file, yaml) ⇒ Object
Write config file.
Class Method Details
.default_camera(file) ⇒ Object
Get default selected camera.
18 19 20 21 22 23 24 25 26 |
# File 'lib/sony_camera_remote_api/client/config.rb', line 18 def default_camera(file) # check default camera in configuration file yaml = read_config_file file unless yaml.key?('default') puts 'Default camera is not selected!' return nil end yaml['camera'].find { |n| n['ssid'] == yaml['default'] } end |
.read_config_file(file, assert: true) ⇒ Hash
Read config file.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sony_camera_remote_api/client/config.rb', line 39 def read_config_file(file, assert: true) if File.exists? file YAML.load_file(file) else if assert puts 'Configuration file not found!' exit 1 end end end |
.save_ssdp_config(file, endpoints) ⇒ Object
Save endpoint information to config file if exists
29 30 31 32 33 34 |
# File 'lib/sony_camera_remote_api/client/config.rb', line 29 def save_ssdp_config(file, endpoints) yaml = read_config_file file config = yaml['camera'].find { |n| n['ssid'] == yaml['default'] } config['endpoints'] = endpoints write_config_file file, yaml end |
.write_config_file(file, yaml) ⇒ Object
Write config file
51 52 53 54 55 |
# File 'lib/sony_camera_remote_api/client/config.rb', line 51 def write_config_file(file, yaml) open(file, 'w') do |e| YAML.dump(yaml, e) end end |