marinetraffic 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ab07ecf1a910c6ae8f99a2939cbcae009072f44
4
- data.tar.gz: 5b4a121d569831974c084de80b023b8434b0dafe
3
+ metadata.gz: d0009285cd9ec60abb0264806ae7e1efdd054828
4
+ data.tar.gz: d9a588dba5761380f20b6e3c59d09d926c992cf1
5
5
  SHA512:
6
- metadata.gz: 31a763348e24afa158793877569edccbafa0c94b54c65066ae45886eb3cba187bf64249099f7d556d348a067cf9f95d892ecbe980ef3ae0c5771a225b13117cd
7
- data.tar.gz: fe58b988362cc59f33d34428dfd1f737964f417f9b54be4fb1f209306bf19cb7b1eabe6665f87f71c4b84766d30de2cd52bca44af1710137e4447befd6eca05f
6
+ metadata.gz: 6aa89875c1c71a660b66b97b39e438b24fd77d0e081469861574e7f6c0a8c6b8508be6bd5ac90d9ac629de80ad0860f37784993341c16a3b664ca4a6209572e3
7
+ data.tar.gz: 729f6793faab79abe5e610748e2f23427290da7d5b47b6582e6997ac156e78d5311c892818312d9c9ed5220a0141ba2a20f4dd70dce6f352bafae4d27c053b4b
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /**/env.yml/
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
3
+ - 2.2.2
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :minitest do
2
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
3
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
4
+ watch(%r{^test/minitest_helper\.rb$}) { 'test' }
5
+ end
data/README.md CHANGED
@@ -23,7 +23,27 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- TODO: Write usage instructions here
26
+ ### Authentication
27
+
28
+ You authenticate to the MarineTraffic API by providing your secret API key in the request.
29
+ To use your API key, you need only set Marinetraffic.api_key equal to the key. The Ruby library will automatically send this key in each request.
30
+
31
+ ```ruby
32
+ require "stripe"
33
+ Marinetraffic.api_key = "2571121d07b9ce09c1abc34db75606a840a2c68c"
34
+ ```
35
+
36
+ ### Find vessels
37
+
38
+ You can call vessel informations by the Vessel.find method. This method accepts a *MMSI Number* and an optional flag for *extended data* (false by default).
39
+
40
+ ```ruby
41
+ vessel = Marinetraffic::Vessel.find("311026000", true)
42
+ vessel.mmsi # => "311026000"
43
+ vessel.lat # => "54.520730"
44
+ vessel.lng # => "10.421800"
45
+ vessel.ship_name # => "NINA"
46
+ ```
27
47
 
28
48
  ## Development
29
49
 
data/lib/marinetraffic.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require "marinetraffic/version"
2
+ require "marinetraffic/vessel"
3
+ require "marinetraffic/api"
2
4
 
3
5
  module Marinetraffic
4
- # Your code goes here...
6
+ class << self
7
+ attr_accessor :api_key
8
+ end
5
9
  end
@@ -0,0 +1,15 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ API_URL = "http://services.marinetraffic.com/api"
5
+
6
+ module Marinetraffic
7
+ class API
8
+ def self.call(name, params = {})
9
+ params[:protocol] = :json
10
+ param_string = params.map{|attr| "#{attr.first}:#{attr.last}"}.join('/')
11
+ url = "#{API_URL}/#{name}/#{Marinetraffic.api_key}/#{param_string}"
12
+ response = Faraday.get(url)
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Marinetraffic
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,68 @@
1
+ module Marinetraffic
2
+ class Vessel
3
+
4
+ attr_reader :mmsi, :lat, :lon, :speed, :course, :status, :timestamp
5
+ attr_reader :ship_type, :ship_name, :imo, :callsign, :flag, :current_port, :last_port, :last_port_time, :destination, :eta, :length, :draught, :grt, :dwt, :year_built
6
+
7
+ def initialize(attributes = {})
8
+ @mmsi = attributes["mmsi"]
9
+ @lat = attributes["lat"]
10
+ @lon = attributes["lon"]
11
+ @speed = attributes["speed"]
12
+ @course = attributes["course"]
13
+ @status = attributes["status"]
14
+ @timestamp = attributes["timestamp"]
15
+ @ship_type = attributes["ship_type"]
16
+ @ship_name = attributes["ship_name"]
17
+ @imo = attributes["imo"]
18
+ @callsign = attributes["callsign"]
19
+ @flag = attributes["flag"]
20
+ @current_port = attributes["current_port"]
21
+ @last_port = attributes["last_port"]
22
+ @last_port_time = attributes["last_port_time"]
23
+ @destination = attributes["destination"]
24
+ @eta = attributes["eta"]
25
+ @length = attributes["length"]
26
+ @draught = attributes["draught"]
27
+ @grt = attributes["grt"]
28
+ @dwt = attributes["dwt"]
29
+ @year_built = attributes["year_built"]
30
+ end
31
+
32
+ def self.find(mmsi, extended = false)
33
+ params = { mmsi: mmsi, timespan: 20 }
34
+ params[:msgtype] = :extended if extended
35
+ response = API.call(:exportvessel, params)
36
+ list = JSON.parse(response.body).first
37
+ attributes = map_attributes(list)
38
+ new(attributes)
39
+ end
40
+
41
+ def self.map_attributes(list)
42
+ attributes = {}
43
+ attributes["mmsi"] = list.shift
44
+ attributes["lat"] = list.shift
45
+ attributes["lon"] = list.shift
46
+ attributes["speed"] = list.shift
47
+ attributes["course"] = list.shift
48
+ attributes["status"] = list.shift
49
+ attributes["timestamp"] = list.shift
50
+ attributes["ship_type"] = list.shift
51
+ attributes["ship_name"] = list.shift
52
+ attributes["imo"] = list.shift
53
+ attributes["callsign"] = list.shift
54
+ attributes["flag"] = list.shift
55
+ attributes["current_port"] = list.shift
56
+ attributes["last_port"] = list.shift
57
+ attributes["last_port_time"] = list.shift
58
+ attributes["destination"] = list.shift
59
+ attributes["eta"] = list.shift
60
+ attributes["length"] = list.shift
61
+ attributes["draught"] = list.shift
62
+ attributes["grt"] = list.shift
63
+ attributes["dwt"] = list.shift
64
+ attributes["year_built"] = list.shift
65
+ attributes
66
+ end
67
+ end
68
+ end
@@ -19,6 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency "faraday"
23
+ spec.add_dependency "json"
24
+
22
25
  spec.add_development_dependency "bundler", "~> 1.9"
23
26
  spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "guard"
28
+ spec.add_development_dependency "guard-minitest", "~> 2.4.4"
29
+ spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "vcr"
31
+ spec.add_development_dependency "webmock"
24
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marinetraffic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Kuhn
@@ -10,6 +10,34 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +66,76 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.4.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.4.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
41
139
  description: 'This is a API wrapper for MarineTraffic written in Ruby. You can find
42
140
  more information about the API of MarineTraffic on this page: https://www.marinetraffic.com/en/ais-api-services'
43
141
  email:
@@ -50,13 +148,16 @@ files:
50
148
  - ".travis.yml"
51
149
  - CODE_OF_CONDUCT.md
52
150
  - Gemfile
151
+ - Guardfile
53
152
  - LICENSE.txt
54
153
  - README.md
55
154
  - Rakefile
56
155
  - bin/console
57
156
  - bin/setup
58
157
  - lib/marinetraffic.rb
158
+ - lib/marinetraffic/api.rb
59
159
  - lib/marinetraffic/version.rb
160
+ - lib/marinetraffic/vessel.rb
60
161
  - marinetraffic.gemspec
61
162
  homepage: https://github.com/mordaroso/marinetraffic.
62
163
  licenses: