Class: SonyCameraRemoteAPI::Shelf
- Inherits:
-
Object
- Object
- SonyCameraRemoteAPI::Shelf
- Includes:
- Utils
- Defined in:
- lib/sony_camera_remote_api/shelf.rb
Constant Summary collapse
- GLOBAL_CONFIG_FILE =
Default config file saved in home directory.
File.('~/.sonycamconf')
Instance Method Summary collapse
-
#add(ssid, pass, interface, overwrite: false) ⇒ Boolean
Add a camera config.
-
#connect(ssid = nil) ⇒ Boolean
Connect to the camera.
-
#get(ssid = nil) ⇒ Hash?
Get a camera config by SSID.
-
#get_all ⇒ Array<Hash>
Get all camera configs.
-
#get_by_index(index) ⇒ Hash?
Get a camera config by index.
-
#initialize(config_file = GLOBAL_CONFIG_FILE) ⇒ Shelf
constructor
Create CameraShelf object.
-
#remove(ssid) ⇒ Boolean
Remove a camera config.
-
#remove_all ⇒ Boolean
Remove all camera configs.
-
#remove_by_index(index) ⇒ Hash?
Remove a camera config by index.
-
#set_endpoints(endpoints, ssid = nil) ⇒ Boolean
Set endpoint information to a camera config.
-
#set_interface(interface, ssid = nil) ⇒ Boolean
Set interface by which the camera is connected.
-
#use(ssid) ⇒ Boolean
Select a camera config as default.
Methods included from Utils
generate_sequencial_filenames, get_next_file_number, partial_and_unique_match, print_array_in_columns
Constructor Details
#initialize(config_file = GLOBAL_CONFIG_FILE) ⇒ Shelf
Create CameraShelf object.
16 17 18 19 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 16 def initialize(config_file = GLOBAL_CONFIG_FILE) @config_file = config_file read_or_create end |
Instance Method Details
#add(ssid, pass, interface, overwrite: false) ⇒ Boolean
Add a camera config.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 56 def add(ssid, pass, interface, overwrite: false) # If input SSID is already registered, ask user to overwrite same_one = @config['camera'].find { |n| n['ssid'] == ssid } if same_one && !overwrite false else @config['camera'].delete_if { |c| c['ssid'] == ssid } @config['camera'] << { 'ssid' => ssid, 'pass' => pass, 'interface' => interface } if @config['camera'].size == 1 @config['default'] = ssid end write end end |
#connect(ssid = nil) ⇒ Boolean
Connect to the camera. If SSID is not given, default camera is used.
147 148 149 150 151 152 153 154 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 147 def connect(ssid = nil) entry = get(ssid) if entry Scripts.connect entry['interface'], entry['ssid'], entry['pass'] else false end end |
#get(ssid = nil) ⇒ Hash?
Get a camera config by SSID. You can use a partial string as long as it is unique. If SSID is not given, get the default camera config.
27 28 29 30 31 32 33 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 27 def get(ssid = nil) if ssid.nil? get_default else get_unique(ssid) end end |
#get_all ⇒ Array<Hash>
Get all camera configs.
48 49 50 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 48 def get_all @config['camera'] end |
#get_by_index(index) ⇒ Hash?
Get a camera config by index.
39 40 41 42 43 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 39 def get_by_index(index) if index.between? 0, @config['camera'].size - 1 @config['camera'][index] end end |
#remove(ssid) ⇒ Boolean
Remove a camera config.
74 75 76 77 78 79 80 81 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 74 def remove(ssid) entry = get_unique(ssid) if @config['camera'].delete entry write else false end end |
#remove_all ⇒ Boolean
Remove all camera configs.
99 100 101 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 99 def remove_all create end |
#remove_by_index(index) ⇒ Hash?
Remove a camera config by index.
87 88 89 90 91 92 93 94 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 87 def remove_by_index(index) if index.between? 0, @config['camera'].size - 1 @config['camera'].delete_at index write else false end end |
#set_endpoints(endpoints, ssid = nil) ⇒ Boolean
Set endpoint information to a camera config.
119 120 121 122 123 124 125 126 127 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 119 def set_endpoints(endpoints, ssid = nil) entry = get(ssid) if entry entry['endpoints'] = endpoints write else false end end |
#set_interface(interface, ssid = nil) ⇒ Boolean
Set interface by which the camera is connected.
132 133 134 135 136 137 138 139 140 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 132 def set_interface(interface, ssid = nil) entry = get(ssid) if entry entry['interface'] = interface write else false end end |
#use(ssid) ⇒ Boolean
Select a camera config as default.
106 107 108 109 110 111 112 113 114 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 106 def use(ssid) entry = get(ssid) if entry @config['default'] = entry['ssid'] write else false end end |