class Callsign

Attributes

json[RW]

Public Class Methods

new(callsign) click to toggle source
# File lib/callsign.rb, line 17
def initialize(callsign)
  json_uri = URI.parse "http://callook.info/#{callsign}/json"
  json_response = Net::HTTP.new(json_uri.host, json_uri.port).get(json_uri.path)
  raise InvalidHTTPResponseException if json_response.code.to_i > 200
  @json = JSON.parse json_response.body

  # Handle invalid/update before the user can do anything that
  # would error anyway.
  case @json['status']
  when 'INVALID'
    raise InvalidCallsignException, 'Invalid callsign'
  when 'UPDATING'
    raise CallookUpdateException, 'Callook.info offline for daily update'
  end
end

Public Instance Methods

method_missing(name) click to toggle source

This literally passes to the JSON response that we get. This means that if the server returns a string for a key, you will get that. If it returns a hash with more info, so will we. Hey, this is 2.0.0 baby. We're allowed to play hardball.

# File lib/callsign.rb, line 41
def method_missing(name)
  @json[name.to_s]
end