ngi_api 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/README.rdoc +45 -0
- data/lib/ngi_api.rb +271 -0
- data/lib/ngi_api/version.rb +4 -0
- data/lib/test_cases.rb +85 -0
- data/ngi_api.gemspec +30 -0
- data/spec/ngi_api_spec.rb +25 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rspec.rake +3 -0
- metadata +143 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Marco Bulgarini
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# NgiApi
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ngi_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ngi_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/ngi_api/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= NgiAPI {<img src="https://travis-ci.org/blacksd/ngi_api.png?rvm=1.9.3" />}[https://travis-ci.org/blacksd/ngi_api]
|
2
|
+
|
3
|
+
* https://github.com/blacksd/ngi_api
|
4
|
+
* https://rubygems.org/gems/ngi_api
|
5
|
+
|
6
|
+
== Description
|
7
|
+
|
8
|
+
This library is a convenient, easy way to access NGI's API for resellers - simple
|
9
|
+
object methods vs. custom SOAP calls. There are multiple built-in checks for type corrections, and
|
10
|
+
the entered values are automatically adjusted. Return values are parsed and presented as a hash.
|
11
|
+
This gem currently supports all API operations:
|
12
|
+
* list_bts
|
13
|
+
* list_comuni
|
14
|
+
* info_bts
|
15
|
+
* info_radio
|
16
|
+
* reboot_radio
|
17
|
+
* set_ethernet
|
18
|
+
|
19
|
+
== Dependencies
|
20
|
+
|
21
|
+
* rubyntlm version 0.3.2 or newer
|
22
|
+
* savon[http://savonrb.com/] version 2
|
23
|
+
|
24
|
+
== Support:
|
25
|
+
|
26
|
+
The bug tracker is available here: https://github.com/blacksd/ngi_api/issues
|
27
|
+
|
28
|
+
== Examples
|
29
|
+
|
30
|
+
With arguments as a hash, cast a
|
31
|
+
|
32
|
+
MyNGIAccess = NgiAPI.new(arguments)
|
33
|
+
|
34
|
+
and use the instance methods.
|
35
|
+
|
36
|
+
== Authors
|
37
|
+
|
38
|
+
Copyright (c) 2015 by Marco Bulgarini (marco.bulgarini@com-net.it)
|
39
|
+
|
40
|
+
This library is the second attempt in using Ruby at something practical. If you
|
41
|
+
think I did a good job, let me know!
|
42
|
+
|
43
|
+
== License
|
44
|
+
|
45
|
+
This library is distributed under the MIT license.
|
data/lib/ngi_api.rb
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
# gem "rubyntlm", "~> 0.3.2" # no "gems" in here! Dependencies go through gemspec.
|
5
|
+
require "rubyntlm"
|
6
|
+
require "savon"
|
7
|
+
require "net/http"
|
8
|
+
|
9
|
+
# This is the main class, holding all of the functions
|
10
|
+
# and checks. The instance it's built with a hash of arguments.
|
11
|
+
class NgiAPI
|
12
|
+
|
13
|
+
# call-seq:
|
14
|
+
# MyNGIAccess = NgiAPI.new(arguments)
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# Initialize the class instance with a hash of arguments. The hash is mandatory and must not be empty.
|
18
|
+
# There's a test mode and a production live mode.
|
19
|
+
# == Test mode
|
20
|
+
# arguments[:test] = true
|
21
|
+
# Puts any operation in test mode, with standard login and password and a different wsdl.
|
22
|
+
# arguments[:debug] = true
|
23
|
+
# The :debug can be set to true for improved stdout logging.
|
24
|
+
# == Production mode
|
25
|
+
# arguments[:partnerLogin] = "13243546"
|
26
|
+
# arguments[:partnerPassword] = "randomsaltprovidedbyNGI"
|
27
|
+
#
|
28
|
+
def initialize(args)
|
29
|
+
raise ArgumentError, "no arguments provided, no idea what to do" if args.empty?
|
30
|
+
raise ArgumentError, "\"test\" option provided with login and/or password - can't do that" if args[:test] && (!!args[:partnerLogin] || !!args[:partnerPassword])
|
31
|
+
raise ArgumentError, "you must give both a login and a password." if !!args[:partnerLogin] ^ !!args[:partnerPassword]
|
32
|
+
@partnerLogin = !!args[:test] ? "12345678" : parameter_to_string(args[:partnerLogin])
|
33
|
+
@partnerPassword = !!args[:test] ? "517fc7b578767ebfa6bb5252252653d2" : parameter_to_string(args[:partnerPassword])
|
34
|
+
fetch_cacert unless File.exist?('cacert.pem')
|
35
|
+
@soapClient = Savon.client do
|
36
|
+
wsdl !!args[:test] ? "https://www.eolo.it/ws/wsdl/?test" : "https://www.eolo.it/ws/wsdl"
|
37
|
+
ssl_ca_cert_file "cacert.pem"
|
38
|
+
if args[:debug]
|
39
|
+
log true
|
40
|
+
log_level :debug
|
41
|
+
pretty_print_xml true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# --------------------------------------
|
47
|
+
# :section: Available Operations
|
48
|
+
# As Public Instance Methods are the operations available through NGI APIs.
|
49
|
+
# Make good use of them, and don't abuse.
|
50
|
+
# --------------------------------------
|
51
|
+
|
52
|
+
# call-seq:
|
53
|
+
# MyNGIAccess.infoRadio(macAddresses_clientLogins) => {...}
|
54
|
+
#
|
55
|
+
# Status of a radio, obtained as a string or an array of a client login/mac address.
|
56
|
+
def infoRadio(macAddresses_clientLogins)
|
57
|
+
|
58
|
+
macAddressArray = []
|
59
|
+
clientLoginArray = []
|
60
|
+
|
61
|
+
case macAddresses_clientLogins.class.to_s
|
62
|
+
when "Array"
|
63
|
+
raise ArgumentError,"array exceeds 20 elements" if macAddresses_clientLogins.size > 20
|
64
|
+
macAddresses_clientLogins.each_with_index do |element,index|
|
65
|
+
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)
|
66
|
+
macAddressArray.push(fix_mac_address(element)) if is_valid_mac(element)
|
67
|
+
clientLoginArray.push(fix_login(element)) if is_valid_login(element)
|
68
|
+
end
|
69
|
+
when "String"
|
70
|
+
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)
|
71
|
+
macAddressArray.push(fix_mac_address(macAddresses_clientLogins)) if is_valid_mac(macAddresses_clientLogins)
|
72
|
+
clientLoginArray.push(fix_login(macAddresses_clientLogins)) if is_valid_login(macAddresses_clientLogins)
|
73
|
+
else
|
74
|
+
raise ArgumentError,"unsupported data type: a single mac address or login string or an array of them are the only allowed types."
|
75
|
+
end
|
76
|
+
|
77
|
+
build_and_send_query(:info_radio,
|
78
|
+
{
|
79
|
+
macAddressList: macAddressArray,
|
80
|
+
clientLoginList: clientLoginArray
|
81
|
+
}
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
# call-seq:
|
86
|
+
# MyNGIAccess.infoBts(btsID) => {...}
|
87
|
+
#
|
88
|
+
# Obtain the exact informations about a specific BTS. btsID is a non-negative integer.
|
89
|
+
def infoBts(btsID)
|
90
|
+
raise ArgumentError, "btsID value not allowed" unless btsID.to_i > 0 && btsID.class.to_s == "Fixnum"
|
91
|
+
build_and_send_query(:info_bts,
|
92
|
+
{
|
93
|
+
btsID: parameter_to_string(btsID)
|
94
|
+
}
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# call-seq:
|
99
|
+
# MyNGIAccess.infoCoverage(via,civico,istat) => {...}
|
100
|
+
#
|
101
|
+
# Gets the coverage for the specified address. The address is composed of
|
102
|
+
# * +via+ the street location
|
103
|
+
# * +civico+ the number
|
104
|
+
# * +istat+ the istat code for the town, gathered from listComuni
|
105
|
+
def infoCoverage(via,civico,istat)
|
106
|
+
build_and_send_query(:info_coverage,
|
107
|
+
{
|
108
|
+
via: parameter_to_string(via),
|
109
|
+
civico: parameter_to_string(civico),
|
110
|
+
istat: parameter_to_string(istat)
|
111
|
+
}
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
# call-seq:
|
116
|
+
# MyNGIAccess.listBts => {}
|
117
|
+
#
|
118
|
+
# Obtain a hash of active BTSes with their details. No input needed, lots of output to be expected.
|
119
|
+
def listBts
|
120
|
+
build_and_send_query(:list_bts)
|
121
|
+
end
|
122
|
+
|
123
|
+
# call-seq:
|
124
|
+
# MyNGIAccess.listComuni(comune) => {}
|
125
|
+
#
|
126
|
+
# Obtain the istat code for the town.
|
127
|
+
def listComuni(comune)
|
128
|
+
raise ArgumentError, "comune is not >=2 and <= 35 in length, or has not allowed characters" unless is_valid_comune(parameter_to_string(comune))
|
129
|
+
build_and_send_query(:list_comuni,
|
130
|
+
{
|
131
|
+
comune: parameter_to_string(comune)
|
132
|
+
}
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
# call-seq:
|
137
|
+
# MyNGIAccess.setEthernet(macAddress,statoEthernet) => {:stato_ethernet=>true}
|
138
|
+
#
|
139
|
+
# Set the ethernet adapter of a customer's radio.
|
140
|
+
def setEthernet(macAddress,statoEthernet)
|
141
|
+
raise ArgumentError, "specified mac address is wrong or in an invalid format" unless is_valid_mac(macAddress)
|
142
|
+
raise ArgumentError, "stato ethernet is wrong on in an invalid format" unless ["0","1"].include? parameter_to_string(statoEthernet)
|
143
|
+
build_and_send_query(:set_ethernet,
|
144
|
+
{
|
145
|
+
macAddress: fix_mac_address(parameter_to_string(macAddress)),
|
146
|
+
statoEthernet: parameter_to_string(statoEthernet)
|
147
|
+
}
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
# call-seq:
|
152
|
+
# MyNGIAccess.rebootRadio(macAddress) => {esito: true}
|
153
|
+
#
|
154
|
+
# Reboot a customer's radio.
|
155
|
+
def rebootRadio(macAddress)
|
156
|
+
raise ArgumentError, "specified mac address is wrong or in an invalid format" unless is_valid_mac(macAddress)
|
157
|
+
build_and_send_query(:reboot_radio,
|
158
|
+
{
|
159
|
+
macAddress: fix_mac_address(parameter_to_string(macAddress))
|
160
|
+
}
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# formats the mac address for the request, stripping separators and upcasing it
|
167
|
+
def fix_mac_address(mac)
|
168
|
+
mac.to_s.gsub(/[\.:-]?/,'').upcase
|
169
|
+
end
|
170
|
+
|
171
|
+
# formats the login for the request, upcasing it
|
172
|
+
def fix_login(login)
|
173
|
+
login.upcase
|
174
|
+
end
|
175
|
+
|
176
|
+
# Download the 'cacert.pem' file from "curl.haxx.se" if not found in the running directory
|
177
|
+
# Courtesy of https://gist.github.com/fnichol/867550
|
178
|
+
def fetch_cacert
|
179
|
+
Net::HTTP.start("curl.haxx.se") do |http|
|
180
|
+
resp = http.get("/ca/cacert.pem")
|
181
|
+
if resp.code == "200"
|
182
|
+
open("cacert.pem", "wb") do |file|
|
183
|
+
file.write(resp.body)
|
184
|
+
end
|
185
|
+
else
|
186
|
+
raise "no \"cacert.pem\" file found, and can't download it from curl website"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Build and submit the SOAP query.
|
192
|
+
# Needed the operation (raise an error if it's not an allowed one from the server) and a hash of optional parameters.
|
193
|
+
def build_and_send_query(type,params = {})
|
194
|
+
type = type.to_sym
|
195
|
+
raise ArgumentError, "query type not included in allowed operations: #{@soapClient.operations}" unless @soapClient.operations.include? type
|
196
|
+
|
197
|
+
message = { wsLogin: @partnerLogin }
|
198
|
+
checksum = @partnerLogin
|
199
|
+
|
200
|
+
case type
|
201
|
+
when :info_bts
|
202
|
+
checksum += params[:btsID]
|
203
|
+
message[:btsID] = params[:btsID]
|
204
|
+
when :list_comuni
|
205
|
+
checksum += params[:comune]
|
206
|
+
message[:comune] = params[:comune]
|
207
|
+
when :set_ethernet
|
208
|
+
checksum += params[:macAddress]
|
209
|
+
checksum += params[:statoEthernet]
|
210
|
+
message[:macAddress] = params[:macAddress]
|
211
|
+
message[:statoEthernet] = params[:statoEthernet]
|
212
|
+
when :reboot_radio
|
213
|
+
checksum += params[:macAddress]
|
214
|
+
message[:macAddress] = params[:macAddress]
|
215
|
+
when :info_radio
|
216
|
+
checksum += parameter_to_string(params[:macAddressList])
|
217
|
+
checksum += parameter_to_string(params[:clientLoginList])
|
218
|
+
message[:macAddressList] = {items: params[:macAddressList]}
|
219
|
+
message[:clientLoginList] = {items: params[:clientLoginList]}
|
220
|
+
when :list_bts # no input needed
|
221
|
+
end
|
222
|
+
|
223
|
+
message[:controlHash] = Digest::MD5.hexdigest(checksum+@partnerPassword)
|
224
|
+
@soapClient.call(type, message: message).to_hash[(type.to_s+"_response").to_sym]
|
225
|
+
end
|
226
|
+
|
227
|
+
# According to {http://unicode-table.com}[http://unicode-table.com]
|
228
|
+
# * \u{00E0} à
|
229
|
+
# * \u{00E8} è
|
230
|
+
# * \u{00E9} é
|
231
|
+
# * \u{00EC} ì
|
232
|
+
# * \u{00F2} ò
|
233
|
+
# * \u{00F9} ù
|
234
|
+
def is_valid_comune(comune)
|
235
|
+
!!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})$/]
|
236
|
+
end
|
237
|
+
|
238
|
+
# Loose check for if a string is a valid login. Value must be formatted before submit with fix_login.
|
239
|
+
# Matches "w or W" + 11 digits
|
240
|
+
def is_valid_login(login)
|
241
|
+
!!login.to_s[/[wW]\d{11}/]
|
242
|
+
end
|
243
|
+
|
244
|
+
# Loose check for the validity of a MAC address. Value must be formatted with fix_mac_address before submit.
|
245
|
+
# Matches any of the following:
|
246
|
+
# * 00aabbccddee
|
247
|
+
# * 00-aa-bb-cc-dd-ee
|
248
|
+
# * 00:aa:bb:cc:dd:ee
|
249
|
+
# * 00.aa.bb.cc.dd.ee
|
250
|
+
def is_valid_mac(mac)
|
251
|
+
!!mac.to_s[/^([0-9a-fA-F]{2}[\.:-]?){5}([0-9a-fA-F]{2})$/]
|
252
|
+
end
|
253
|
+
|
254
|
+
# Formatting types according to NGI API
|
255
|
+
def parameter_to_string(parameter)
|
256
|
+
case parameter.class.to_s
|
257
|
+
when "TrueClass","FalseClass"
|
258
|
+
parameter ? "1" : "0"
|
259
|
+
when "Integer"
|
260
|
+
"%d" % parameter
|
261
|
+
when "Float"
|
262
|
+
"%.5f" % parameter
|
263
|
+
when "Array" # streamline it
|
264
|
+
parameter.map{ |element| parameter_to_string(element) }.join
|
265
|
+
else # for any other type, convert it to a string
|
266
|
+
"%s" % parameter.to_s
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
data/lib/test_cases.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
load ('test_class.rb')
|
3
|
+
=begin
|
4
|
+
|
5
|
+
api_config_fake = {
|
6
|
+
partnerLogin: "asdasd12345",
|
7
|
+
partnerPassword: "asdasdhbi8asd78972ui"
|
8
|
+
}
|
9
|
+
myNgiAccess = NgiAPI.new(api_config_fake)
|
10
|
+
|
11
|
+
api_config_test = { test: true }
|
12
|
+
myNgiAccess = NgiAPI.new(api_config_test)
|
13
|
+
|
14
|
+
puts myNgiAccess.operations
|
15
|
+
puts myNgiAccess.listBts
|
16
|
+
puts myNgiAccess.infoBts(1)
|
17
|
+
puts myNgiAccess.listComuni("Lòp")
|
18
|
+
puts myNgiAccess.setEthernet("00-00-00000000",false)
|
19
|
+
|
20
|
+
# this will rise an exception, as per specs
|
21
|
+
begin
|
22
|
+
puts myNgiAccess.setEthernet("11-11-11-11-11-11",true)
|
23
|
+
rescue Exception => e
|
24
|
+
puts "Damn! Got an exception: #{e}"
|
25
|
+
end
|
26
|
+
|
27
|
+
puts myNgiAccess.rebootRadio("aa-bb-cc-dd-ee-11")
|
28
|
+
|
29
|
+
# this will rise an exception, as per specs
|
30
|
+
begin
|
31
|
+
puts myNgiAccess.rebootRadio("111111111111")
|
32
|
+
rescue Exception => e
|
33
|
+
puts "Damn! Got an exception, should be an internal server error: #{e}"
|
34
|
+
end
|
35
|
+
|
36
|
+
# this will trigger an ArgumentError
|
37
|
+
begin
|
38
|
+
api_config_err = { test: true, partnerLogin: "asdasd12345", partnerPassword: "asdasdhbi8asd78972ui" }
|
39
|
+
myNgiAccess_err = NgiAPI.new(api_config_err)
|
40
|
+
rescue Exception => e
|
41
|
+
puts "Damn! Got an exception, should be an invalid API initialization: #{e}"
|
42
|
+
end
|
43
|
+
|
44
|
+
# this will trigger an ArgumentError
|
45
|
+
begin
|
46
|
+
api_config_err2 = { partnerLogin: "asdasd12345" }
|
47
|
+
myNgiAccess_err2 = NgiAPI.new(api_config_err2)
|
48
|
+
rescue Exception => e
|
49
|
+
puts "Damn! Got an exception, should be an invalid API initialization: #{e}"
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# this will trigger an ArgumentError
|
54
|
+
begin
|
55
|
+
puts myNgiAccess.infoRadio(["aa.bb.cc.dd.ee.ff","W12345678901"])
|
56
|
+
rescue Exception => e
|
57
|
+
puts "Damn! Got an exception, should be an invalid mix: #{e}"
|
58
|
+
end
|
59
|
+
|
60
|
+
=end
|
61
|
+
|
62
|
+
api_config_test = { test:true }
|
63
|
+
myNgiAccess = NgiAPI.new(api_config_test)
|
64
|
+
|
65
|
+
# puts myNgiAccess.operations
|
66
|
+
# puts myNgiAccess.infoRadio(["000000000000","aa11bb22cc33"])
|
67
|
+
puts myNgiAccess.infoRadio(["W00001200000","00:ee:aa:bb:cc:dd","W12345678901","W09898778766"])
|
68
|
+
# {:info=>{:radio_info_list=>[{:client_login=>{:"@xsi:type"=>"xsd:string"}, :mac_address=>"00EEAABBCCDD", :snr_up=>"1", :snr_down=>"2", :distanza=>"13.17", :stato_ethernet=>"1", :bts_id=>"2", :nome_cella=>nil, :tipo_radio=>nil, :"@xsi:type"=>"ns1:radioInfoType"}, {:client_login=>"W00000000001", :mac_address=>"000000000001", :snr_up=>"1", :snr_down=>"2", :distanza=>"13.17", :stato_ethernet=>"1", :bts_id=>"2", :nome_cella=>nil, :tipo_radio=>nil, :"@xsi:type"=>"ns1:radioInfoType"}], :"@xsi:type"=>"ns1:radioInfoListType"}}
|
69
|
+
|
70
|
+
puts myNgiAccess.listBts
|
71
|
+
# {:lista_bts=>{:items=>[{:bts_id=>"1", :nome_bts=>"1 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"2", :nome_bts=>"2 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"3", :nome_bts=>"3 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"4", :nome_bts=>"4 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"5", :nome_bts=>"5 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"6", :nome_bts=>"6 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"7", :nome_bts=>"7 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"8", :nome_bts=>"8 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"9", :nome_bts=>"9 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"10", :nome_bts=>"10 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"11", :nome_bts=>"11 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"12", :nome_bts=>"12 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"13", :nome_bts=>"13 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"14", :nome_bts=>"14 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"15", :nome_bts=>"15 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"16", :nome_bts=>"16 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"17", :nome_bts=>"17 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}, {:bts_id=>"18", :nome_bts=>"18 of 18: 12345678-a9f1870699c64a453757842d645e36ea", :lat=>"45.8", :lng=>"8.45", :attiva=>false, :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsInfoType"}], :"@xsi:type"=>"ns1:BtsListType"}}
|
72
|
+
|
73
|
+
puts myNgiAccess.listComuni("Peppinaio")
|
74
|
+
# {:lista_comuni=>{:items=>[{:comune=>"Alagna", :istat=>"18001", :provincia=>"PV", :"@xsi:type"=>"ns1:comuneType"}, {:comune=>"Alpignano", :istat=>"1008", :provincia=>"TO", :"@xsi:type"=>"ns1:comuneType"}, {:comune=>"Montorio al Vomano", :istat=>"67028", :provincia=>"TE", :"@xsi:type"=>"ns1:comuneType"}, {:comune=>"Roio del Sangro", :istat=>"69077", :provincia=>"CH", :"@xsi:type"=>"ns1:comuneType"}, {:comune=>"Varano de' Melegari", :istat=>"34045", :provincia=>"PR", :"@xsi:type"=>"ns1:comuneType"}, {:comune=>"Voghera", :istat=>"18182", :provincia=>"PV", :"@xsi:type"=>"ns1:comuneType"}, {:comune=>"Zoppola", :istat=>"93051", :provincia=>"PN", :"@xsi:type"=>"ns1:comuneType"}], :"@xsi:type"=>"ns1:comuneListType"}}
|
75
|
+
|
76
|
+
puts myNgiAccess.rebootRadio("00eeaabbccdd")
|
77
|
+
# {:esito=>true}
|
78
|
+
|
79
|
+
puts myNgiAccess.infoBts(3)
|
80
|
+
# {:info_bts=>{:bts_id=>"3", :nome_bts=>"il nome \u00E8: 12345678, 3, bb5fa1323d296928d1a4c2ae5a908f70", :lat=>"45.9", :lng=>"8.15", :asl=>"99", :attiva=>true, :data_attivazione=>#<Date: 2015-01-08 ((2457031j,0s,0n),+0s,2299161j)>, :file_mappa=>"mappa.file", :inf_sx_lat=>"45.79585", :inf_sx_lng=>"7.873442", :sup_dx_lat=>"46.15581", :sup_dx_lng=>"8.391391", :tech_string=>{:"@xsi:type"=>"ns1:nonNullName"}, :"@xsi:type"=>"ns1:BtsFullInfoType"}}
|
81
|
+
|
82
|
+
puts myNgiAccess.setEthernet("00aabbccddee",true)
|
83
|
+
# {:stato_ethernet=>true}
|
84
|
+
|
85
|
+
|
data/ngi_api.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ngi_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ngi_api"
|
8
|
+
spec.version = NgiAPI::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Marco Bulgarini"]
|
11
|
+
spec.email = ["marco.bulgarini@com-net.it"]
|
12
|
+
spec.summary = "NGI's API"
|
13
|
+
spec.description = "A ruby implementation of NGI's API"
|
14
|
+
spec.homepage = "https://rubygems.org/gems/ngi_api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
|
26
|
+
# spec.add_runtime_dependency "digest" # no need to add stdlib!
|
27
|
+
# spec.add_runtime_dependency "net/http" # no need to add stdlib!
|
28
|
+
spec.add_runtime_dependency "rubyntlm", "~> 0.3.2"
|
29
|
+
spec.add_runtime_dependency "savon"
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NgiApi do
|
4
|
+
# subject { NgiApi.new }
|
5
|
+
|
6
|
+
# describe '#process' do
|
7
|
+
# let(:input) { 'My grandmom gave me a sweater for Christmas.' }
|
8
|
+
# let(:output) { subject.process(input) }
|
9
|
+
|
10
|
+
# it 'converts to lowercase' do
|
11
|
+
# expect(output.downcase).to eq output
|
12
|
+
# end
|
13
|
+
|
14
|
+
# it 'combines nouns with doge adjectives' do
|
15
|
+
# expect(output).to match /so grandmom\./i
|
16
|
+
# expect(output).to match /such sweater\./i
|
17
|
+
# expect(output).to match /very christmas\./i
|
18
|
+
# end
|
19
|
+
|
20
|
+
# it 'always appends "wow."' do
|
21
|
+
# expect(output).to end_with 'wow.'
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ngi_api'
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ngi_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marco Bulgarini
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.7'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.7'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '10.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '10.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rubyntlm
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.2
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.3.2
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: savon
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: A ruby implementation of NGI's API
|
95
|
+
email:
|
96
|
+
- marco.bulgarini@com-net.it
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- lib/README.rdoc
|
107
|
+
- lib/cacert.pem
|
108
|
+
- lib/ngi_api.rb
|
109
|
+
- lib/ngi_api/version.rb
|
110
|
+
- lib/test_cases.rb
|
111
|
+
- ngi_api.gemspec
|
112
|
+
- spec/ngi_api_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- tasks/rspec.rake
|
115
|
+
homepage: https://rubygems.org/gems/ngi_api
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.24
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: NGI's API
|
140
|
+
test_files:
|
141
|
+
- spec/ngi_api_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
has_rdoc:
|