callsign 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/callsign.rb +34 -108
  2. metadata +39 -16
  3. data/README +0 -32
@@ -1,110 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rexml/document'
3
- require 'open-uri'
4
- class CallSign
5
- def initialize(callsign,prefixes=false)
6
- @callinfo = REXML::Document.new(open("http://callook.info/index.php?callsign=#{callsign}&display=xml"))
7
- end
8
-
9
- def address(sep = "\n")
10
- @callinfo.elements.each("callook/address") do |ele|
11
- return ele.elements['line1'].text + sep + ele.elements['line2'].text
12
- end
13
- end
14
-
15
- def name
16
- @callinfo.elements.each("callook") do |ele|
17
- return ele.elements['name'].text
18
- end
19
- end
20
-
21
- def callsign
22
- @callinfo.elements.each("callook/current") do |ele|
23
- return ele.elements['callsign'].text
24
- end
25
- end
26
-
27
- def previouscallsign
28
- @callinfo.elements.each("callook/previous") do |ele|
29
- return ele.elements['callsign'].text
30
- end
31
- end
32
-
33
- def trusteecallsign
34
- @callinfo.elements.each("callook/trustee") do |ele|
35
- return ele.elements['callsign'].text
36
- end
37
- end
38
-
39
- def trusteename
40
- @callinfo.elements.each("callook/trustee") do |ele|
41
- return ele.elements['name'].text
42
- end
43
- end
44
-
45
- def type
46
- @callinfo.elements.each("callook") do |ele|
47
- return ele.elements['type'].text
48
- end
49
- end
50
-
51
- def status
52
- @callinfo.elements.each("callook") do |ele|
53
- return ele.elements['status'].text
54
- end
55
- end
56
-
57
- def class
58
- @callinfo.elements.each("callook/current") do |ele|
59
- return ele.elements['class'].text
60
- end
61
- end
62
-
63
- def previousclass
64
- @callinfo.elements.each("callook/previous") do |ele|
65
- return ele.elements['class'].text
66
- end
67
- end
68
-
69
- def latitude
70
- @callinfo.elements.each("callook/location") do |ele|
71
- return ele.elements['latitude'].text
72
- end
73
- end
74
-
75
- def longitude
76
- @callinfo.elements.each("callook/location") do |ele|
77
- return ele.elements['logitude'].text
78
- end
79
- end
80
-
81
- def gridsquare
82
- @callinfo.elements.each("callook/location") do |ele|
83
- return ele.elements['gridsquare'].text
84
- end
85
- end
86
-
87
- def grantdate
88
- @callinfo.elements.each("callook/otherinfo") do |ele|
89
- return ele.elements['grantdate'].text
90
- end
91
- end
92
-
93
- def expirydate
94
- @callinfo.elements.each("callook/otherinfo") do |ele|
95
- return ele.elements['expirydate'].text
96
- end
97
- end
98
-
99
- def lastaction
100
- @callinfo.elements.each("callook/otherinfo") do |ele|
101
- return ele.elements['lastactiondate'].text
102
- end
103
- end
104
-
105
- def frn
106
- @callinfo.elements.each("callook/otherinfo") do |ele|
107
- return ele.elements['frn'].text
108
- end
109
- end
2
+ # encoding: utf-8
3
+ # (c) 2011-present. Ricky Elrod <ricky@elrod.me>
4
+ # Released under the MIT license.
5
+ require 'rubygems'
6
+ require 'uri'
7
+ require 'net/http'
8
+ require 'json'
9
+
10
+ class InvalidCallsignException < StandardError; end
11
+ class CallookUpdateException < StandardError; end
12
+
13
+ class Callsign
14
+ def initialize(callsign)
15
+ json_uri = URI.parse "http://callook.info/#{callsign}/json"
16
+ json_response = Net::HTTP.new(json_uri.host, json_uri.port).get(json_uri.path).body
17
+ @json = JSON.parse json_response
18
+
19
+ # Handle invalid/update before the user can do anything that
20
+ # would error anyway.
21
+ case @json['status']
22
+ when 'INVALID'
23
+ raise InvalidCallsignException, 'Invalid callsign'
24
+ when 'UPDATING'
25
+ raise CallookUpdateException, 'Callook.info offline for daily update'
26
+ end
27
+ end
28
+
29
+ # This literally passes to the JSON response that we get.
30
+ # This means that if the server returns a string for a key, you will get that.
31
+ # If it returns a hash with more info, so will we. Hey, this is 2.0.0 baby.
32
+ # We're allowed to play hardball.
33
+ def method_missing(name)
34
+ @json[name.to_s]
35
+ end
110
36
  end
metadata CHANGED
@@ -1,20 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callsign
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
5
11
  platform: ruby
6
12
  authors:
7
- - Rick E.
13
+ - Ricky Elrod
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-07-30 00:00:00 -04:00
13
- default_executable:
14
- dependencies: []
15
-
16
- description: This RubyGem allows Ruby Coders to access the information contained on callook.info, an online Amateur Radio Callsign Lookup service, run by Joshua Dick, W1JDD.
17
- email: codeblock@eighthbit.net
18
+ date: 2011-12-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Provides a simple Ruby interface to the callook.info API by Joshua Dick, W1JDD.
35
+ email: ricky@elrod.me
18
36
  executables: []
19
37
 
20
38
  extensions: []
@@ -22,10 +40,8 @@ extensions: []
22
40
  extra_rdoc_files: []
23
41
 
24
42
  files:
25
- - README
26
43
  - lib/callsign.rb
27
- has_rdoc: true
28
- homepage: http://github.com/codeblock/CallSignRb
44
+ homepage: http://github.com/codeblock/callsign-gem
29
45
  licenses: []
30
46
 
31
47
  post_install_message:
@@ -34,23 +50,30 @@ rdoc_options: []
34
50
  require_paths:
35
51
  - lib
36
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
37
54
  requirements:
38
55
  - - ">="
39
56
  - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
40
60
  version: "0"
41
- version:
42
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
43
63
  requirements:
44
64
  - - ">="
45
65
  - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
46
69
  version: "0"
47
- version:
48
70
  requirements: []
49
71
 
50
72
  rubyforge_project: CallSignRb
51
- rubygems_version: 1.3.4
73
+ rubygems_version: 1.8.5
52
74
  signing_key:
53
- specification_version: 2
54
- summary: This RubyGem allows Ruby Coders to access the information contained on callook.info, an online Amateur Radio Callsign Lookup service, run by Joshua Dick, W1JDD.
75
+ specification_version: 3
76
+ summary: Look up United States Amateur (ham) Radio callsign information.
55
77
  test_files: []
56
78
 
79
+ has_rdoc:
data/README DELETED
@@ -1,32 +0,0 @@
1
- This RubyGem allows Ruby Coders to access the information contained on callook.info, an online Amateur Radio Callsign Lookup service, run by Joshua Dick, W1JDD.
2
-
3
- The gem is easy to use and should work something like this:
4
-
5
- #!/usr/bin/ruby
6
- require 'rubygems'
7
- require 'callsign'
8
- call = CallSign.new("w1aw")
9
- puts call.address
10
-
11
-
12
- -------------------------------------------------
13
-
14
- Well since I can't figure rdoc out, I'll tell you that CallSignRb has the following functions:
15
-
16
- address(sep = "\n") - you can specify a separator if you don't want newlines.
17
- name
18
- callsign
19
- previouscallsign
20
- trusteecallsign
21
- trusteename
22
- type
23
- status
24
- class
25
- previousclass
26
- latitude
27
- longitude
28
- gridsquare
29
- grantdate
30
- expirydate
31
- lastaction
32
- frn