Class: NgiAPI
- Inherits:
-
Object
- Object
- NgiAPI
- Defined in:
- lib/ngi_api.rb,
lib/ngi_api/version.rb
Overview
This is the main class, holding all of the functions and checks. The instance it’s built with a hash of arguments.
Constant Summary collapse
- VERSION =
gem version
"0.0.3"
Instance Method Summary collapse
-
#infoBts(btsID) ⇒ Object
call-seq: MyNGIAccess.infoBts(btsID) => … Obtain the exact informations about a specific BTS.
-
#infoCoverage(via, civico, istat) ⇒ Object
call-seq: MyNGIAccess.infoCoverage(via,civico,istat) => … Gets the coverage for the specified address.
-
#infoRadio(macAddresses_clientLogins) ⇒ Object
call-seq: MyNGIAccess.infoRadio(macAddresses_clientLogins) => … Status of a radio, obtained as a string or an array of a client login/mac address.
-
#initialize(args) ⇒ NgiAPI
constructor
call-seq: MyNGIAccess = NgiAPI.new(arguments) .
-
#listBts ⇒ Object
call-seq: MyNGIAccess.listBts => {} Obtain a hash of active BTSes with their details.
-
#listComuni(comune) ⇒ Object
call-seq: MyNGIAccess.listComuni(comune) => {} Obtain the istat code for the town.
-
#rebootRadio(macAddress) ⇒ Object
call-seq: MyNGIAccess.rebootRadio(macAddress) => true Reboot a customer’s radio.
-
#setEthernet(macAddress, statoEthernet) ⇒ Object
call-seq: MyNGIAccess.setEthernet(macAddress,statoEthernet) => :stato_ethernet=>true Set the ethernet adapter of a customer’s radio.
Constructor Details
#initialize(args) ⇒ NgiAPI
call-seq:
MyNGIAccess = NgiAPI.new(arguments)
Initialize the class instance with a hash of arguments. The hash is mandatory and must not be empty. There’s a test mode and a production live mode.
Test mode
arguments[:test] = true
Puts any operation in test mode, with standard login and password and a different wsdl.
arguments[:debug] = true
The :debug can be set to true for improved stdout logging.
Production mode
arguments[:partnerLogin] = "13243546"
arguments[:partnerPassword] = "randomsaltprovidedbyNGI"
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ngi_api.rb', line 28 def initialize(args) raise ArgumentError, "no arguments provided, no idea what to do" if args.empty? raise ArgumentError, "\"test\" option provided with login and/or password - can't do that" if args[:test] && (!!args[:partnerLogin] || !!args[:partnerPassword]) raise ArgumentError, "you must give both a login and a password." if !!args[:partnerLogin] ^ !!args[:partnerPassword] @partnerLogin = !!args[:test] ? "12345678" : parameter_to_string(args[:partnerLogin]) @partnerPassword = !!args[:test] ? "517fc7b578767ebfa6bb5252252653d2" : parameter_to_string(args[:partnerPassword]) fetch_cacert unless File.exist?('cacert.pem') @soapClient = Savon.client do wsdl !!args[:test] ? "https://www.eolo.it/ws/wsdl/?test" : "https://www.eolo.it/ws/wsdl" ssl_ca_cert_file "cacert.pem" if args[:debug] log true log_level :debug pretty_print_xml true end end end |
Instance Method Details
#infoBts(btsID) ⇒ Object
call-seq:
MyNGIAccess.infoBts(btsID) => {...}
Obtain the exact informations about a specific BTS. btsID is a non-negative integer.
89 90 91 92 93 94 95 96 |
# File 'lib/ngi_api.rb', line 89 def infoBts(btsID) raise ArgumentError, "btsID value not allowed" unless btsID.to_i > 0 && btsID.class.to_s == "Fixnum" build_and_send_query(:info_bts, { btsID: parameter_to_string(btsID) } ) end |
#infoCoverage(via, civico, istat) ⇒ Object
call-seq:
MyNGIAccess.infoCoverage(via,civico,istat) => {...}
Gets the coverage for the specified address. The address is composed of
-
via
the street location -
civico
the number -
istat
the istat code for the town, gathered from listComuni
105 106 107 108 109 110 111 112 113 |
# File 'lib/ngi_api.rb', line 105 def infoCoverage(via,civico,istat) build_and_send_query(:info_coverage, { via: parameter_to_string(via), civico: parameter_to_string(civico), istat: parameter_to_string(istat) } ) end |
#infoRadio(macAddresses_clientLogins) ⇒ Object
call-seq:
MyNGIAccess.infoRadio(macAddresses_clientLogins) => {...}
Status of a radio, obtained as a string or an array of a client login/mac address.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ngi_api.rb', line 56 def infoRadio(macAddresses_clientLogins) macAddressArray = [] clientLoginArray = [] case macAddresses_clientLogins.class.to_s when "Array" raise ArgumentError,"array exceeds 20 elements" if macAddresses_clientLogins.size > 20 macAddresses_clientLogins.each_with_index do |element,index| raise ArgumentError, "value #{element} at position #{index} is not a valid mac address or a login" unless is_valid_mac(element) || is_valid_login(element) macAddressArray.push(fix_mac_address(element)) if is_valid_mac(element) clientLoginArray.push(fix_login(element)) if is_valid_login(element) end when "String" raise ArgumentError,"the single value to check is not a valid mac address or customer login" unless is_valid_mac(macAddresses_clientLogins) || is_valid_login(macAddresses_clientLogins) macAddressArray.push(fix_mac_address(macAddresses_clientLogins)) if is_valid_mac(macAddresses_clientLogins) clientLoginArray.push(fix_login(macAddresses_clientLogins)) if is_valid_login(macAddresses_clientLogins) else raise ArgumentError,"unsupported data type: a single mac address or login string or an array of them are the only allowed types." end build_and_send_query(:info_radio, { macAddressList: macAddressArray, clientLoginList: clientLoginArray } ) end |
#listBts ⇒ Object
call-seq:
MyNGIAccess.listBts => {}
Obtain a hash of active BTSes with their details. No input needed, lots of output to be expected.
119 120 121 |
# File 'lib/ngi_api.rb', line 119 def listBts build_and_send_query(:list_bts) end |
#listComuni(comune) ⇒ Object
call-seq:
MyNGIAccess.listComuni(comune) => {}
Obtain the istat code for the town.
127 128 129 130 131 132 133 134 |
# File 'lib/ngi_api.rb', line 127 def listComuni(comune) raise ArgumentError, "comune is not >=2 and <= 35 in length, or has not allowed characters" unless is_valid_comune(parameter_to_string(comune)) build_and_send_query(:list_comuni, { comune: parameter_to_string(comune) } ) end |
#rebootRadio(macAddress) ⇒ Object
call-seq:
MyNGIAccess.rebootRadio(macAddress) => {esito: true}
Reboot a customer’s radio.
155 156 157 158 159 160 161 162 |
# File 'lib/ngi_api.rb', line 155 def rebootRadio(macAddress) raise ArgumentError, "specified mac address is wrong or in an invalid format" unless is_valid_mac(macAddress) build_and_send_query(:reboot_radio, { macAddress: fix_mac_address(parameter_to_string(macAddress)) } ) end |
#setEthernet(macAddress, statoEthernet) ⇒ Object
call-seq:
MyNGIAccess.setEthernet(macAddress,statoEthernet) => {:stato_ethernet=>true}
Set the ethernet adapter of a customer’s radio.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ngi_api.rb', line 140 def setEthernet(macAddress,statoEthernet) raise ArgumentError, "specified mac address is wrong or in an invalid format" unless is_valid_mac(macAddress) raise ArgumentError, "stato ethernet is wrong on in an invalid format" unless ["0","1"].include? parameter_to_string(statoEthernet) build_and_send_query(:set_ethernet, { macAddress: fix_mac_address(parameter_to_string(macAddress)), statoEthernet: parameter_to_string(statoEthernet) } ) end |