Class: Marinetraffic::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/marinetraffic/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Subscription

Returns a new instance of Subscription.



5
6
7
# File 'lib/marinetraffic/subscription.rb', line 5

def initialize(api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



3
4
5
# File 'lib/marinetraffic/subscription.rb', line 3

def api_key
  @api_key
end

Instance Method Details

#all(extended = false, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# 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 = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# 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