searates 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ccfa3f04be9a5e54658770d3edfd8d0301c5ec6ccfd05322c1b8f56772c9da51
4
+ data.tar.gz: 215848dfda17abf1475e84beb4d0ef93b3453408d9d8f88e4822c4dd479f7a5b
5
+ SHA512:
6
+ metadata.gz: '08e1bd4401b4dabaf40ce442c0f7739f09eb5b0bdf18a8f325fee881d9d5a758896d521d571048c17ea94a200a1f29db63637f97b37da64cee0f9cc84188886c'
7
+ data.tar.gz: 703633c976bdffaeaa1c822604731bdd0863adf6273e368ce67eb0d93dff153f5f082a42136fd1791c62efa36fc57a249440a38ef20ed2f7b40c6e075f2a1627
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in searates.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ searates (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.1)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.4)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 2.0)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ searates!
33
+
34
+ BUNDLED WITH
35
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 André Galatti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # SeaRates
2
+
3
+ Ruby gem to make requests to SeaRates REST API in a simple and easy way.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'searates'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install searates
20
+
21
+ ## Usage
22
+
23
+ Run the Generator:
24
+
25
+ $ rails g searates:install
26
+
27
+
28
+ Place your API Key as an environment variable at your server or replace the ENV value in the initializer `initializers/searates.rb`
29
+
30
+ ```ruby
31
+ Searates.configure do |config|
32
+ config.api_key = ENV['SEARATES_API_KEY']
33
+ #config.api_key = 'XXXXXXXXXXXXXXXX'
34
+ end
35
+ ```
36
+
37
+ ### Logistics Explorer - FCL Rates
38
+
39
+ To make requests, simple call the API you want and store the return in a variable. e.g.
40
+ ```ruby
41
+ response = Searates::API::LogisticsExplorer.get_fcl_rates(lat_from, lng_from, lat_to, lng_to)
42
+ ```
43
+
44
+ you can also pass *true* after the lng_to value if you also want the route info.
45
+
46
+ ### Logistics Explorer - LCL Rates
47
+
48
+ - Weight of cargo in *kg*
49
+ - Volume of cargo in *CBM*
50
+
51
+ ```ruby
52
+ response = Searates::API::LogisticsExplorer.get_lcl_rates(lat_from, lng_from, lat_to, lng_to, volume, weight)
53
+ ```
54
+
55
+ ### Logistics Explorer - Sea Route
56
+
57
+ ```ruby
58
+ response = Searates::API::LogisticsExplorer.get_sea_route(lat_from, lng_from, lat_to, lng_to)
59
+ ```
60
+
61
+ ### Logistics Explorer - Air Rates
62
+
63
+ - Weight of cargo in *tons*
64
+
65
+ ```ruby
66
+ response = Searates::API::LogisticsExplorer.get_air_rates(lat_from, lng_from, lat_to, lng_to, weight)
67
+ ```
68
+
69
+ ### Logistics Explorer - Rail Rates
70
+
71
+ ```ruby
72
+ response = Searates::API::LogisticsExplorer.get_rail_rates(lat_from, lng_from, lat_to, lng_to)
73
+ ```
74
+
75
+ ### Logistics Explorer - Road Rates
76
+
77
+ - Weight of cargo in *kg*
78
+ - Volume of cargo in *CBM*
79
+ - Type of shipment. The available values for this parameter are: `LTL | FTL | CONTAINER` *(optional) Default value: CONTAINER*
80
+ - Container type. The available values for this parameter are: `20st | 40st | 40hq | 20ref | 40ref` *(optional) Default value: 20st*
81
+
82
+ ```ruby
83
+ response = Searates::API::LogisticsExplorer.get_road_rates(lat_from, lng_from, lat_to, lng_to, volume, weight, type, container)
84
+ ```
85
+
86
+ ## For more information, please visit the [official API documentation](https://www.searates.com/reference/platform-api/)
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andre-lgf/searates.
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "searates"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ module Searates
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../../templates', __FILE__)
5
+
6
+ desc 'Creates a SeaRates initializer file in your application.'
7
+
8
+ def copy_initializer
9
+ template 'searates.rb', 'config/initializers/searates.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ Searates.configure do |config|
2
+ config.api_key = ENV['SEARATES_API_KEY']
3
+ end
data/lib/searates.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "searates/version"
2
+ require 'searates/configuration'
3
+ require 'searates/errors'
4
+ require 'searates/api'
5
+
6
+ module Searates
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.reset
16
+ @configuration = Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ require 'searates/api/logistics_explorer'
2
+ require 'open-uri'
@@ -0,0 +1,50 @@
1
+ module Searates
2
+ module API
3
+ class LogisticsExplorer
4
+ BASE_URL = 'https://sirius.searates.com/port/api-'
5
+ def self.get_fcl_rates(lat_from, long_from, lat_to, long_to, route_info=false)
6
+ [lat_from, long_from, lat_to, long_to].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
7
+ 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}"
8
+ response = JSON.parse(URI.open(request_url).read)
9
+ end
10
+
11
+ def self.get_lcl_rates(lat_from, long_from, lat_to, long_to, weight, volume)
12
+ [lat_from, long_from, lat_to, long_to, weight, volume].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
13
+ 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}"
14
+ response = JSON.parse(URI.open(request_url).read)
15
+ end
16
+
17
+ def self.get_sea_route(lat_from, long_from, lat_to, long_to)
18
+ [lat_from, long_from, lat_to, long_to].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
19
+ 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}"
20
+ response = JSON.parse(URI.open(request_url).read)
21
+ end
22
+
23
+ def self.get_air_rates(lat_from, long_from, lat_to, long_to, weight)
24
+ [lat_from, long_from, lat_to, long_to, weight].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
25
+ 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}"
26
+ response = JSON.parse(URI.open(request_url).read)
27
+ end
28
+
29
+ def self.get_rail_rates(lat_from, long_from, lat_to, long_to)
30
+ [lat_from, long_from, lat_to, long_to].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
31
+ 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}"
32
+ response = JSON.parse(URI.open(request_url).read)
33
+ end
34
+
35
+ def self.get_road_rates(lat_from, long_from, lat_to, long_to, weight, volume, type='CONTAINER', container='20st')
36
+ [lat_from, long_from, lat_to, long_to, weight, volume, type, container].each{|param| raise Searates::Errors::API::MissingParameters, "Missing parameter: #{param}" unless param}
37
+ 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}&volume=#{volume}"
38
+ if type
39
+ raise Searates::Errors::API::InvalidParameterValue unless ['FCL', 'LCL', 'CONTAINER'].include? type.upcase
40
+ request_url += "&type=#{type.upcase}"
41
+ end
42
+ if container
43
+ raise Searates::Errors::API::InvalidParameterValue unless container.downcase =~ /20st|40st|40hq|20ref|40ref/
44
+ request_url += "&container=#{container.downcase}"
45
+ end
46
+ response = JSON.parse(URI.open(request_url).read)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ module Searates
2
+ class Configuration
3
+ attr_accessor :api_key
4
+
5
+ def initialize
6
+ @api_key ||= nil
7
+ end
8
+
9
+ def api_key
10
+ raise Searates::Errors::Configuration, 'SeaRates API Key missing!' unless @api_key
11
+ @api_key
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module Searates
2
+ module Errors
3
+ class Configuration < StandardError; end
4
+
5
+ module API
6
+ class MissingParameters < StandardError; end
7
+ class InvalidParameterValue < StandardError; end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Searates
2
+ VERSION = "0.1.1"
3
+ end
data/searates.gemspec ADDED
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "searates/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "searates"
8
+ spec.version = Searates::VERSION
9
+ spec.authors = ["André Galatti"]
10
+ spec.email = ["andreluisgalatti@hotmail.com"]
11
+
12
+ spec.summary = %q{SeaRates' REST API Consumer}
13
+ spec.homepage = "https://github.com/andre-lgf/searates"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/andre-lgf/searates"
23
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: searates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - André Galatti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - andreluisgalatti@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/generators/searates/install_generator.rb
73
+ - lib/generators/templates/searates.rb
74
+ - lib/searates.rb
75
+ - lib/searates/api.rb
76
+ - lib/searates/api/logistics_explorer.rb
77
+ - lib/searates/configuration.rb
78
+ - lib/searates/errors.rb
79
+ - lib/searates/version.rb
80
+ - searates.gemspec
81
+ homepage: https://github.com/andre-lgf/searates
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ homepage_uri: https://github.com/andre-lgf/searates
86
+ source_code_uri: https://github.com/andre-lgf/searates
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.7.6
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: SeaRates' REST API Consumer
107
+ test_files: []