Class: SonyCameraRemoteAPI::Shelf
- Inherits:
-
Object
- Object
- SonyCameraRemoteAPI::Shelf
- Includes:
- Utils
- Defined in:
- lib/sony_camera_remote_api/shelf.rb
Overview
Class for handling multiple camera’s connection configurations.
Constant Summary collapse
- GLOBAL_CONFIG_FILE =
Default config file saved in home directory.
File. '~/.sonycam.shelf'
Instance Method Summary collapse
-
#add(ssid, pass, interface, overwrite: false) ⇒ Boolean
Add a camera config.
-
#add_and_select(ssid, pass, interface, overwrite: false) ⇒ Boolean
Add a camera config, and select it.
-
#connect(ssid = nil) ⇒ Boolean
Connect to the camera.
-
#ep(ssid = nil) ⇒ Boolean
Get endpoint information to a camera config.
-
#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.
-
#reconnect(ssid = nil) ⇒ Boolean
Restart interface, and then connect to the camera.
-
#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.
-
#select(ssid) ⇒ Boolean
Select a camera config as default.
-
#set_ep(endpoints, ssid = nil) ⇒ Boolean
Set endpoint information to a camera config.
-
#set_if(interface, ssid = nil) ⇒ Boolean
Set interface by which the camera is connected.
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.
17 18 19 20 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 17 def initialize(config_file = GLOBAL_CONFIG_FILE) @config_file = File. config_file read_or_create end |
Instance Method Details
#add(ssid, pass, interface, overwrite: false) ⇒ Boolean
Add a camera config.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 57 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 |
#add_and_select(ssid, pass, interface, overwrite: false) ⇒ Boolean
Add a camera config, and select it
121 122 123 124 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 121 def add_and_select(ssid, pass, interface, overwrite: false) add ssid, pass, interface, overwrite: overwrite select ssid end |
#connect(ssid = nil) ⇒ Boolean
Connect to the camera. If SSID is not given, default camera is used.
169 170 171 172 173 174 175 176 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 169 def connect(ssid = nil) entry = get(ssid) if entry Scripts.connect entry['ssid'], entry['pass'], entry['interface'] else false end end |
#ep(ssid = nil) ⇒ Boolean
Get endpoint information to a camera config.
142 143 144 145 146 147 148 149 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 142 def ep(ssid = nil) entry = get(ssid) if entry entry['endpoints'] else nil 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.
28 29 30 31 32 33 34 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 28 def get(ssid = nil) if ssid.nil? get_default else get_unique(ssid) end end |
#get_all ⇒ Array<Hash>
Get all camera configs.
49 50 51 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 49 def get_all @config['camera'] end |
#get_by_index(index) ⇒ Hash?
Get a camera config by index.
40 41 42 43 44 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 40 def get_by_index(index) if index.between? 0, @config['camera'].size - 1 @config['camera'][index] end end |
#reconnect(ssid = nil) ⇒ Boolean
Restart interface, and then connect to the camera. If SSID is not given, default camera is used.
183 184 185 186 187 188 189 190 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 183 def reconnect(ssid = nil) entry = get(ssid) if entry Scripts.restart_and_connect entry['ssid'], entry['pass'], entry['interface'] else false end end |
#remove(ssid) ⇒ Boolean
Remove a camera config.
75 76 77 78 79 80 81 82 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 75 def remove(ssid) entry = get_unique(ssid) if @config['camera'].delete entry write else false end end |
#remove_all ⇒ Boolean
Remove all camera configs.
100 101 102 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 100 def remove_all create end |
#remove_by_index(index) ⇒ Hash?
Remove a camera config by index.
88 89 90 91 92 93 94 95 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 88 def remove_by_index(index) if index.between? 0, @config['camera'].size - 1 @config['camera'].delete_at index write else false end end |
#select(ssid) ⇒ Boolean
Select a camera config as default.
107 108 109 110 111 112 113 114 115 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 107 def select(ssid) entry = get(ssid) if entry @config['default'] = entry['ssid'] write else false end end |
#set_ep(endpoints, ssid = nil) ⇒ Boolean
Set endpoint information to a camera config.
129 130 131 132 133 134 135 136 137 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 129 def set_ep(endpoints, ssid = nil) entry = get(ssid) if entry entry['endpoints'] = endpoints write else false end end |
#set_if(interface, ssid = nil) ⇒ Boolean
Set interface by which the camera is connected.
154 155 156 157 158 159 160 161 162 |
# File 'lib/sony_camera_remote_api/shelf.rb', line 154 def set_if(interface, ssid = nil) entry = get(ssid) if entry entry['interface'] = interface write else false end end |