radiodns 0.0.2 → 0.0.3
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/Gemfile.lock +1 -1
- data/README.md +32 -1
- data/lib/radiodns.rb +42 -0
- data/lib/radiodns/version.rb +1 -1
- data/radiodns.gemspec +1 -1
- data/spec/radiodns_spec.rb +149 -2
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -10,7 +10,38 @@ This Ruby Gem provides utilities for working with the RadioDNS spec.
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
Add this to the top of your script
|
|
14
|
+
|
|
13
15
|
require 'radiodns'
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
Then if you already have the Fully Qualified Domain Name as specified
|
|
18
|
+
in the [RadioDNS spec](http://radiodns.org/wp-content/uploads/2009/03/rdns011.pdf), you
|
|
19
|
+
can resolve it into a CNAME like so
|
|
20
|
+
|
|
21
|
+
cname = RadioDNS::Resolver.resolve('09580.c586.ce1.fm.radiodns.org')
|
|
16
22
|
puts cname #=> 'rdns.musicradio.com'
|
|
23
|
+
|
|
24
|
+
You can also pass in the parameters required to construct the FQDN to
|
|
25
|
+
the resolve method
|
|
26
|
+
|
|
27
|
+
params = {
|
|
28
|
+
:freq => '09580',
|
|
29
|
+
:pi => 'c586',
|
|
30
|
+
:ecc => 'ce1',
|
|
31
|
+
:bearer => 'fm'
|
|
32
|
+
}
|
|
33
|
+
cname = RadioDNS::Resolver.resolve(params)
|
|
34
|
+
|
|
35
|
+
The bearers `fm`, `dab`, `drm`, `amss` and `hd` are supported.
|
|
36
|
+
|
|
37
|
+
## TODO
|
|
38
|
+
|
|
39
|
+
- better error checking of supplied parameters. The code current
|
|
40
|
+
checks for mandatory parameters but not if the parameters
|
|
41
|
+
themselves conform to the spec (e.g. pa should be between 0 and
|
|
42
|
+
1023)
|
|
43
|
+
|
|
44
|
+
- return an appropriate error if DNS look-up does not resolve to
|
|
45
|
+
CNAME.
|
|
46
|
+
|
|
47
|
+
- service discovery
|
data/lib/radiodns.rb
CHANGED
|
@@ -3,9 +3,51 @@ require 'resolv'
|
|
|
3
3
|
module RadioDNS
|
|
4
4
|
class Resolver
|
|
5
5
|
def self.resolve(fqdn)
|
|
6
|
+
if fqdn.is_a? Hash
|
|
7
|
+
fqdn = construct_fqdn(fqdn)
|
|
8
|
+
end
|
|
9
|
+
|
|
6
10
|
resolver = Resolv::DNS.new
|
|
7
11
|
cname = resolver.getresource(fqdn, Resolv::DNS::Resource::IN::CNAME)
|
|
8
12
|
cname.name.to_s
|
|
9
13
|
end
|
|
14
|
+
|
|
15
|
+
def self.construct_fqdn(params)
|
|
16
|
+
bearer = params[:bearer]
|
|
17
|
+
case bearer
|
|
18
|
+
when "fm" then construct_fqdn_for_fm(params)
|
|
19
|
+
when "dab" then construct_fqdn_for_dab(params)
|
|
20
|
+
when "drm" then construct_fqdn_for_drm_or_amss(params)
|
|
21
|
+
when "amss" then construct_fqdn_for_drm_or_amss(params)
|
|
22
|
+
when "hd" then construct_fqdn_for_hd(params)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
def self.construct_fqdn_for_hd(params)
|
|
28
|
+
raise ArgumentError unless params[:tx] && params[:cc]
|
|
29
|
+
[params[:tx], params[:cc], 'hd.radiodns.org'].join('.')
|
|
30
|
+
end
|
|
31
|
+
def self.construct_fqdn_for_drm_or_amss(params)
|
|
32
|
+
raise ArgumentError unless params[:sid]
|
|
33
|
+
[params[:sid], params[:bearer], 'radiodns.org'].join('.')
|
|
34
|
+
end
|
|
35
|
+
def self.construct_fqdn_for_dab(params)
|
|
36
|
+
raise ArgumentError unless params[:scids] && params[:sid] && params[:eid] && params[:ecc]
|
|
37
|
+
[params[:appty_uatype] || params[:pa],
|
|
38
|
+
params[:scids],
|
|
39
|
+
params[:sid],
|
|
40
|
+
params[:eid],
|
|
41
|
+
params[:ecc],
|
|
42
|
+
'dab.radiodns.org'].reject{|a| a.nil?}.join('.')
|
|
43
|
+
end
|
|
44
|
+
def self.construct_fqdn_for_fm(params)
|
|
45
|
+
raise ArgumentError if params[:ecc] && params[:country]
|
|
46
|
+
raise ArgumentError if params[:ecc].nil? && params[:country].nil?
|
|
47
|
+
[params[:freq],
|
|
48
|
+
params[:pi],
|
|
49
|
+
params[:ecc] || params[:country],
|
|
50
|
+
'fm.radiodns.org'].join('.')
|
|
51
|
+
end
|
|
10
52
|
end
|
|
11
53
|
end
|
data/lib/radiodns/version.rb
CHANGED
data/radiodns.gemspec
CHANGED
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["Chris Lowis"]
|
|
10
10
|
s.email = ["chris.lowis@gmail.com"]
|
|
11
|
-
s.homepage = ""
|
|
11
|
+
s.homepage = "http://github.com/chrislo/radiodns"
|
|
12
12
|
s.summary = %q{Perform RadioDNS resolutions and service lookups}
|
|
13
13
|
s.description = %q{Perform RadioDNS resolutions and service lookups}
|
|
14
14
|
|
data/spec/radiodns_spec.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'radiodns'
|
|
|
5
5
|
|
|
6
6
|
describe "RadioDNS::Resolver" do
|
|
7
7
|
describe "resolve" do
|
|
8
|
-
|
|
8
|
+
before(:each) do
|
|
9
9
|
mock_resolver = mock()
|
|
10
10
|
mock_cname = mock()
|
|
11
11
|
mock_resolver.expects(:getresource).
|
|
@@ -14,9 +14,156 @@ describe "RadioDNS::Resolver" do
|
|
|
14
14
|
mock_cname.expects(:name).returns('rdns.musicradio.com')
|
|
15
15
|
|
|
16
16
|
Resolv::DNS.expects(:new).returns(mock_resolver)
|
|
17
|
-
|
|
17
|
+
end
|
|
18
|
+
it "should query radiodns.org" do
|
|
18
19
|
cname = RadioDNS::Resolver.resolve('09580.c586.ce1.fm.radiodns.org')
|
|
19
20
|
assert_equal 'rdns.musicradio.com', cname
|
|
20
21
|
end
|
|
22
|
+
|
|
23
|
+
it "should accept hash params too" do
|
|
24
|
+
params = {
|
|
25
|
+
:freq => '09580',
|
|
26
|
+
:pi => 'c586',
|
|
27
|
+
:ecc => 'ce1',
|
|
28
|
+
:bearer => 'fm'
|
|
29
|
+
}
|
|
30
|
+
cname = RadioDNS::Resolver.resolve(params)
|
|
31
|
+
assert_equal 'rdns.musicradio.com', cname
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "construct_fqdn" do
|
|
36
|
+
describe "for FM/VHF bearer" do
|
|
37
|
+
it "should construct a fqdn when ecc is supplied" do
|
|
38
|
+
params = {
|
|
39
|
+
:bearer => 'fm',
|
|
40
|
+
:ecc => 'ce1',
|
|
41
|
+
:pi => 'c585',
|
|
42
|
+
:freq => '09580'
|
|
43
|
+
}
|
|
44
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
45
|
+
assert_equal '09580.c585.ce1.fm.radiodns.org', fqdn
|
|
46
|
+
end
|
|
47
|
+
it "should construct a fqdn when country is supplied" do
|
|
48
|
+
params = {
|
|
49
|
+
:bearer => 'fm',
|
|
50
|
+
:country => 'gb',
|
|
51
|
+
:pi => 'c585',
|
|
52
|
+
:freq => '09580'
|
|
53
|
+
}
|
|
54
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
55
|
+
assert_equal '09580.c585.gb.fm.radiodns.org', fqdn
|
|
56
|
+
end
|
|
57
|
+
it "should raise when country and ecc is supplied" do
|
|
58
|
+
params = {
|
|
59
|
+
:bearer => 'fm',
|
|
60
|
+
:country => 'gb',
|
|
61
|
+
:ecc => 'ce1',
|
|
62
|
+
:pi => 'c585',
|
|
63
|
+
:freq => '09580'
|
|
64
|
+
}
|
|
65
|
+
assert_raises(ArgumentError) {RadioDNS::Resolver.construct_fqdn(params)}
|
|
66
|
+
end
|
|
67
|
+
it "should raise when neither country nor ecc is supplied" do
|
|
68
|
+
params = {
|
|
69
|
+
:bearer => 'fm',
|
|
70
|
+
:pi => 'c585',
|
|
71
|
+
:freq => '09580'
|
|
72
|
+
}
|
|
73
|
+
assert_raises(ArgumentError) {RadioDNS::Resolver.construct_fqdn(params)}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
describe "for DAB bearer" do
|
|
77
|
+
it "should construct a fqdn" do
|
|
78
|
+
params = {
|
|
79
|
+
:bearer => 'dab',
|
|
80
|
+
:ecc => 'ecc',
|
|
81
|
+
:eid => 'eid',
|
|
82
|
+
:sid => 'sid',
|
|
83
|
+
:scids => 'scids'
|
|
84
|
+
}
|
|
85
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
86
|
+
assert_equal 'scids.sid.eid.ecc.dab.radiodns.org', fqdn
|
|
87
|
+
end
|
|
88
|
+
it "should raise if parameters are missing" do
|
|
89
|
+
params = {
|
|
90
|
+
:bearer => 'dab',
|
|
91
|
+
}
|
|
92
|
+
assert_raises(ArgumentError) {RadioDNS::Resolver.construct_fqdn(params)}
|
|
93
|
+
end
|
|
94
|
+
it "should prepend appty-uatype if provided" do
|
|
95
|
+
params = {
|
|
96
|
+
:bearer => 'dab',
|
|
97
|
+
:ecc => 'ecc',
|
|
98
|
+
:eid => 'eid',
|
|
99
|
+
:sid => 'sid',
|
|
100
|
+
:scids => 'scids',
|
|
101
|
+
:appty_uatype => 'appty-uatype'
|
|
102
|
+
}
|
|
103
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
104
|
+
assert_equal 'appty-uatype.scids.sid.eid.ecc.dab.radiodns.org', fqdn
|
|
105
|
+
end
|
|
106
|
+
it "should prepend pa if provided" do
|
|
107
|
+
params = {
|
|
108
|
+
:bearer => 'dab',
|
|
109
|
+
:ecc => 'ecc',
|
|
110
|
+
:eid => 'eid',
|
|
111
|
+
:sid => 'sid',
|
|
112
|
+
:scids => 'scids',
|
|
113
|
+
:pa => 'pa'
|
|
114
|
+
}
|
|
115
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
116
|
+
assert_equal 'pa.scids.sid.eid.ecc.dab.radiodns.org', fqdn
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
describe "for DRM bearer" do
|
|
120
|
+
it "should construct a fqdn" do
|
|
121
|
+
params = {
|
|
122
|
+
:bearer => 'drm',
|
|
123
|
+
:sid => 'sid',
|
|
124
|
+
}
|
|
125
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
126
|
+
assert_equal 'sid.drm.radiodns.org', fqdn
|
|
127
|
+
end
|
|
128
|
+
it "should raise if sid is missing" do
|
|
129
|
+
params = {
|
|
130
|
+
:bearer => 'drm',
|
|
131
|
+
}
|
|
132
|
+
assert_raises(ArgumentError) {RadioDNS::Resolver.construct_fqdn(params)}
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
describe "for AMSS bearer" do
|
|
136
|
+
it "should construct a fqdn" do
|
|
137
|
+
params = {
|
|
138
|
+
:bearer => 'amss',
|
|
139
|
+
:sid => 'sid',
|
|
140
|
+
}
|
|
141
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
142
|
+
assert_equal 'sid.amss.radiodns.org', fqdn
|
|
143
|
+
end
|
|
144
|
+
it "should raise if sid is missing" do
|
|
145
|
+
params = {
|
|
146
|
+
:bearer => 'amss',
|
|
147
|
+
}
|
|
148
|
+
assert_raises(ArgumentError) {RadioDNS::Resolver.construct_fqdn(params)}
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
describe "for hd bearer" do
|
|
152
|
+
it "should construct a fqdn" do
|
|
153
|
+
params = {
|
|
154
|
+
:bearer => 'hd',
|
|
155
|
+
:tx => 'tx',
|
|
156
|
+
:cc => 'cc',
|
|
157
|
+
}
|
|
158
|
+
fqdn = RadioDNS::Resolver.construct_fqdn(params)
|
|
159
|
+
assert_equal 'tx.cc.hd.radiodns.org', fqdn
|
|
160
|
+
end
|
|
161
|
+
it "should raise if tx or cc is missing" do
|
|
162
|
+
params = {
|
|
163
|
+
:bearer => 'hd',
|
|
164
|
+
}
|
|
165
|
+
assert_raises(ArgumentError) {RadioDNS::Resolver.construct_fqdn(params)}
|
|
166
|
+
end
|
|
167
|
+
end
|
|
21
168
|
end
|
|
22
169
|
end
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: radiodns
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.0.
|
|
5
|
+
version: 0.0.3
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Chris Lowis
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-03-
|
|
13
|
+
date: 2011-03-06 00:00:00 +00:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -55,7 +55,7 @@ files:
|
|
|
55
55
|
- radiodns.gemspec
|
|
56
56
|
- spec/radiodns_spec.rb
|
|
57
57
|
has_rdoc: true
|
|
58
|
-
homepage:
|
|
58
|
+
homepage: http://github.com/chrislo/radiodns
|
|
59
59
|
licenses: []
|
|
60
60
|
|
|
61
61
|
post_install_message:
|