Class: Marinetraffic::Subscription
- Inherits:
-
Object
- Object
- Marinetraffic::Subscription
- Defined in:
- lib/marinetraffic/subscription.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #all(extended = false, options = {}) ⇒ Object
- #find(mmsi, extended = false, options = {}) ⇒ Object
-
#initialize(api_key) ⇒ Subscription
constructor
A new instance of Subscription.
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_key ⇒ Object
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, = {}) params = { timespan: 20, api_key: api_key }.merge() 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, = {}) params = { api_key: api_key }.merge() 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 |