marinetraffic 0.0.3.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/marinetraffic/api.rb +14 -3
- data/lib/marinetraffic/version.rb +1 -1
- data/lib/marinetraffic/vessel.rb +90 -28
- data/marinetraffic.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 963b7256b9a67232841c756caff1c328b95f6bc6
|
4
|
+
data.tar.gz: d293a6882f22a6ea43a6e674f70d2d6995779944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f896e46875f2b57af4fbb4c28fe4db5c898608294a1d3c92540efd2ae036fae80063a859653826fccd701574eddab9e95bfb03b1072d9e57129e074c59c5f19
|
7
|
+
data.tar.gz: 9ae87d9b8c14b520cc161a3ba2f9a801d16d969dae9b9f358128da12b6585781d51e95ff7adb1f19a489652e45284b7cabf90e7cb2bfbd445b903bb1f6ade7f1
|
data/lib/marinetraffic/api.rb
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'nokogiri'
|
3
3
|
|
4
4
|
API_URL = "http://services.marinetraffic.com/api"
|
5
5
|
|
6
6
|
module Marinetraffic
|
7
7
|
class API
|
8
8
|
def self.call(name, params = {})
|
9
|
-
params[:protocol] = :
|
9
|
+
params[:protocol] = :xml
|
10
10
|
param_string = params.map{|attr| "#{attr.first}:#{attr.last}"}.join('/')
|
11
11
|
url = "#{API_URL}/#{name}/#{Marinetraffic.api_key}/#{param_string}"
|
12
12
|
response = Faraday.get(url)
|
13
|
+
doc = Nokogiri::XML(response.body)
|
14
|
+
raise_exception(doc) if doc.xpath('//ERROR').any?
|
15
|
+
doc
|
13
16
|
end
|
17
|
+
|
18
|
+
def self.raise_exception(doc)
|
19
|
+
message = doc.xpath("//ERROR")[0]['DESCRIPTION']
|
20
|
+
raise MarinetrafficException.new(message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class MarinetrafficException < Exception
|
14
25
|
end
|
15
|
-
end
|
26
|
+
end
|
data/lib/marinetraffic/vessel.rb
CHANGED
@@ -34,41 +34,103 @@ module Marinetraffic
|
|
34
34
|
params = { mmsi: mmsi, timespan: 20 }.merge(options)
|
35
35
|
params[:msgtype] = :extended if extended
|
36
36
|
response = API.call(:exportvessel, params)
|
37
|
-
|
38
|
-
attributes = map_attributes(list, extended)
|
37
|
+
attributes = map_attributes(response.xpath("//row")[0], extended)
|
39
38
|
new(attributes)
|
40
39
|
end
|
41
40
|
|
42
|
-
def self.map_attributes(
|
41
|
+
def self.map_attributes(response, extended)
|
43
42
|
attributes = {}
|
44
|
-
attributes["mmsi"] =
|
45
|
-
attributes["lat"] =
|
46
|
-
attributes["lon"] =
|
47
|
-
attributes["speed"] =
|
48
|
-
attributes["course"] =
|
43
|
+
attributes["mmsi"] = response['MMSI']
|
44
|
+
attributes["lat"] = response['LAT'].to_f
|
45
|
+
attributes["lon"] = response['LON'].to_f
|
46
|
+
attributes["speed"] = response['SPEED'].to_i
|
47
|
+
attributes["course"] = response['COURSE'].to_i
|
49
48
|
if extended
|
50
|
-
attributes["timestamp"] =
|
51
|
-
attributes["ship_name"] =
|
52
|
-
attributes["ship_type"] =
|
53
|
-
attributes["imo"] =
|
54
|
-
attributes["callsign"] =
|
55
|
-
attributes["flag"] =
|
56
|
-
attributes["current_port"] =
|
57
|
-
attributes["last_port"] =
|
58
|
-
attributes["last_port_time"] =
|
59
|
-
attributes["destination"] =
|
60
|
-
attributes["eta"] =
|
61
|
-
attributes["length"] =
|
62
|
-
attributes["width"] =
|
63
|
-
attributes["draught"] =
|
64
|
-
attributes["grt"] =
|
65
|
-
attributes["dwt"] =
|
66
|
-
attributes["year_built"] =
|
49
|
+
attributes["timestamp"] = response['TIMESTAMP']
|
50
|
+
attributes["ship_name"] = response['SHIPNAME']
|
51
|
+
attributes["ship_type"] = response['SHIPTYPE'].to_i
|
52
|
+
attributes["imo"] = response['IMO']
|
53
|
+
attributes["callsign"] = response['CALLSIGN']
|
54
|
+
attributes["flag"] = response['FLAG']
|
55
|
+
attributes["current_port"] = response['CURRENT_PORT']
|
56
|
+
attributes["last_port"] = response['LAST_PORT']
|
57
|
+
attributes["last_port_time"] = response['LAST_PORT_TIME']
|
58
|
+
attributes["destination"] = response['DESTINATION']
|
59
|
+
attributes["eta"] = response['ETA']
|
60
|
+
attributes["length"] = response['LENGTH'].to_i
|
61
|
+
attributes["width"] = response['WIDTH'].to_i
|
62
|
+
attributes["draught"] = response['DRAUGHT'].to_i
|
63
|
+
attributes["grt"] = response['GRT'].to_i
|
64
|
+
attributes["dwt"] = response['DWT'].to_i
|
65
|
+
attributes["year_built"] = response['YEAR_BUILT'].to_i
|
67
66
|
else
|
68
|
-
attributes["status"] =
|
69
|
-
attributes["timestamp"] =
|
67
|
+
attributes["status"] = response['STATUS'].to_i
|
68
|
+
attributes["timestamp"] = response['TIMESTAMP']
|
70
69
|
end
|
71
70
|
attributes
|
72
71
|
end
|
72
|
+
|
73
|
+
# http://help.marinetraffic.com/hc/en-us/articles/203990998-What-is-the-significance-of-the-AIS-Navigational-Status-Values-
|
74
|
+
def status_human
|
75
|
+
case status
|
76
|
+
when 0
|
77
|
+
'under way using engine'
|
78
|
+
when 1
|
79
|
+
'at anchor'
|
80
|
+
when 2
|
81
|
+
'not under command '
|
82
|
+
when 3
|
83
|
+
'restricted maneuverability'
|
84
|
+
when 4
|
85
|
+
'constrained by her draught'
|
86
|
+
when 5
|
87
|
+
'moored'
|
88
|
+
when 6
|
89
|
+
'aground '
|
90
|
+
when 7
|
91
|
+
'engaged in fishing'
|
92
|
+
when 8
|
93
|
+
'under way sailing'
|
94
|
+
when 9
|
95
|
+
'reserved for future amendment of navigational status for ships carrying DG, HS, or MP, or IMO hazard or pollutant category C, high-speed craft (HSC)'
|
96
|
+
when 10
|
97
|
+
'reserved for future amendment of navigational status for ships carrying dangerous goods (DG), harmful substances (HS) or marine pollutants (MP), or IMO hazard or pollutant category A, wing in ground (WIG)'
|
98
|
+
when 11
|
99
|
+
'power-driven vessel towing astern (regional use)'
|
100
|
+
when 12
|
101
|
+
'power-driven vessel pushing ahead or towing alongside (regional use)'
|
102
|
+
when 13
|
103
|
+
'reserved for future use'
|
104
|
+
when 14
|
105
|
+
'AIS-SART (active), MOB-AIS, EPIRB-AIS'
|
106
|
+
when 15
|
107
|
+
'undefined = default (also used by AIS-SART, MOB-AIS and EPIRB-AIS under test)'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# http://help.marinetraffic.com/hc/en-us/articles/205579997-What-is-the-significance-of-the-AIS-SHIPTYPE-number-
|
112
|
+
def ship_type_human
|
113
|
+
return if ship_type == nil
|
114
|
+
case ship_type / 10
|
115
|
+
when 1
|
116
|
+
'Reserved'
|
117
|
+
when 2
|
118
|
+
'Wing In Ground'
|
119
|
+
when 3
|
120
|
+
'Special Category'
|
121
|
+
when 4
|
122
|
+
'High-Speed Craft'
|
123
|
+
when 5
|
124
|
+
'Special Category'
|
125
|
+
when 6
|
126
|
+
'Passenger'
|
127
|
+
when 7
|
128
|
+
'Cargo'
|
129
|
+
when 8
|
130
|
+
'Tanker'
|
131
|
+
when 9
|
132
|
+
'Other'
|
133
|
+
end
|
134
|
+
end
|
73
135
|
end
|
74
|
-
end
|
136
|
+
end
|
data/marinetraffic.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_dependency "faraday"
|
23
|
-
spec.add_dependency "
|
23
|
+
spec.add_dependency "nokogiri"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", ">= 1.7.9"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marinetraffic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Kuhn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|