class Wdmc::Share
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/wdmc/shares.rb, line 7 def initialize(*args) @wdmc = Wdmc::Client.new @device_description = @wdmc.device_description super end
Public Instance Methods
create( name )
click to toggle source
# File lib/wdmc/shares.rb, line 49 def create( name ) share_exists = @wdmc.share_exists?( name ) abort "Share already exists!".color(:yellow) if share_exists.include?( name ) begin data = { :share_name => name, :description => options['description'], :media_serving => options['media_serving'], :public_access => options['public_access'], :samba_available => options['samba_available'], :share_access_locked => options['share_access_locked'], :grant_share_access => options['grant_share_access'] } puts "Create share:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.add_share( data ) rescue RestClient::ExceptionWithResponse => e e.response.each do |x| p x end end end
delete( name )
click to toggle source
# File lib/wdmc/shares.rb, line 96 def delete( name ) share_exists = @wdmc.share_exists?( name ) abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name ) unless options['force'] puts "\nDeleting this share will delete all content and configuration settings within the share!".color(:orange) puts "Are you sure you want to delete:\s".color(:orange) + "#{name}".color(:whitesmoke) return unless yes?("DELETE? (yes/no):") end puts "Delete share:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.delete_share( name ) end
list()
click to toggle source
# File lib/wdmc/shares.rb, line 14 def list shares = @wdmc.all_shares puts "Available Shares".upcase.color(:magenta) shares.each do |share| puts "\s- #{share[:share_name]}" end end
modify( name )
click to toggle source
# File lib/wdmc/shares.rb, line 76 def modify( name ) share_exists = @wdmc.share_exists?( name ) abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name ) begin data = { :share_name => name, :new_share_name => options['new_share_name'] || name, :description => options['description'], :media_serving => options['media_serving'], :public_access => options['public_access'], :remote_access => options['remote_access'] } puts "Modify share:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.modify_share( data ) rescue RestClient::ExceptionWithResponse => e puts e.response end end
show( name )
click to toggle source
# File lib/wdmc/shares.rb, line 23 def show( name ) shares = @wdmc.find_share( name ) share_exists = @wdmc.share_exists?( name ) abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name ) shares.each do |share| puts "Name:\s".upcase.color(:magenta) + share[:share_name] puts "\sRemote Access\t\t: ".color(:whitesmoke) + "#{share[:remote_access]}" puts "\sPublic Access\t\t: ".color(:whitesmoke) + "#{share[:public_access]}" puts "\sMedia Serving\t\t: ".color(:whitesmoke) + "#{share[:media_serving]}" if share[:share_access] puts "Permissions\t\t ".upcase.color(:magenta) share[:share_access].map do |access| puts "\s#{access[:username]}\t\t\t:\s" + access[:access].color(:green) if access[:access] == 'RW' puts "\s#{access[:username]}\t\t\t:\s" + access[:access].color(:cyan) if access[:access] == 'RO' end end end end