qrz-callbook 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/Manifest +5 -0
- data/README.rdoc +80 -0
- data/Rakefile +13 -0
- data/lib/qrz-callbook.rb +90 -0
- data/qrz-callbook.gemspec +33 -0
- metadata +93 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Brad McConahay
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= QRZCallbook
|
2
|
+
|
3
|
+
This gem provides an easy object oriented front end to access Amateur Radio
|
4
|
+
callsign data from the QRZ.COM online database.
|
5
|
+
|
6
|
+
It uses the QRZ XML Database Service, which requires a subscription from QRZ.COM.
|
7
|
+
|
8
|
+
The QRZ XML Database Service specification states "The data supplied by the XML port may
|
9
|
+
be extended in a forwardly compatible manner. New XML elements and database objects
|
10
|
+
(with their associated elements) may be transmitted at any time. It is the developers
|
11
|
+
responsibility to have their program ignore any unrecognized objects and/or elements
|
12
|
+
without raising an error, so long as the information received consists of properly formatted XML."
|
13
|
+
|
14
|
+
Therefore, this gem will not attempt to list or manage individual elements of a callsign. You
|
15
|
+
will need to inspect the hash to see which elements are available for any given
|
16
|
+
callsign, as demonstrated in the synopsis.
|
17
|
+
|
18
|
+
This gem does not handle any management of reusing session keys at this time, although you can
|
19
|
+
specify a key you have used previously when initializing, or at any time via the key accessor.
|
20
|
+
|
21
|
+
== Usage
|
22
|
+
|
23
|
+
require "rubygems"
|
24
|
+
require "pp"
|
25
|
+
require "qrz-callbook"
|
26
|
+
|
27
|
+
qrz = QRZCallbook.new({
|
28
|
+
'callsign' => 'n8qq',
|
29
|
+
'username' => 'qrz_username',
|
30
|
+
'password' => 'qrz_password'
|
31
|
+
})
|
32
|
+
|
33
|
+
# get and inspect the basic listing
|
34
|
+
|
35
|
+
qrz.get_listing
|
36
|
+
pp qrz.listing
|
37
|
+
|
38
|
+
# get and inspect biography information
|
39
|
+
|
40
|
+
qrz.get_bio
|
41
|
+
pp qrz.bio
|
42
|
+
|
43
|
+
qrz.get_bio_file
|
44
|
+
puts "Biography: #{qrz.bio_file}"
|
45
|
+
|
46
|
+
# get and inspect dxcc information
|
47
|
+
|
48
|
+
qrz.get_dxcc
|
49
|
+
pp qrz.dxcc
|
50
|
+
|
51
|
+
# show the session information from the last call to the api
|
52
|
+
|
53
|
+
pp qrz.session
|
54
|
+
|
55
|
+
# set a new callsign and show some misc individual information
|
56
|
+
|
57
|
+
qrz.callsign = 'w8irc'
|
58
|
+
qrz.get_listing
|
59
|
+
qrz.get_dxcc
|
60
|
+
|
61
|
+
puts "Name: #{qrz.listing['fname']} #{qrz.listing['name']}"
|
62
|
+
puts "DXCC Continent: #{qrz.dxcc['continent']}"
|
63
|
+
|
64
|
+
== Dependencies
|
65
|
+
|
66
|
+
* xml-simple
|
67
|
+
|
68
|
+
* A QRZ.COM subscription that includes access to the QRZ XML Database Service
|
69
|
+
|
70
|
+
== See Also
|
71
|
+
|
72
|
+
* In order to use this module you need to have a subscription for the QRZ XML Database Service. See http://www.qrz.com/XML/index.html
|
73
|
+
|
74
|
+
* The technical reference for the QRZ XML Database Service is at http://www.qrz.com/XML/current_spec.html
|
75
|
+
|
76
|
+
== Copyright
|
77
|
+
|
78
|
+
Copyright (c) 2010 Brad McConahay. See LICENSE.txt for
|
79
|
+
further details.
|
80
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('qrz-callbook', '0.0.1') do |p|
|
6
|
+
p.description = "A front end for the QRZ.COM Amateur Radio callsign database API."
|
7
|
+
p.url = "http://github.com/bradmc/qrz-callbook"
|
8
|
+
p.author = "Brad McConahay"
|
9
|
+
p.email = "brad @nospam@ mcconahay.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.runtime_dependencies = ["xml-simple"]
|
12
|
+
end
|
13
|
+
|
data/lib/qrz-callbook.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'xmlsimple'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
class QRZCallbook
|
7
|
+
|
8
|
+
@@VERSION = '0.0.1'
|
9
|
+
|
10
|
+
class SessionError < StandardError; end
|
11
|
+
|
12
|
+
attr_accessor :callsign, :username, :password, :key
|
13
|
+
attr_reader :session, :listing, :bio, :bio_file, :dxcc
|
14
|
+
|
15
|
+
QRZ_URL = 'http://www.qrz.com/xml'
|
16
|
+
AGENT = "ruby-gem-qrz-callbook-#{@@VERSION}"
|
17
|
+
|
18
|
+
def initialize(args={})
|
19
|
+
@callsign = args['callsign']
|
20
|
+
@username = args['username']
|
21
|
+
@password = args['password']
|
22
|
+
@key = args['key']
|
23
|
+
raise "A QRZ API subscription username is required." if @username.to_s.empty?
|
24
|
+
raise "A QRZ API subscription password is required." if @password.to_s.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def login
|
28
|
+
raise "A QRZ API subscription username is required." if @username.to_s.empty?
|
29
|
+
raise "A QRZ API subscription password is required." if @password.to_s.empty?
|
30
|
+
url = "#{QRZ_URL}/bin/xml?username=#{@username};password=#{@password};agent=#{AGENT}"
|
31
|
+
xml = open(url).read
|
32
|
+
content = XmlSimple.xml_in( xml, { 'ForceArray' => false } )
|
33
|
+
@session = content['Session']
|
34
|
+
raise SessionError, @session['Error'] if @session['Error']
|
35
|
+
@key = @session['Key']
|
36
|
+
raise SessionError, "Unknown Error: Could not retrieve session key." if @session['Key'].to_s.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_listing
|
40
|
+
raise "An amateur radio callsign is required to retrieve data." if @callsign.to_s.empty?
|
41
|
+
login if @key.to_s.empty?
|
42
|
+
url = "#{QRZ_URL}/bin/xml?s=#{@key};callsign=#{@callsign}";
|
43
|
+
xml = open(url).read
|
44
|
+
content = XmlSimple.xml_in( xml, { 'ForceArray' => false } )
|
45
|
+
@session = content['Session']
|
46
|
+
raise SessionError, @session['Error'] if @session['Error']
|
47
|
+
@listing = content['Callsign']
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_bio
|
51
|
+
raise "An amateur radio callsign is required to retrieve data." if @callsign.to_s.empty?
|
52
|
+
login if @key.to_s.empty?
|
53
|
+
url = "#{QRZ_URL}/bin/xml?s=#{@key};bio=#{@callsign}";
|
54
|
+
xml = open(url).read
|
55
|
+
content = XmlSimple.xml_in( xml, { 'ForceArray' => false } )
|
56
|
+
@session = content['Session']
|
57
|
+
if @session['Error'] =~ /not found/i
|
58
|
+
@bio = {}
|
59
|
+
return
|
60
|
+
end
|
61
|
+
raise SessionError, @session['Error'] if @session['Error']
|
62
|
+
@bio = content['Bio']
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_bio_file
|
66
|
+
get_bio if @bio.to_s.empty?
|
67
|
+
if @bio['bio'].to_s.empty?
|
68
|
+
@bio_file = ''
|
69
|
+
return;
|
70
|
+
end
|
71
|
+
url = "#{@bio['bio']}";
|
72
|
+
content = open(url).read
|
73
|
+
content = content.gsub(/ /," ").gsub(/<.*?>/m, '').gsub(%r{(\n\s*){2}}, "\n\n")
|
74
|
+
@bio_file = CGI.unescapeHTML(content)
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_dxcc
|
78
|
+
raise "An amateur radio callsign is required to retrieve data." if @callsign.to_s.empty?
|
79
|
+
login if @key.to_s.empty?
|
80
|
+
url = "#{QRZ_URL}/bin/xml?s=#{@key};dxcc=#{@callsign}";
|
81
|
+
xml = open(url).read
|
82
|
+
content = XmlSimple.xml_in( xml, { 'ForceArray' => false } )
|
83
|
+
@session = content['Session']
|
84
|
+
raise SessionError, @session['Error'] if @session['Error']
|
85
|
+
@dxcc = content['DXCC']
|
86
|
+
end
|
87
|
+
|
88
|
+
end # class QRZCallbook
|
89
|
+
|
90
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{qrz-callbook}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Brad McConahay"]
|
9
|
+
s.date = %q{2010-12-26}
|
10
|
+
s.description = %q{A front end for the QRZ.COM Amateur Radio callsign database API.}
|
11
|
+
s.email = %q{brad @nospam@ mcconahay.com}
|
12
|
+
s.extra_rdoc_files = ["LICENSE.txt", "README.rdoc", "lib/qrz-callbook.rb"]
|
13
|
+
s.files = ["LICENSE.txt", "README.rdoc", "Rakefile", "lib/qrz-callbook.rb", "Manifest", "qrz-callbook.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/bradmc/qrz-callbook}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Qrz-callbook", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{qrz-callbook}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{A front end for the QRZ.COM Amateur Radio callsign database API.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qrz-callbook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brad McConahay
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-26 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: xml-simple
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: A front end for the QRZ.COM Amateur Radio callsign database API.
|
36
|
+
email: brad @nospam@ mcconahay.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.rdoc
|
44
|
+
- lib/qrz-callbook.rb
|
45
|
+
files:
|
46
|
+
- LICENSE.txt
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- lib/qrz-callbook.rb
|
50
|
+
- Manifest
|
51
|
+
- qrz-callbook.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/bradmc/qrz-callbook
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --line-numbers
|
59
|
+
- --inline-source
|
60
|
+
- --title
|
61
|
+
- Qrz-callbook
|
62
|
+
- --main
|
63
|
+
- README.rdoc
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 11
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 2
|
84
|
+
version: "1.2"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: qrz-callbook
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: A front end for the QRZ.COM Amateur Radio callsign database API.
|
92
|
+
test_files: []
|
93
|
+
|