class Marinetraffic::Subscription

Attributes

api_key[RW]

Public Class Methods

new(api_key) click to toggle source
# File lib/marinetraffic/subscription.rb, line 5
def initialize(api_key)
  @api_key = api_key
end

Public Instance Methods

all(extended = false, options = {}) click to toggle source
# File lib/marinetraffic/subscription.rb, line 21
def all(extended = false, options = {})
  params = { timespan: 20, api_key: api_key }.merge(options)
  params[:msgtype] = :extended if extended
  response = API.call(:exportvessels, params)
  result = response.xpath("//row").map do |row|
    attributes = Marinetraffic::Vessel.map_attributes(row, extended)
    Marinetraffic::Vessel.new(attributes)
  end
end
find(mmsi, extended = false, options = {}) click to toggle source
# File lib/marinetraffic/subscription.rb, line 9
def find(mmsi, extended = false, options = {})
  params = { api_key: api_key }.merge(options)
  params[:msgtype] = :extended if extended
  response = API.call(:exportvessels, params)
  result = response.xpath("//row[@MMSI='#{mmsi}']")[0]

  if result != nil
    attributes = Marinetraffic::Vessel.map_attributes(result, extended)
    Marinetraffic::Vessel.new(attributes)
  end
end