class Object

Public Instance Methods

build_and_send_query(type,params = {}) click to toggle source

Build and submit the SOAP query. Needed the operation (raise an error if it’s not an allowed one from the server) and a hash of optional parameters.

# File lib/ngi_api.rb, line 198
def build_and_send_query(type,params = {})
    type = type.to_sym
    raise ArgumentError, "query type not included in allowed operations: #{@soapClient.operations}" unless @soapClient.operations.include? type
    
    message = { wsLogin: @partnerLogin }
    checksum = @partnerLogin

    case type
        when :info_bts
            checksum += params[:btsID]
            message[:btsID] = params[:btsID]
        when :list_comuni
            checksum += params[:comune]
            message[:comune] = params[:comune]
        when :set_ethernet
            checksum += params[:macAddress]
            checksum += params[:statoEthernet]
            message[:macAddress] = params[:macAddress]
            message[:statoEthernet] = params[:statoEthernet]
        when :reboot_radio
            checksum += params[:macAddress]
            message[:macAddress] = params[:macAddress]
        when :info_radio
            checksum += parameter_to_string(params[:macAddressList])
            checksum += parameter_to_string(params[:clientLoginList])
            message[:macAddressList] = {items: params[:macAddressList]}
            message[:clientLoginList] = {items: params[:clientLoginList]}
        when :info_coverage
            checksum += params[:via]
            checksum += params[:civico]
            checksum += params[:istat]
            message[:via] = params[:via]
            message[:civico] = params[:civico]
            message[:istat] = params[:istat]
        when :list_bts # no input needed
    end
    message[:controlHash] = Digest::MD5.hexdigest(checksum+@partnerPassword)
    @soapClient.call(type, message: message).to_hash[(type.to_s+"_response").to_sym]
end
fetch_cacert() click to toggle source

Download the ‘cacert.pem’ file from “curl.haxx.se” if not found in the running directory Courtesy of gist.github.com/fnichol/867550

# File lib/ngi_api.rb, line 183
def fetch_cacert
    Net::HTTP.start("curl.haxx.se") do |http|
        resp = http.get("/ca/cacert.pem")
        if resp.code == "200"
            open("cacert.pem", "wb") do |file|
                file.write(resp.body)
            end 
        else
            raise "no \"cacert.pem\" file found, and can't download it from curl website"
        end
    end
end
fix_login(login) click to toggle source

formats the login for the request, upcasing it

# File lib/ngi_api.rb, line 172
def fix_login(login)
    login.upcase
end
is_i?() click to toggle source

check if string is integer

# File lib/ngi_api.rb, line 177
def is_i?
   /\A[-+]?\d+\z/ === self
end
is_valid_comune(comune) click to toggle source

According to unicode-table.com

  • u{00E0} à

  • u{00E8} è

  • u{00E9} é

  • u{00EC} ì

  • u{00F2} ò

  • u{00F9} ù

# File lib/ngi_api.rb, line 245
def is_valid_comune(comune)
    !!comune.to_s[/^([a-zA-Z\u{00E0}\u{00E8}\u{00E9}\u{00EC}\u{00F2}\u{00F9}]{2}[a-zA-Z\u{0200}\u{0201}\u{0236}\u{0242}\u{0249}]{0,33})$/]
end
is_valid_login(login) click to toggle source

Loose check for if a string is a valid login. Value must be formatted before submit with fix_login. Matches “w or W” + 11 digits

# File lib/ngi_api.rb, line 251
def is_valid_login(login)
    !!login.to_s[/[wW]\d{11}/]
end
is_valid_mac(mac) click to toggle source

Loose check for the validity of a MAC address. Value must be formatted with fix_mac_address before submit. Matches any of the following:

  • 00aabbccddee

  • 00-aa-bb-cc-dd-ee

  • 00:aa:bb:cc:dd:ee

  • 00.aa.bb.cc.dd.ee

# File lib/ngi_api.rb, line 261
def is_valid_mac(mac)
    !!mac.to_s[/^([0-9a-fA-F]{2}[\.:-]?){5}([0-9a-fA-F]{2})$/]
end
parameter_to_string(parameter) click to toggle source

Formatting types according to NGI API

# File lib/ngi_api.rb, line 266
def parameter_to_string(parameter)
    case parameter.class.to_s
    when "TrueClass","FalseClass" 
        parameter ? "1" : "0"
    when "Integer"
        "%d" % parameter
    when "Float"
        "%.5f" % parameter
    when "Array" # streamline it
        parameter.map{ |element| parameter_to_string(element) }.join
    else # for any other type, convert it to a string
        "%s" % parameter.to_s
    end
end