ninja_van 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8297ee72de90f1aae35dbcc55e45c9c4ef45cc7e33b2321b79297c00fb2141c4
4
+ data.tar.gz: f58ec85f3f33df65945cc92050efc24c53b5d389ad50176ada56daf6ad8266c7
5
+ SHA512:
6
+ metadata.gz: 072717163c7434eb40c9fcb554885f31def5fb57dc24f7dd5f833d663038ba20397ea20db77c6bd2e4de8c512cfcd342775e99384c231bcf361a592e5f71953e
7
+ data.tar.gz: d7cb4fd454c269e87f89a53a7307d7b93bc9cf1c1d5314df94ec474424ae62c021c6f3a00becf4559c0c01adc1748ea53995355ffddb737d1686451a98d7b237
@@ -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
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 1.17.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ThanhKhoaIT@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'http', '>= 4.1.1'
6
+
7
+ # Specify your gem's dependencies in ninja_van.gemspec
8
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ninja_van (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.6.0)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ diff-lcs (1.3)
12
+ domain_name (0.5.20190701)
13
+ unf (>= 0.0.5, < 1.0.0)
14
+ http (4.1.1)
15
+ addressable (~> 2.3)
16
+ http-cookie (~> 1.0)
17
+ http-form_data (~> 2.0)
18
+ http_parser.rb (~> 0.6.0)
19
+ http-cookie (1.0.3)
20
+ domain_name (~> 0.5)
21
+ http-form_data (2.1.1)
22
+ http_parser.rb (0.6.0)
23
+ public_suffix (3.1.1)
24
+ rake (10.5.0)
25
+ rspec (3.8.0)
26
+ rspec-core (~> 3.8.0)
27
+ rspec-expectations (~> 3.8.0)
28
+ rspec-mocks (~> 3.8.0)
29
+ rspec-core (3.8.2)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-expectations (3.8.4)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-mocks (3.8.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-support (3.8.2)
38
+ unf (0.1.4)
39
+ unf_ext
40
+ unf_ext (0.0.7.6)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.17)
47
+ http (>= 4.1.1)
48
+ ninja_van!
49
+ rake (~> 10.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.17.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 KhoaRB
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.
@@ -0,0 +1,87 @@
1
+ # NinjaVan API Caller
2
+ **GHTK Documentation:** https://ninjaorderapibeta.docs.apiary.io
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'ninja_van'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install ninja_van
19
+
20
+ ## Setup for Rails
21
+
22
+ Add `config/initializers/ninjavan.rb` file
23
+ ```ruby
24
+ NinjaVan.setup do |config|
25
+ # Add your config diff by the environment
26
+ config.domain = Rails.application.secrets.ninjavan_endpoint
27
+ config.client_id = Rails.application.secrets.ninjavan_client_id
28
+ config.client_secret = Rails.application.secrets.ninjavan_client_secret
29
+ config.grant_type = :client_credentials
30
+
31
+ # Set class for getting token from the cache to optimize request getting a new token
32
+ config.get_token_from_cache_klass = Ninjavan::AccessTokenFromCacheService
33
+
34
+ config.get_access_token_endpoint = '/2.0/oauth/access_token'
35
+ config.create_endpoint = '/4.1/orders'
36
+ config.get_detail_endpoint = '/3.0/orders'
37
+ config.get_status_endpoint = '/2.0/track'
38
+ config.cancel_endpoint = '/2.2/orders/'
39
+ end
40
+ ```
41
+
42
+ **Example** for `Ninjavan::AccessTokenFromCacheService` class
43
+ ```ruby
44
+ module Ninjavan
45
+ class AccessTokenFromCacheService
46
+ def call
47
+ token = Rails.cache.fetch('ninjavan_token')
48
+ return token if token
49
+ response = NinjaVan::AccessToken.get
50
+ Rails.cache.fetch('ninjavan_token', expires_in: response['expires_in'] - 5.minute) { response["access_token"] }
51
+ end
52
+ end
53
+ end
54
+ ```
55
+
56
+ ## Usage
57
+ #### How to create Order
58
+ With **ActiveModel::Serializer**
59
+ ```ruby
60
+ serializer = NinjavanSerializer.new(Shipment.last)
61
+ NinjaVan::Order.create(serializer)
62
+ ```
63
+ Or by **Hash**
64
+
65
+ ```ruby
66
+ request_data = {...}
67
+ NinjaVan::Order.create(request_data)
68
+ ```
69
+ - Request data: [view JSON file](https://bit.ly/33RJicn)
70
+ - Success response: [view JSON file](https://bit.ly/2Ziswoh)
71
+
72
+ - Ninjavan documentation: [detail](https://ninjaorderapibeta.docs.apiary.io/#reference/0/create-order-v41-latest/post)
73
+
74
+ #### How to get Order detail
75
+ ```ruby
76
+ NinjaVan::Order.get_detail(tracking_id: 'NVSG00000000000000')
77
+ ```
78
+
79
+ #### How to get Order status
80
+ ```ruby
81
+ NinjaVan::Order.get_status(trackingIds: ['NVSG00000000000000'])
82
+ ```
83
+
84
+ #### How to cancel Order
85
+ ```ruby
86
+ NinjaVan::Order.cancel('NVSG00000000000000')
87
+ ```
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ninja_van"
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__)
@@ -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,36 @@
1
+ require "http"
2
+ require "ninja_van/support/hash"
3
+ require "ninja_van/version"
4
+ require "ninja_van/error"
5
+ require "ninja_van/config"
6
+ require "ninja_van/types"
7
+ require "ninja_van/flexible_params"
8
+ require "ninja_van/request"
9
+ require "ninja_van/access_token"
10
+ require "ninja_van/validations/order_validation"
11
+ require "ninja_van/order"
12
+
13
+ module NinjaVan
14
+
15
+ def self.setup
16
+ @config ||= NinjaVan::Config.new
17
+ yield @config if block_given?
18
+ @config
19
+ end
20
+
21
+ def self.is_blank?(object)
22
+ case object
23
+ when NilClass, FalseClass
24
+ return true
25
+ when TrueClass, Numeric, Fixnum
26
+ return false
27
+ when Array, Hash
28
+ return object.empty?
29
+ when String
30
+ return object.empty? || !object.match(/\A[[:space:]]*\z/).nil?
31
+ else
32
+ return object.respond_to?(:empty?) ? !!object.empty? : !object
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,13 @@
1
+ module NinjaVan
2
+ class AccessToken
3
+
4
+ def self.get
5
+ NinjaVan::Request.post_without_token(NinjaVan.setup.require!(:get_access_token_endpoint), {
6
+ grant_type: NinjaVan.setup.require!(:grant_type),
7
+ client_id: NinjaVan.setup.require!(:client_id),
8
+ client_secret: NinjaVan.setup.require!(:client_secret),
9
+ })
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ module NinjaVan
2
+ class Config
3
+
4
+ attr_accessor :domain
5
+ attr_accessor :client_id
6
+ attr_accessor :client_secret
7
+ attr_accessor :grant_type
8
+
9
+ attr_accessor :get_token_from_cache_klass
10
+
11
+ attr_accessor :get_access_token_endpoint
12
+ attr_accessor :create_endpoint
13
+ attr_accessor :get_detail_endpoint
14
+ attr_accessor :get_status_endpoint
15
+ attr_accessor :cancel_endpoint
16
+
17
+ attr_accessor :create_order_required_params
18
+
19
+ def get_token_from_cache
20
+ if self.get_token_from_cache_klass.is_a?(Class)
21
+ self.get_token_from_cache_klass.new.call
22
+ else
23
+ raise NinjaVan::ConfigError.new("get_token_from_cache_klass is not class!")
24
+ end
25
+ end
26
+
27
+ def require!(key)
28
+ setup_value = self.send(key)
29
+ raise NinjaVan::ConfigError.new("#{key} is nil!") if setup_value.nil?
30
+ return setup_value
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ module NinjaVan
2
+ class Error < StandardError; end
3
+
4
+ class RequestError < Error
5
+ attr_reader :response
6
+
7
+ delegate :message,
8
+ :request_id,
9
+ :code,
10
+ :title,
11
+ to: :error
12
+
13
+ def initialize(response)
14
+ super
15
+ @response = response
16
+ end
17
+
18
+ def error
19
+ @error ||= OpenStruct.new(response['error'])
20
+ end
21
+ end
22
+
23
+ class ResponseError < Error
24
+ attr_reader :error_data
25
+ def initialize(error_data)
26
+ super
27
+ @error_data = error_data
28
+ end
29
+ end
30
+
31
+ class ConfigError < Error; end
32
+ class ForbiddenError < Error; end
33
+ class ServerError < Error; end
34
+ class BadParamsError < Error; end
35
+
36
+ class CreateOrderError < ResponseError; end
37
+ class NotFoundError < ResponseError; end
38
+ end
@@ -0,0 +1,18 @@
1
+ module NinjaVan
2
+ class FlexibleParams
3
+
4
+ attr_reader :hash
5
+
6
+ def initialize(object)
7
+ if object.is_a?(Hash)
8
+ data = object
9
+ elsif object.respond_to?(:as_json)
10
+ data = object.as_json
11
+ else
12
+ data = object.attributes
13
+ end
14
+ @hash = data.to_deep_symbolize_keys
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ module NinjaVan
2
+ class Order
3
+
4
+ def self.create(serializer)
5
+ create_data = NinjaVan::FlexibleParams.new(serializer).hash
6
+ begin
7
+ NinjaVan::Validations::OrderValidation.new(create_data).validate!
8
+ NinjaVan::Request.post(NinjaVan.setup.require!(:create_endpoint), create_data)
9
+ rescue NinjaVan::RequestError => exception
10
+ raise NinjaVan::CreateOrderError.new(create_data.merge(exception.response.to_deep_symbolize_keys))
11
+ rescue => exception
12
+ raise NinjaVan::CreateOrderError.new(create_data.merge({ error: exception.to_s }))
13
+ end
14
+ end
15
+
16
+ # Params: tracking_id: tracking_code
17
+ def self.get_detail(params)
18
+ NinjaVan::Request.get(NinjaVan.setup.require!(:get_detail_endpoint), params)
19
+ end
20
+
21
+ # Params: trackingIds: [tracking_code1, tracking_code2]
22
+ def self.get_status(params)
23
+ NinjaVan::Request.post(NinjaVan.setup.require!(:get_status_endpoint), params)
24
+ end
25
+
26
+ # Params: NVSG00000000000000
27
+ def self.cancel(tracking_code)
28
+ NinjaVan::Request.delete(NinjaVan.setup.require!(:cancel_endpoint) << tracking_code)
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,48 @@
1
+ module NinjaVan
2
+ class Request
3
+
4
+ def self.post(endpoint, params={})
5
+ full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}"
6
+ response = Http.headers(content_type: 'application/json', accept: 'application/json')
7
+ .auth("Bearer #{NinjaVan.setup.get_token_from_cache}")
8
+ .post(full_endpoint, json: params)
9
+ raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403
10
+ raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500
11
+ raise NinjaVan::RequestError.new(response.parse) if response.parse.is_a?(Hash) && !response.parse['error'].nil?
12
+ response.parse
13
+ end
14
+
15
+ def self.post_without_token(endpoint, params={})
16
+ full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}"
17
+ response = Http.headers(content_type: 'application/json', accept: 'application/json')
18
+ .post(full_endpoint, json: params)
19
+ raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403
20
+ raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500
21
+ raise NinjaVan::RequestError.new(response.parse) unless response.parse['error'].nil?
22
+ response.parse
23
+ end
24
+
25
+ def self.get(endpoint, params={})
26
+ full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}"
27
+ response = Http.headers(content_type: 'application/json', accept: 'application/json')
28
+ .auth("Bearer #{NinjaVan.setup.get_token_from_cache}")
29
+ .get(full_endpoint, params: params)
30
+ raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403
31
+ raise NinjaVan::NotFoundError.new(response.parse) if response.code == 404
32
+ raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500
33
+ response.parse
34
+ end
35
+
36
+ def self.delete(endpoint, params={})
37
+ full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}"
38
+ response = Http.headers(content_type: 'application/json', accept: 'application/json')
39
+ .auth("Bearer #{NinjaVan.setup.get_token_from_cache}")
40
+ .delete(full_endpoint, params: params)
41
+ raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403
42
+ raise NinjaVan::NotFoundError.new(response.parse) if response.code == 404
43
+ raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500
44
+ response.parse
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ class Hash
2
+
3
+ def to_deep_symbolize_keys
4
+ to_deep_transform_keys { |key| key.to_sym rescue key }
5
+ end
6
+
7
+ def to_deep_transform_keys(&block)
8
+ _to_deep_transform_keys_in_object(self, &block)
9
+ end
10
+
11
+ private
12
+
13
+ def _to_deep_transform_keys_in_object(object, &block)
14
+ case object
15
+ when Hash
16
+ object.each_with_object({}) do |(key, value), result|
17
+ result[yield(key)] = _to_deep_transform_keys_in_object(value, &block)
18
+ end
19
+ when Array
20
+ object.map { |e| _to_deep_transform_keys_in_object(e, &block) }
21
+ else
22
+ object
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,71 @@
1
+ module NinjaVan
2
+
3
+ class ServiceTypes
4
+ PARCEL = 'Parcel'
5
+ RETURN = 'Return'
6
+ MARKETPLACE = 'Marketplace'
7
+ BULKY = 'Bulky'
8
+ INTERNATIONAL = 'International'
9
+ ALL = [PARCEL, RETURN, MARKETPLACE, BULKY, INTERNATIONAL]
10
+ end
11
+
12
+ class ServiceLevels
13
+ STANDARD = 'Standard'
14
+ EXPRESS = 'Express'
15
+ SAMEDAY = 'Sameday'
16
+ NEXTDAY = 'Nextday'
17
+ ALL = [STANDARD, EXPRESS, SAMEDAY, NEXTDAY]
18
+ end
19
+
20
+ class Dimensions
21
+ S = 'S'
22
+ M = 'M'
23
+ L = 'L'
24
+ XL = 'XL'
25
+ XXL = 'XXL'
26
+ ALL = [S, M, L, XL, XXL]
27
+ end
28
+
29
+ class PickupServiceTypes
30
+ SCHEDULED = 'Scheduled'
31
+ ON_DEMAND = 'On-Demand'
32
+ ALL = [SCHEDULED, ON_DEMAND]
33
+ end
34
+
35
+ class PickupServiceLevels
36
+ STANDARD = 'Standard'
37
+ PREMIUM = 'Premium'
38
+ ALL = [STANDARD, PREMIUM]
39
+ end
40
+
41
+ class Timezones
42
+ SINGAPORE = 'Asia/Singapore'
43
+ KUALA_LUMPUR = 'Asia/Kuala_Lumpur'
44
+ JAKARTA = 'Asia/Jakarta'
45
+ JAYAPURA = 'Asia/Jayapura'
46
+ MAKASSAR = 'Asia/Makassar'
47
+ BANGKOK = 'Asia/Bangkok'
48
+ MANILA = 'Asia/Manila'
49
+ HO_CHI_MINH = 'Asia/Ho_Chi_Minh'
50
+ YANGON = 'Asia/Yangon'
51
+ ALL = [SINGAPORE, KUALA_LUMPUR, JAKARTA, JAYAPURA, MAKASSAR, BANGKOK, MANILA, HO_CHI_MINH, YANGON]
52
+ end
53
+
54
+ class PickupApproxVolumes
55
+ FULL_VAN_LOAD = 'Full-Van Load'
56
+ HALF_VAN_LOAD = 'Half-Van Load'
57
+ LARGER_THAN_VAN_LOAD = 'Larger than Van Load'
58
+ LESS_THAN_10_PARCELS = 'Less than 10 Parcels'
59
+ LESS_THAN_3_PARCELS = 'Less than 3 Parcels'
60
+ TROLLEY_REQUIRED = 'Trolley Required'
61
+ ALL = [
62
+ FULL_VAN_LOAD,
63
+ HALF_VAN_LOAD,
64
+ LARGER_THAN_VAN_LOAD,
65
+ LESS_THAN_10_PARCELS,
66
+ LESS_THAN_3_PARCELS,
67
+ TROLLEY_REQUIRED,
68
+ ]
69
+ end
70
+
71
+ end
@@ -0,0 +1,34 @@
1
+ module NinjaVan::Validations
2
+ class OrderValidation
3
+
4
+ def initialize(hash)
5
+ @hash = hash.to_deep_symbolize_keys
6
+ end
7
+
8
+ def validate!
9
+ blank_params = []
10
+ required_params.each do |field|
11
+ blank_params << field if NinjaVan.is_blank?(hash[field.to_sym])
12
+ end
13
+ raise NinjaVan::BadParamsError.new("Params: [#{blank_params.join(', ')}] is blank!") unless blank_params.empty?
14
+ return true
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :hash
20
+
21
+ DEFAULT_REQUIRED_PARAMS = [
22
+ :service_type,
23
+ :service_level,
24
+ :from,
25
+ :to,
26
+ :parcel_job
27
+ ]
28
+
29
+ def required_params
30
+ NinjaVan.setup.create_order_required_params || DEFAULT_REQUIRED_PARAMS
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module NinjaVan
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ninja_van/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ninja_van"
8
+ spec.version = NinjaVan::VERSION
9
+ spec.authors = ["KhoaRB"]
10
+ spec.email = ["ThanhKhoaIT@gmail.com"]
11
+
12
+ spec.summary = %q{NinjaVan API Caller for Ruby}
13
+ spec.description = %q{NinjaVan 3PL shipping service API Caller for Ruby}
14
+ spec.homepage = "https://github.com/ThanhKhoaIT/ninja_van"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["documentation_uri"] = "https://github.com/ThanhKhoaIT/ninja_van/#setup-for-rails"
22
+ spec.metadata["bug_tracker_uri"] = "https://github.com/ThanhKhoaIT/ninja_van/issues"
23
+ spec.metadata["wiki_uri"] = "https://github.com/ThanhKhoaIT/ninja_van/wiki"
24
+ spec.metadata["changelog_uri"] = "https://github.com/ThanhKhoaIT/ninja_van/releases"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "http", "~> 4.1.1"
43
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ninja_van
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - KhoaRB
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-24 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: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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
+ - !ruby/object:Gem::Dependency
56
+ name: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.1.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.1.1
69
+ description: NinjaVan 3PL shipping service API Caller for Ruby
70
+ email:
71
+ - ThanhKhoaIT@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/ninja_van.rb
88
+ - lib/ninja_van/access_token.rb
89
+ - lib/ninja_van/config.rb
90
+ - lib/ninja_van/error.rb
91
+ - lib/ninja_van/flexible_params.rb
92
+ - lib/ninja_van/order.rb
93
+ - lib/ninja_van/request.rb
94
+ - lib/ninja_van/support/hash.rb
95
+ - lib/ninja_van/types.rb
96
+ - lib/ninja_van/validations/order_validation.rb
97
+ - lib/ninja_van/version.rb
98
+ - ninja_van.gemspec
99
+ homepage: https://github.com/ThanhKhoaIT/ninja_van
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ homepage_uri: https://github.com/ThanhKhoaIT/ninja_van
104
+ documentation_uri: https://github.com/ThanhKhoaIT/ninja_van/#setup-for-rails
105
+ bug_tracker_uri: https://github.com/ThanhKhoaIT/ninja_van/issues
106
+ wiki_uri: https://github.com/ThanhKhoaIT/ninja_van/wiki
107
+ changelog_uri: https://github.com/ThanhKhoaIT/ninja_van/releases
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.10
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: NinjaVan API Caller for Ruby
128
+ test_files: []