dx-lookup 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53be409b66cb963cfb9e05b80c762cee71e64866
4
+ data.tar.gz: b67e36b333f28b7561b43a1c7a6926825e458d23
5
+ SHA512:
6
+ metadata.gz: 9cbf0cf0c61140d893675d5c8a2da315703085545e1a7c09f05f519385b15fddb51d22b891c2080b0f4006bd17666feeee6bcd1294040a0ffe2416ceff937750
7
+ data.tar.gz: e691220c6c57e92d9409ccf4673ba6ed6d22161edc1028dcd2ca27997fb7b11e9b92425c508de4fa292adf425b2c323d919f144161bc90d236939dc591f6d8bc
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dx-lookup.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rockwell Schrock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # DX::Lookup
2
+
3
+ Easy callsign and DXCC entity lookup utilizing third-party APIs.
4
+
5
+ Currently-supported APIs:
6
+
7
+ * QRZ.com
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'dx-lookup'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install dx-lookup
24
+
25
+ ## Usage
26
+
27
+ ### QRZ.com Lookup
28
+
29
+ You must have a subscription to the "XML Logbook Data" subscription on QRZ.com. Go to [your account page](https://www.qrz.com/manager) to subscribe.
30
+
31
+ It is highly recommended that you store your QRZ.com username externally to your source files, for example in a configuration file, or in your environment variables.
32
+
33
+ ```ruby
34
+ qrz = DX::Lookup::QRZ.new(ENV['QRZ_USERNAME'], ENV['QRZ_PASSWORD'])
35
+
36
+ call = qrz.get_callsign('W1AW')
37
+ puts call.last_name # => 'ARRL HQ OPERATORS CLUB'
38
+ puts call.dxcc # => 291
39
+ puts call.grid # => 'FN31pr'
40
+
41
+ entity = qrz.get_dxcc_entity(291)
42
+ puts entity.name # => 'United States'
43
+
44
+ entity = qrz.get_callsign_entity('OH8X')
45
+ puts entity.name # => 'Finland'
46
+
47
+ entities = qrz.get_all_entities
48
+ puts entities.count # => 399
49
+ ```
50
+
51
+ See `lib/dx/lookup/qrz/callsign.rb` and `lib/dx/lookup/qrz/entity.rb` for a complete list of supported attributes.
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/schrockwell/dx-lookup.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dx/lookup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dx/lookup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dx-lookup"
8
+ spec.version = DX::Lookup::VERSION
9
+ spec.authors = ["Rockwell Schrock"]
10
+ spec.email = ["cq@ww1x.com"]
11
+
12
+ spec.summary = %q{Callsign detail lookup}
13
+ spec.homepage = "https://github.com/schrockwell/dx-lookup"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+
25
+ spec.add_runtime_dependency 'httparty', '~> 0.14'
26
+ spec.add_runtime_dependency 'virtus', '~> 1.0'
27
+ end
@@ -0,0 +1,6 @@
1
+ require 'date'
2
+ require 'httparty'
3
+ require 'virtus'
4
+
5
+ require "dx/lookup/version"
6
+ require 'dx/lookup/qrz'
@@ -0,0 +1,81 @@
1
+ require_relative 'qrz/callsign'
2
+ require_relative 'qrz/entity'
3
+
4
+ module DX
5
+ module Lookup
6
+ class QRZ
7
+ class APIError < StandardError; end
8
+
9
+ include HTTParty
10
+
11
+ API_VERSION = '1.33'
12
+ AGENT = "dx-lookup-#{DX::Lookup::VERSION}"
13
+
14
+ base_uri "xmldata.qrz.com/xml/#{API_VERSION}/"
15
+
16
+ attr_reader :session_key
17
+
18
+ def initialize(username, password, options={})
19
+ @username, @password = username, password
20
+ end
21
+
22
+ def get_callsign(callsign)
23
+ login_if_needed!
24
+ uri = construct_uri(:callsign => callsign)
25
+ response = self.class.get(uri).parsed_response
26
+ check_for_error(response)
27
+
28
+ callsign_response = response['QRZDatabase']['Callsign']
29
+ Callsign.from_response(callsign_response)
30
+ end
31
+
32
+ def get_dxcc_entity(dxcc)
33
+ get_entities(dxcc.to_s).first
34
+ end
35
+
36
+ def get_all_entities
37
+ get_entities('all')
38
+ end
39
+
40
+ def get_callsign_entity(callsign)
41
+ get_entities(callsign).first
42
+ end
43
+
44
+ def create_session!
45
+ uri = construct_uri(:username => @username, :password => @password, :agent => AGENT)
46
+ response = self.class.get(uri)
47
+ response = response.parsed_response
48
+ check_for_error(response)
49
+
50
+ @session_key = response['QRZDatabase']['Session']['Key']
51
+ end
52
+
53
+ protected
54
+
55
+ def construct_uri(params={})
56
+ params = params.merge(:s => session_key) if session_key && !params[:s]
57
+ "?#{params.map { |k, v| "#{k}=#{v}" }.join(';')}"
58
+ end
59
+
60
+ def login_if_needed!
61
+ create_session! unless session_key
62
+ end
63
+
64
+ def check_for_error(parsed_response)
65
+ error = parsed_response['QRZDatabase']['Session']['Error']
66
+ message = parsed_response['QRZDatabase']['Session']['Message']
67
+ raise(APIError, message || error) if error
68
+ end
69
+
70
+ def get_entities(callsign)
71
+ login_if_needed!
72
+ uri = construct_uri(:dxcc => callsign)
73
+ response = self.class.get(uri).parsed_response
74
+ check_for_error(response)
75
+
76
+ dxccs = [response['QRZDatabase']['DXCC']].flatten
77
+ dxccs.map { |dxcc| Entity.from_response(dxcc) }
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,83 @@
1
+ module DX
2
+ module Lookup
3
+ class QRZ
4
+ class Callsign
5
+ include Virtus.model
6
+
7
+ attribute :callsign, String
8
+ attribute :aliases, Array[String]
9
+ attribute :dxcc, Integer
10
+ attribute :first_name, String
11
+ attribute :last_name, String
12
+ attribute :address_1, String
13
+ attribute :address_2, String
14
+ attribute :address_state, String
15
+ attribute :address_zip, String
16
+ attribute :address_country, String
17
+ attribute :address_dxcc, Integer
18
+ attribute :coordinate, Array[Float]
19
+ attribute :grid, String
20
+ attribute :county, String
21
+ attribute :dxcc_name, String
22
+ attribute :effective_date, Date
23
+ attribute :expiration_date, Date
24
+ attribute :fips, String
25
+ attribute :previous_callsign, String
26
+ attribute :license_class, String
27
+ attribute :license_codes, String
28
+ attribute :qsl_info, String
29
+ attribute :email, String
30
+ attribute :url, String
31
+ attribute :profile_views, Integer
32
+ attribute :qsl_accepted, Boolean
33
+ attribute :eqsl_accepted, Boolean
34
+ attribute :lotw_accepted, Boolean
35
+ attribute :cq_zone, Integer
36
+ attribute :itu_zone, Integer
37
+ attribute :birth_year, Integer
38
+ attribute :qrz_admin, String
39
+ attribute :iota, String
40
+ attribute :geo_source, Symbol
41
+
42
+ def self.from_response(xml)
43
+ Callsign.new(
44
+ :callsign => xml['call'],
45
+ :aliases => xml['aliases'].to_s.split(','),
46
+ :dxcc => xml['dxcc'],
47
+ :first_name => xml['fname'],
48
+ :last_name => xml['name'],
49
+ :address_1 => xml['addr1'],
50
+ :address_2 => xml['addr2'],
51
+ :address_state => xml['state'],
52
+ :address_zip => xml['zip'],
53
+ :address_country => xml['country'],
54
+ :address_dxcc => xml['ccode'],
55
+ :coordinate => [xml['lat'], xml['lon']],
56
+ :grid => xml['grid'],
57
+ :county => xml['county'],
58
+ :dxcc_name => xml['land'],
59
+ :effective_date => xml['efdate'],
60
+ :expiration_date => xml['expdate'],
61
+ :fips => xml['fips'],
62
+ :previous_callsign => xml['p_call'],
63
+ :license_class => xml['class'],
64
+ :license_codes => xml['codes'],
65
+ :qsl_info => xml['qslmgr'],
66
+ :email => xml['email'],
67
+ :url => xml['url'],
68
+ :profile_views => xml['u_views'],
69
+ :eqsl_accepted => xml['eqsl'],
70
+ :qsl_accepted => xml['mqsl'],
71
+ :cq_zone => xml['cqzone'],
72
+ :itu_zone => xml['ituzone'],
73
+ :birth_year => xml['born'],
74
+ :qrz_admin => xml['user'],
75
+ :lotw_accepted => xml['lotw'],
76
+ :iota => xml['iota'],
77
+ :geo_source => xml['geoloc']
78
+ )
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,35 @@
1
+ module DX
2
+ module Lookup
3
+ class QRZ
4
+ class Entity
5
+ include Virtus.model
6
+
7
+ attribute :dxcc, Integer
8
+ attribute :code_short, String
9
+ attribute :code_long, String
10
+ attribute :name, String
11
+ attribute :continent, String
12
+ attribute :itu_zone, Integer
13
+ attribute :cq_zone, Integer
14
+ attribute :time_zone, Integer
15
+ attribute :coordinate, Array[Float]
16
+ attribute :notes, String
17
+
18
+ def self.from_response(xml)
19
+ Entity.new(
20
+ :dxcc => xml['dxcc'],
21
+ :code_short => xml['cc'],
22
+ :code_long => xml['ccc'],
23
+ :name => xml['name'],
24
+ :continent => xml['continent'],
25
+ :itu_zone => xml['ituzone'],
26
+ :cq_zone => xml['cqzone'],
27
+ :time_zone => xml['timezone'],
28
+ :coordinate => [xml['lat'], xml['lon']],
29
+ :notes => xml['notes']
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module DX
2
+ module Lookup
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dx-lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rockwell Schrock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: virtus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description:
84
+ email:
85
+ - cq@ww1x.com
86
+ executables:
87
+ - console
88
+ - setup
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - dx-lookup.gemspec
100
+ - lib/dx/lookup.rb
101
+ - lib/dx/lookup/qrz.rb
102
+ - lib/dx/lookup/qrz/callsign.rb
103
+ - lib/dx/lookup/qrz/entity.rb
104
+ - lib/dx/lookup/version.rb
105
+ homepage: https://github.com/schrockwell/dx-lookup
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Callsign detail lookup
129
+ test_files: []