ngi_api 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.5
5
+ - 2.2.0
6
+ gemfile:
7
+ - Gemfile
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # NgiApi
2
2
 
3
- TODO: Write a gem description
3
+ This library is a convenient, easy way to access NGI's API for resellers - simple object methods vs. custom SOAP calls. There are multiple built-in checks for type corrections, and the entered values are automatically adjusted. Return values are parsed and presented as a hash.
4
+ This gem currently supports all API operations:
5
+ * list_bts
6
+ * list_comuni
7
+ * info_bts
8
+ * info_radio
9
+ * reboot_radio
10
+ * set_ethernet
4
11
 
5
12
  ## Installation
6
13
 
@@ -20,11 +27,11 @@ Or install it yourself as:
20
27
 
21
28
  ## Usage
22
29
 
23
- TODO: Write usage instructions here
30
+ See documentation!
24
31
 
25
32
  ## Contributing
26
33
 
27
- 1. Fork it ( https://github.com/[my-github-username]/ngi_api/fork )
34
+ 1. Fork it ( https://github.com/blacksd/ngi_api/fork )
28
35
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
36
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
37
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
- Dir.glob('tasks/**/*.rake').each(&method(:import))
2
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
3
+ task :default => :spec
@@ -33,9 +33,9 @@ class NgiAPI
33
33
  @partnerPassword = !!args[:test] ? "517fc7b578767ebfa6bb5252252653d2" : parameter_to_string(args[:partnerPassword])
34
34
  fetch_cacert unless File.exist?('cacert.pem')
35
35
  @soapClient = Savon.client do
36
- wsdl !!args[:test] ? "https://www.eolo.it/ws/wsdl/?test" : "https://www.eolo.it/ws/wsdl"
36
+ wsdl !!args[:test] ? "https://www.eolo.it/ws/wsdl/?test" : "https://www.eolo.it/ws/wsdl/"
37
37
  ssl_ca_cert_file "cacert.pem"
38
- if args[:debug]
38
+ if !!args[:debug]
39
39
  log true
40
40
  log_level :debug
41
41
  pretty_print_xml true
@@ -161,7 +161,7 @@ class NgiAPI
161
161
  )
162
162
  end
163
163
 
164
- private
164
+ private # ------------------
165
165
 
166
166
  # formats the mac address for the request, stripping separators and upcasing it
167
167
  def fix_mac_address(mac)
@@ -203,28 +203,34 @@ class NgiAPI
203
203
  checksum = @partnerLogin
204
204
 
205
205
  case type
206
- when :info_bts
207
- checksum += params[:btsID]
208
- message[:btsID] = params[:btsID]
209
- when :list_comuni
210
- checksum += params[:comune]
211
- message[:comune] = params[:comune]
212
- when :set_ethernet
213
- checksum += params[:macAddress]
214
- checksum += params[:statoEthernet]
215
- message[:macAddress] = params[:macAddress]
216
- message[:statoEthernet] = params[:statoEthernet]
217
- when :reboot_radio
218
- checksum += params[:macAddress]
219
- message[:macAddress] = params[:macAddress]
220
- when :info_radio
221
- checksum += parameter_to_string(params[:macAddressList])
222
- checksum += parameter_to_string(params[:clientLoginList])
223
- message[:macAddressList] = {items: params[:macAddressList]}
224
- message[:clientLoginList] = {items: params[:clientLoginList]}
225
- when :list_bts # no input needed
206
+ when :info_bts
207
+ checksum += params[:btsID]
208
+ message[:btsID] = params[:btsID]
209
+ when :list_comuni
210
+ checksum += params[:comune]
211
+ message[:comune] = params[:comune]
212
+ when :set_ethernet
213
+ checksum += params[:macAddress]
214
+ checksum += params[:statoEthernet]
215
+ message[:macAddress] = params[:macAddress]
216
+ message[:statoEthernet] = params[:statoEthernet]
217
+ when :reboot_radio
218
+ checksum += params[:macAddress]
219
+ message[:macAddress] = params[:macAddress]
220
+ when :info_radio
221
+ checksum += parameter_to_string(params[:macAddressList])
222
+ checksum += parameter_to_string(params[:clientLoginList])
223
+ message[:macAddressList] = {items: params[:macAddressList]}
224
+ message[:clientLoginList] = {items: params[:clientLoginList]}
225
+ when :info_coverage
226
+ checksum += params[:via]
227
+ checksum += params[:civico]
228
+ checksum += params[:istat]
229
+ message[:via] = params[:via]
230
+ message[:civico] = params[:civico]
231
+ message[:istat] = params[:istat]
232
+ when :list_bts # no input needed
226
233
  end
227
-
228
234
  message[:controlHash] = Digest::MD5.hexdigest(checksum+@partnerPassword)
229
235
  @soapClient.call(type, message: message).to_hash[(type.to_s+"_response").to_sym]
230
236
  end
@@ -1,4 +1,4 @@
1
1
  class NgiAPI
2
2
  # gem version
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe NgiAPI do
@@ -5,6 +7,35 @@ describe NgiAPI do
5
7
 
6
8
  before :all do
7
9
  @myNgiAPI = NgiAPI.new({test: true})
10
+ @macstotest = [
11
+ # '00.aA.bB.cC.dD.11', # dots
12
+ # '00:aA:bB:cC:dD:11', # colons
13
+ # '00-aA-bB-cC-dD-11', # dashes
14
+ # '00aAbBcCdD11', # no spaces
15
+ '00aA:bB.cC-dD-11' # mixed
16
+ ]
17
+ @zeroedmacstotest = [
18
+ # '00.00.00.00.00.00', # dots
19
+ # '00:00:00:00:00:00', # colons
20
+ # '00-00-00-00-00-00', # dashes
21
+ # '000000000000', # no spaces
22
+ '0000:00.00-00-00' # mixed
23
+ ]
24
+ @onedmacstotest = [
25
+ # '11.11.11.11.11.11', # dots
26
+ # '11:11:11:11:11:11', # colons
27
+ # '11-11-11-11-11-11', # dashes
28
+ # '111111111111', # no spaces
29
+ '1111:11.11-11-11' # mixed
30
+ ]
31
+ @loginstotest = [
32
+ # 'W12345678901' # upcase
33
+ 'w12345678901', # lowcase
34
+ ]
35
+ @zeroedloginstotest = [
36
+ # 'W00000000000' # upcase
37
+ 'w00000000000', # lowcase
38
+ ]
8
39
  end
9
40
 
10
41
  it 'can build a test instance' do
@@ -30,37 +61,22 @@ describe NgiAPI do
30
61
 
31
62
  describe '#infoRadio' do
32
63
  # OKs
33
- it 'is fine with a dot separated single mac' do
34
- expect(@myNgiAPI.infoRadio('00.aA.bB.cC.dD.11')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
35
- end
36
- it 'is fine with a colon divided single mac' do
37
- expect(@myNgiAPI.infoRadio('00:aA:bB:cC:dD:11')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
38
- end
39
- it 'is fine with a dashed single mac' do
40
- expect(@myNgiAPI.infoRadio('00-aA-bB-cC-dD-11')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
41
- end
42
- it 'is fine with an unspaced single mac' do
43
- expect(@myNgiAPI.infoRadio('00aAbBcCdD11')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
44
- end
45
- it 'is fine with a mixed separated single mac' do
46
- expect(@myNgiAPI.infoRadio('00aA:bB.cC-dD-11')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
47
- end
48
- it 'is okay with a single lowercase login' do
49
- expect(@myNgiAPI.infoRadio('w12345678901')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
64
+ it 'is fine with a single mac' do
65
+ @macstotest.each do |mac|
66
+ expect(@myNgiAPI.infoRadio(mac)[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
67
+ end
50
68
  end
51
- it 'is okay with a single uppercase login' do
52
- expect(@myNgiAPI.infoRadio('W12345678901')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
69
+
70
+ it 'is okay with a single login' do
71
+ @loginstotest.each do |login|
72
+ expect(@myNgiAPI.infoRadio(login)[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
73
+ end
53
74
  end
75
+
54
76
  it 'is fine with an array of mixed values' do
55
- test_array = [
56
- '00.aA.bB.cC.dD.11',
57
- '00-aA-bB-cC-dD-11',
58
- '00aAbBcCdD11',
59
- '00aA:bB.cC-dD-11',
60
- 'w12345678901',
61
- 'W12345678901'
62
- ]
63
- expect(@myNgiAPI.infoRadio(test_array)[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
77
+ (@macstotest + @loginstotest).each do |element|
78
+ expect(@myNgiAPI.infoRadio(element)[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
79
+ end
64
80
  end
65
81
 
66
82
  # KOs
@@ -72,56 +88,143 @@ describe NgiAPI do
72
88
  expect{ @myNgiAPI.infoRadio(large_test_array) }.to raise_error(ArgumentError)
73
89
  end
74
90
  it 'fails with a mac value of 000000000000' do
75
- expect{ @myNgiAPI.infoRadio('000000000000') }.to raise_error
76
- expect{ @myNgiAPI.infoRadio('00.00.00.00.00.00') }.to raise_error
77
- expect{ @myNgiAPI.infoRadio('00:00:00:00:00:00') }.to raise_error
78
- expect{ @myNgiAPI.infoRadio('00-00-00-00-00-00') }.to raise_error
79
- expect{ @myNgiAPI.infoRadio('000000:00.00-00') }.to raise_error
91
+ @zeroedmacstotest.each do |zeroedmac|
92
+ expect{ @myNgiAPI.infoRadio(zeroedmac) }.to raise_error
93
+ end
80
94
  end
95
+
81
96
  it 'fails with a login value of W00000000000' do
82
- expect{ @myNgiAPI.infoRadio('W00000000000') }.to raise_error
83
- expect{ @myNgiAPI.infoRadio('w00000000000') }.to raise_error
97
+ @zeroedloginstotest.each do |zeroedlogin|
98
+ expect{ @myNgiAPI.infoRadio(zeroedlogin) }.to raise_error
99
+ end
84
100
  end
85
101
 
86
102
  end
87
103
 
88
104
  describe '#infoBts' do
89
105
  # OKs
90
- it 'returns sample data with a numeric param' do
91
- expect( @myNgiAPI.infoBts(3)[:info_bts][:"@xsi:type"] ).to eq("ns1:BtsFullInfoType")
92
- end
93
-
94
- it 'returns sample data with a numeric string param' do
95
- expect( @myNgiAPI.infoBts("3")[:info_bts][:"@xsi:type"] ).to eq("ns1:BtsFullInfoType")
106
+ it 'returns sample data' do
107
+ [
108
+ 3, # int
109
+ "3" # string
110
+ ].each do |bts_input|
111
+ expect( @myNgiAPI.infoBts(bts_input)[:info_bts][:"@xsi:type"] ).to eq("ns1:BtsFullInfoType")
112
+ end
96
113
  end
97
114
 
98
115
  # KOs
99
116
  it 'throws an error with btsId < 1' do
100
- expect{ @myNgiAPI.infoBts(0) }.to raise_error(ArgumentError)
101
- expect{ @myNgiAPI.infoBts('0') }.to raise_error(ArgumentError)
117
+ [
118
+ 0, # int
119
+ "0" # string
120
+ ].each do |bts_input|
121
+ expect{ @myNgiAPI.infoBts(bts_input) }.to raise_error(ArgumentError)
122
+ end
102
123
  end
103
124
 
104
125
  end
105
126
 
106
127
  describe '#infoCoverage' do
107
-
128
+ # OKs
129
+ it 'returns a list of matching BTSes for the address' do
130
+ expect( @myNgiAPI.infoCoverage("Viale Monza",12,"01234")[:lista_bts][:"@xsi:type"] ).to eq("ns1:BtsListType")
131
+ end
108
132
  end
109
133
 
110
134
  describe '#listComuni' do
135
+ # OKs
136
+ it 'returns a list of towns' do
137
+ expect( @myNgiAPI.listComuni("someteststring")[:lista_comuni][:"@xsi:type"] ).to eq("ns1:comuneListType")
138
+ end
139
+
140
+ it 'works fine with latin characters' do
141
+ expect( @myNgiAPI.listComuni("sometestàèéìòùstring")[:lista_comuni][:"@xsi:type"] ).to eq("ns1:comuneListType")
142
+ end
111
143
 
144
+ # KOs
145
+ it 'throws an error with a short (<2 chars) param' do
146
+ expect{ @myNgiAPI.listComuni("a") }.to raise_error(ArgumentError)
147
+ end
148
+
149
+ it 'throws an error with a long (>35 chars) param' do
150
+ expect{ @myNgiAPI.listComuni("areallylongstringthatshouldnotbeatown") }.to raise_error(ArgumentError)
151
+ end
152
+
153
+ it 'returns an empty list with a "nolist" param' do
154
+ expect( @myNgiAPI.listComuni("nolist")[:lista_comuni][:items] ).to be_nil
155
+ end
156
+
157
+ it 'throws an error with a "error" param' do
158
+ expect{ @myNgiAPI.listComuni("error") }.to raise_error
159
+ end
112
160
  end
113
161
 
114
162
  describe '#setEthernet' do
163
+ # OKs
164
+ it 'can enable an ethernet interface' do
165
+ [
166
+ 1, # int
167
+ true # bool
168
+ ].each do |eth_enable_state|
169
+ @macstotest.each do |mac|
170
+ expect( @myNgiAPI.setEthernet(mac,eth_enable_state)[:stato_ethernet] ).to be true
171
+ end
172
+ end
173
+ end
115
174
 
175
+ it 'can disable an ethernet interface' do
176
+ [
177
+ 0, # int
178
+ false # bool
179
+ ].each do |eth_enable_state|
180
+ @macstotest.each do |mac|
181
+ expect( @myNgiAPI.setEthernet(mac,eth_enable_state)[:stato_ethernet] ).to be false
182
+ end
183
+ end
184
+ end
185
+
186
+ # KOs
187
+ it 'throws an error if mac is all 1s' do
188
+ [
189
+ true, # bool
190
+ false
191
+ ].each do |eth_state|
192
+ @onedmacstotest.each do |onedmac|
193
+ expect{ @myNgiAPI.setEthernet(onedmac,eth_state) }.to raise_error
194
+ end
195
+ end
196
+ end
197
+
198
+ it 'always gets a false with a mac of all 0s' do
199
+ [
200
+ true, # bool
201
+ false
202
+ ].each do |eth_state|
203
+ @zeroedmacstotest.each do |zeroedmac|
204
+ expect( @myNgiAPI.setEthernet(zeroedmac,eth_state)[:stato_ethernet] ).to be false
205
+ end
206
+ end
207
+ end
116
208
  end
117
209
 
118
210
  describe '#rebootRadio' do
119
211
  # OKs
120
- it 'returns true'
212
+ it 'returns true' do
213
+ @macstotest.each do |mac|
214
+ expect( @myNgiAPI.rebootRadio(mac)[:esito] ).to be true
215
+ end
216
+ end
121
217
 
122
218
  # KOs
123
- it 'throws an error if mac address is invalid'
124
- it 'returns an error if mac is all 0s or all 1s'
219
+ it 'throws an error if mac address is invalid' do
220
+ expect{ @myNgiAPI.rebootRadio('someinvalidstring') }.to raise_error(ArgumentError)
221
+ end
222
+
223
+ it 'returns an error if mac is all 0s or all 1s' do
224
+ (@zeroedmacstotest + @onedmacstotest).each do |mac|
225
+ expect{ @myNgiAPI.rebootRadio(mac) }.to raise_error
226
+ end
227
+ end
125
228
  end
126
229
  end
127
230
 
@@ -1,3 +1,3 @@
1
1
  require 'rspec/core/rake_task'
2
2
 
3
- RSpec::Core::RakeTask.new(:spec)
3
+ RSpec::Core::RakeTask.new(:spec)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngi_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-02 00:00:00.000000000 Z
12
+ date: 2015-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -99,6 +99,7 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - .gitignore
102
+ - .travis.yml
102
103
  - Gemfile
103
104
  - LICENSE.txt
104
105
  - README.md