Class: Wdmc::Share
Instance Method Summary collapse
- #create(name) ⇒ Object
- #delete(name) ⇒ Object
-
#initialize(*args) ⇒ Share
constructor
A new instance of Share.
- #list ⇒ Object
- #modify(name) ⇒ Object
- #show(name) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Share
Returns a new instance of Share.
7 8 9 10 11 |
# File 'lib/wdmc/shares.rb', line 7 def initialize(*args) @wdmc = Wdmc::Client.new @device_description = @wdmc.device_description super end |
Instance Method Details
#create(name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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 => ['description'], :media_serving => ['media_serving'], :public_access => ['public_access'], :samba_available => ['samba_available'], :share_access_locked => ['share_access_locked'], :grant_share_access => ['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) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# 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 ['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 ⇒ Object
14 15 16 17 18 19 20 |
# 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) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 => ['new_share_name'] || name, :description => ['description'], :media_serving => ['media_serving'], :public_access => ['public_access'], :remote_access => ['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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |