ngi_api 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ <<<<<<< HEAD
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -13,3 +14,39 @@
13
14
  *.a
14
15
  mkmf.log
15
16
  cacert.pem
17
+ =======
18
+ *.gem
19
+ *.rbc
20
+ /.config
21
+ /coverage/
22
+ /InstalledFiles
23
+ /pkg/
24
+ /spec/reports/
25
+ /test/tmp/
26
+ /test/version_tmp/
27
+ /tmp/
28
+
29
+ ## Specific to RubyMotion:
30
+ .dat*
31
+ .repl_history
32
+ build/
33
+
34
+ ## Documentation cache and generated files:
35
+ /.yardoc/
36
+ /_yardoc/
37
+ /doc/
38
+ /rdoc/
39
+
40
+ ## Environment normalisation:
41
+ /.bundle/
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+ >>>>>>> 71defb1db547347cf4973972add9a39d23ab6fc8
@@ -1,4 +1,4 @@
1
1
  class NgiAPI
2
2
  # gem version
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.5"
4
4
  end
data/lib/ngi_api.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require "digest"
4
- # gem "rubyntlm", "~> 0.3.2" # no "gems" in here! Dependencies go through gemspec.
4
+ # gem "rubyntlm", "~> 0.3.2" # no "gems" in here! Dependencies go in gemspec.
5
5
  require "rubyntlm"
6
6
  require "savon"
7
7
  require "net/http"
@@ -85,9 +85,9 @@ class NgiAPI
85
85
  # call-seq:
86
86
  # MyNGIAccess.infoBts(btsID) => {...}
87
87
  #
88
- # Obtain the exact informations about a specific BTS. btsID is a non-negative integer.
88
+ # Obtain the exact informations about a specific BTS. btsID is a non-negative integer, number or string
89
89
  def infoBts(btsID)
90
- raise ArgumentError, "btsID value not allowed" unless btsID.to_i > 0 && btsID.class.to_s == "Fixnum"
90
+ raise ArgumentError, "btsID value not allowed" unless btsID.to_i > 0 && btsID.to_s[/\A[-+]?\d+\z/] === btsID.to_s # kudos to http://stackoverflow.com/a/1235990/2513430
91
91
  build_and_send_query(:info_bts,
92
92
  {
93
93
  btsID: parameter_to_string(btsID)
@@ -125,7 +125,7 @@ class NgiAPI
125
125
  #
126
126
  # Obtain the istat code for the town.
127
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))
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
129
  build_and_send_query(:list_comuni,
130
130
  {
131
131
  comune: parameter_to_string(comune)
@@ -173,6 +173,11 @@ class NgiAPI
173
173
  login.upcase
174
174
  end
175
175
 
176
+ # check if string is integer
177
+ def is_i?
178
+ /\A[-+]?\d+\z/ === self
179
+ end
180
+
176
181
  # Download the 'cacert.pem' file from "curl.haxx.se" if not found in the running directory
177
182
  # Courtesy of https://gist.github.com/fnichol/867550
178
183
  def fetch_cacert
data/spec/ngi_api_spec.rb CHANGED
@@ -1,6 +1,132 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe NgiApi do
3
+ describe NgiAPI do
4
+ context 'when in test mode' do
5
+
6
+ before :all do
7
+ @myNgiAPI = NgiAPI.new({test: true})
8
+ end
9
+
10
+ it 'can build a test instance' do
11
+ expect(@myNgiAPI).to be_an_instance_of NgiAPI
12
+ end
13
+
14
+ describe '#listBts' do
15
+ # OKs
16
+ it 'returns a BtsListType' do
17
+ expect(@myNgiAPI.listBts[:lista_bts][:"@xsi:type"]).to eq("ns1:BtsListType")
18
+ end
19
+
20
+ # KOs
21
+ it 'sometimes returns an empty list (1 in 10)' do
22
+ sample = ""
23
+ 10.times do
24
+ sample = @myNgiAPI.listBts[:lista_bts][:items]
25
+ break if sample.nil?
26
+ end
27
+ expect(sample).to be_nil
28
+ end
29
+ end
30
+
31
+ describe '#infoRadio' do
32
+ # 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")
50
+ end
51
+ it 'is okay with a single uppercase login' do
52
+ expect(@myNgiAPI.infoRadio('W12345678901')[:info][:"@xsi:type"]).to eq("ns1:radioInfoListType")
53
+ end
54
+ 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")
64
+ end
65
+
66
+ # KOs
67
+ it 'fails with a non-mac non-login value' do
68
+ expect{ @myNgiAPI.infoRadio('someinvalidstring') }.to raise_error(ArgumentError)
69
+ end
70
+ it 'fails with a large (> 20) array' do
71
+ large_test_array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]
72
+ expect{ @myNgiAPI.infoRadio(large_test_array) }.to raise_error(ArgumentError)
73
+ end
74
+ 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
80
+ end
81
+ 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
84
+ end
85
+
86
+ end
87
+
88
+ describe '#infoBts' do
89
+ # 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")
96
+ end
97
+
98
+ # KOs
99
+ 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)
102
+ end
103
+
104
+ end
105
+
106
+ describe '#infoCoverage' do
107
+
108
+ end
109
+
110
+ describe '#listComuni' do
111
+
112
+ end
113
+
114
+ describe '#setEthernet' do
115
+
116
+ end
117
+
118
+ describe '#rebootRadio' do
119
+ # OKs
120
+ it 'returns true'
121
+
122
+ # KOs
123
+ it 'throws an error if mac address is invalid'
124
+ it 'returns an error if mac is all 0s or all 1s'
125
+ end
126
+ end
127
+
128
+
129
+
4
130
  # subject { NgiApi.new }
5
131
 
6
132
  # describe '#process' do
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.3
4
+ version: 0.0.5
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-01-25 00:00:00.000000000 Z
12
+ date: 2015-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler