Skip to content
Browse files

a

  • Loading branch information...
1 parent 791509f commit 7ca06b9afbc90edd9b0b6c5d38820d0e1c09ab76 @swistaczek committed Mar 30, 2013
Showing with 72 additions and 71 deletions.
  1. +71 −70 lib/network_manager/modem.rb
  2. +1 −1 ruby-network-manager.gemspec
View
141 lib/network_manager/modem.rb
@@ -1,94 +1,95 @@
# encoding: utf-8
-class NetworkManager::Modem
- attr_reader :bus_path, :service
+class NetworkManager
+ class Modem
+ attr_reader :bus_path, :service
- def initialize(opts)
- args.each do |k,v|
- instance_variable_set("@#{k}", v) unless v.nil?
- end
-
- # Set DBUS proxy
- @proxy = @service.object(@bus_path)
- @proxy.introspect
+ def initialize(opts)
+ args.each do |k,v|
+ instance_variable_set("@#{k}", v) unless v.nil?
+ end
+
+ # Set DBUS proxy
+ @proxy = @service.object(@bus_path)
+ @proxy.introspect
- @properties = @proxy.dup
- @properties.default_iface = NetworkManager::DBUS_PROPERTIES
- @properties.introspect
+ @properties = @proxy.dup
+ @properties.default_iface = NetworkManager::DBUS_PROPERTIES
+ @properties.introspect
- @s_modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_SIMPLE]
- @modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM]
- @network = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_NETWORK]
- @ussd = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_USSD]
+ @s_modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_SIMPLE]
+ @modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM]
+ @network = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_NETWORK]
+ @ussd = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_USSD]
- @device_info = @properties.GetInfo[0] rescue nil
- end
+ @device_info = @properties.GetInfo[0] rescue nil
+ end
- def enabled?
- begin
- status
- return true
- rescue => e
- return !e.message.include?('device is not enabled')
+ def enabled?
+ begin
+ status
+ return true
+ rescue => e
+ return !e.message.include?('device is not enabled')
+ end
+ nil
end
- nil
- end
- def enable!
- @modem.Enable(true) if disabled?
- end
+ def enable!
+ @modem.Enable(true) if disabled?
+ end
- def disabled?
- !enabled?
- end
+ def disabled?
+ !enabled?
+ end
- def disable!
- @modem.Enable(false) if enabled?
- end
+ def disable!
+ @modem.Enable(false) if enabled?
+ end
- def model
- @device_info[1] rescue nil
- end
+ def model
+ @device_info[1] rescue nil
+ end
- def status
- @s_modem.GetStatus[0]
- end
+ def status
+ @s_modem.GetStatus[0]
+ end
- def operator_code
- status["operator_code"] rescue nil
- end
+ def operator_code
+ status["operator_code"] rescue nil
+ end
- def vendor
- @device_info[0] rescue nil
- end
+ def vendor
+ @device_info[0] rescue nil
+ end
- def version
- @device_info[2] rescue nil
- end
+ def version
+ @device_info[2] rescue nil
+ end
- def signal
- @properties.GetSignalQuality[0] rescue 0
- end
+ def signal
+ @properties.GetSignalQuality[0] rescue 0
+ end
- def imei
- @properties.GetImei[0] rescue nil
- end
+ def imei
+ @properties.GetImei[0] rescue nil
+ end
- def imsi
- @properties.GetImsi[0] rescue nil
- end
+ def imsi
+ @properties.GetImsi[0] rescue nil
+ end
- def scan
- @network.Scan[0] rescue nil
- end
+ def scan
+ @network.Scan[0] rescue nil
+ end
- class << self
- def fetch(paths_array, opts = {})
- devices = []
- paths_array.compact.reject {|x| x && x.size <= 0 }.each do |path|
- devices << self.new(opts.merge({bus_path: path}))
+ class << self
+ def fetch(paths_array, opts = {})
+ devices = []
+ paths_array.compact.reject {|x| x && x.size <= 0 }.each do |path|
+ devices << self.new(opts.merge({bus_path: path}))
+ end
+ devices
end
- devices
end
end
-
end
View
2 ruby-network-manager.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = "ruby-network-manager"
- s.version = "0.3.0"
+ s.version = "0.4.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ernest Bursa"]

0 comments on commit 7ca06b9

Please sign in to comment.
Something went wrong with that request. Please try again.