Class: Searates::API::LogisticsExplorer

Inherits:
Object
  • Object
show all
Defined in:
lib/searates/api/logistics_explorer.rb

Constant Summary collapse

BASE_URL =
'https://sirius.searates.com/port/api-'

Class Method Summary collapse

Class Method Details

.get_air_rates(lat_from, long_from, lat_to, long_to, weight) ⇒ Object



23
24
25
26
27
# File 'lib/searates/api/logistics_explorer.rb', line 23

def self.get_air_rates(lat_from, long_from, lat_to, long_to, weight)
  [lat_from, long_from, lat_to, long_to, weight].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
  request_url = "#{BASE_URL}air?apiKey=#{Searates.configuration.api_key}&lat_from=#{lat_from}&lng_from=#{long_from}&lat_to=#{lat_to}&lng_to=#{long_to}&weight=#{weight}"
  response = JSON.parse(URI.open(request_url).read)
end

.get_fcl_rates(lat_from, long_from, lat_to, long_to, route_info = false) ⇒ Object



5
6
7
8
9
# File 'lib/searates/api/logistics_explorer.rb', line 5

def self.get_fcl_rates(lat_from, long_from, lat_to, long_to, route_info=false)
  [lat_from, long_from, lat_to, long_to].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
  request_url = "#{BASE_URL}fcl?apiKey=#{Searates.configuration.api_key}&lat_from=#{lat_from}&lng_from=#{long_from}&lat_to=#{lat_to}&lng_to=#{long_to}&route_info=#{route_info}"
  response = JSON.parse(URI.open(request_url).read)
end

.get_lcl_rates(lat_from, long_from, lat_to, long_to, weight, volume) ⇒ Object



11
12
13
14
15
# File 'lib/searates/api/logistics_explorer.rb', line 11

def self.get_lcl_rates(lat_from, long_from, lat_to, long_to, weight, volume)
  [lat_from, long_from, lat_to, long_to, weight, volume].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
  request_url = "#{BASE_URL}lcl?apiKey=#{Searates.configuration.api_key}&lat_from=#{lat_from}&lng_from=#{long_from}&lat_to=#{lat_to}&lng_to=#{long_to}&weight=#{weight}&volume=#{volume}"
  response = JSON.parse(URI.open(request_url).read)
end

.get_rail_rates(lat_from, long_from, lat_to, long_to) ⇒ Object



29
30
31
32
33
# File 'lib/searates/api/logistics_explorer.rb', line 29

def self.get_rail_rates(lat_from, long_from, lat_to, long_to)
  [lat_from, long_from, lat_to, long_to].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
  request_url = "#{BASE_URL}rail?apiKey=#{Searates.configuration.api_key}&lat_from=#{lat_from}&lng_from=#{long_from}&lat_to=#{lat_to}&lng_to=#{long_to}"
  response = JSON.parse(URI.open(request_url).read)
end

.get_road_rates(lat_from, long_from, lat_to, long_to, weight, volume, type = 'CONTAINER', container = '20st') ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/searates/api/logistics_explorer.rb', line 35

def self.get_road_rates(lat_from, long_from, lat_to, long_to, weight, volume, type='CONTAINER', container='20st')
  [lat_from, long_from, lat_to, long_to, weight, volume, type, container].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
  request_url = "#{BASE_URL}road?apiKey=#{Searates.configuration.api_key}&lat_from=#{lat_from}&lng_from=#{long_from}&lat_to=#{lat_to}&lng_to=#{long_to}&weight=#{weight}&volume=#{volume}"
  if type
    raise Searates::Errors::API::InvalidParameterValue unless ['FCL', 'LCL', 'CONTAINER'].include? type.upcase
    request_url += "&type=#{type.upcase}"
  end
  if container
    raise Searates::Errors::API::InvalidParameterValue unless container.downcase =~ /20st|40st|40hq|20ref|40ref/
    request_url += "&container=#{container.downcase}"
  end
  response = JSON.parse(URI.open(request_url).read)
end

.get_sea_route(lat_from, long_from, lat_to, long_to) ⇒ Object



17
18
19
20
21
# File 'lib/searates/api/logistics_explorer.rb', line 17

def self.get_sea_route(lat_from, long_from, lat_to, long_to)
  [lat_from, long_from, lat_to, long_to].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
  request_url = "#{BASE_URL}path?apiKey=#{Searates.configuration.api_key}&lat_from=#{lat_from}&lng_from=#{long_from}&lat_to=#{lat_to}&lng_to=#{long_to}"
  response = JSON.parse(URI.open(request_url).read)
end