ghtk 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ghtk.gemspec +33 -0
- data/lib/ghtk.rb +36 -0
- data/lib/ghtk/config.rb +9 -0
- data/lib/ghtk/error.rb +8 -0
- data/lib/ghtk/flexible_params.rb +18 -0
- data/lib/ghtk/order.rb +23 -0
- data/lib/ghtk/request.rb +28 -0
- data/lib/ghtk/shipping_fee.rb +11 -0
- data/lib/ghtk/support/hash.rb +26 -0
- data/lib/ghtk/validations/order_validation.rb +56 -0
- data/lib/ghtk/validations/shipping_fee_validation.rb +27 -0
- data/lib/ghtk/version.rb +3 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4df0ff353b7f46feeda5484a8b2d8360a4479f78f23ba1fe99e24fc1573656b8
|
4
|
+
data.tar.gz: 0aac5a1d1bab0a652620fa9aeb01cc35c47713f7c22fc0fc9eb89a09b58d3fe5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29f10fdda2c80bd30a7e614ee55cc56f3d89ea1e5d659e5d4173e8cc4cb6c228f38768320002b9dab2e0da824120e8756c44df59dec691ed5acec6c12df31f06
|
7
|
+
data.tar.gz: 963961413fb2a39e10ea794d29717fb839e54cd301182a2f748d36384e8a7ae38349f23f4646aea93a3c6430d62c7e8bdf67055937bf93814daad8c42dfc38d7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ghtk (1.0.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 (~> 2.0)
|
47
|
+
ghtk!
|
48
|
+
http (>= 4.1.1)
|
49
|
+
rake (~> 10.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# GHTK API Caller
|
2
|
+
**GHTK Documentation:** https://docs.giaohangtietkiem.vn
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'ghtk'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install ghtk
|
19
|
+
|
20
|
+
## Setup for Rails
|
21
|
+
Add `config/initializers/ghtk.rb` file
|
22
|
+
```ruby
|
23
|
+
Ghtk.setup do |config|
|
24
|
+
config.domain = '' # Add domain for sandbox or production
|
25
|
+
config.access_token = '' # Add your token of sandbox or production
|
26
|
+
config.version = 1.5
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
#### How to create Order
|
32
|
+
```ruby
|
33
|
+
serializer = ShippingServices::GhtkSerializer.new(Shipment.last)
|
34
|
+
Ghtk::Order.create(serializer)
|
35
|
+
```
|
36
|
+
- Response data: [detail](https://docs.giaohangtietkiem.vn/?http#ng-n-h-ng)
|
37
|
+
|
38
|
+
#### How to get Order detail for check status,.....
|
39
|
+
```ruby
|
40
|
+
Ghtk::Order.get_detail(tracking_code)
|
41
|
+
```
|
42
|
+
- Response data: [detail](https://docs.giaohangtietkiem.vn/?http#tr-ng-th-i-n-h-ng)
|
43
|
+
|
44
|
+
#### How to cancel Order
|
45
|
+
```ruby
|
46
|
+
Ghtk::Order.cancel(tracking_code)
|
47
|
+
```
|
48
|
+
- Response data: [detail](https://docs.giaohangtietkiem.vn/?http#h-y-n-h-ng)
|
49
|
+
|
50
|
+
#### How to check shipping fee
|
51
|
+
```ruby
|
52
|
+
serializer = ShippingServices::GhtkFeeSerializer.new(Shipment.last)
|
53
|
+
Ghtk::ShippingFee.check(serializer)
|
54
|
+
```
|
55
|
+
- Response data: [detail](https://docs.giaohangtietkiem.vn/?http#t-nh-ph-v-n-chuy-n)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ghtk"
|
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
data/ghtk.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ghtk/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ghtk"
|
7
|
+
spec.version = Ghtk::VERSION
|
8
|
+
spec.authors = ["KhoaRB"]
|
9
|
+
spec.email = ["ThanhKhoaIT@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{GHTK API Caller}
|
12
|
+
spec.description = %q{Ruby gem for call GHTK API}
|
13
|
+
spec.homepage = "https://github.com/ThanhKhoaIT/ghtk"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
18
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "http", "~> 4.1.1"
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
data/lib/ghtk.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "http"
|
2
|
+
require "ghtk/support/hash"
|
3
|
+
require "ghtk/version"
|
4
|
+
require "ghtk/error"
|
5
|
+
require "ghtk/config"
|
6
|
+
require "ghtk/flexible_params"
|
7
|
+
require "ghtk/request"
|
8
|
+
require "ghtk/validations/order_validation"
|
9
|
+
require "ghtk/validations/shipping_fee_validation"
|
10
|
+
require "ghtk/order"
|
11
|
+
require "ghtk/shipping_fee"
|
12
|
+
|
13
|
+
module Ghtk
|
14
|
+
|
15
|
+
def self.setup
|
16
|
+
@config ||= Ghtk::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
|
data/lib/ghtk/config.rb
ADDED
data/lib/ghtk/error.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Ghtk
|
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
|
data/lib/ghtk/order.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ghtk
|
2
|
+
class Order
|
3
|
+
|
4
|
+
def self.create(serializer)
|
5
|
+
create_data = NinjaVan::FlexibleParams.new(serializer).hash
|
6
|
+
Ghtk::Validations::OrderValidation.new(create_data).validate!
|
7
|
+
Ghtk::Request.post('/services/shipment/order', create_data)
|
8
|
+
rescue Ghtk::ForbiddenError
|
9
|
+
raise Ghtk::CreateOrderError.new(create_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_detail(tracking_code)
|
13
|
+
raise Ghtk::BadParamsError.new('Tracking code is blank!') if Ghtk.is_blank?(tracking_code)
|
14
|
+
Ghtk::Request.get("/services/shipment/v2/#{tracking_code}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.cancel(tracking_code)
|
18
|
+
raise Ghtk::BadParamsError.new('Tracking code is blank!') if Ghtk.is_blank?(tracking_code)
|
19
|
+
Ghtk::Request.post("/services/shipment/cancel/#{tracking_code}")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/ghtk/request.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ghtk
|
2
|
+
class Request
|
3
|
+
|
4
|
+
def self.post(endpoint, params={})
|
5
|
+
full_endpoint = "#{Ghtk.setup.domain}#{endpoint}?ver=#{Ghtk.setup.version}"
|
6
|
+
response = Http.headers(
|
7
|
+
content_type: 'application/json',
|
8
|
+
token: Ghtk.setup.access_token,
|
9
|
+
).post(full_endpoint, json: params)
|
10
|
+
raise Ghtk::ForbiddenError.new(full_endpoint) if response.code == 403
|
11
|
+
raise Ghtk::ServerError.new(full_endpoint) if response.code == 500
|
12
|
+
raise Ghtk::RequestError.new(response.parse) unless response.parse['success']
|
13
|
+
response.parse
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get(endpoint, params={})
|
17
|
+
full_endpoint = "#{Ghtk.setup.domain}#{endpoint}?ver=#{Ghtk.setup.version}"
|
18
|
+
response = Http.headers(
|
19
|
+
content_type: 'aplication/json',
|
20
|
+
token: Ghtk.setup.access_token,
|
21
|
+
).get(full_endpoint, params: params)
|
22
|
+
raise Ghtk::ForbiddenError.new(full_endpoint) if response.code == 403
|
23
|
+
raise Ghtk::ServerError.new(full_endpoint) if response.code == 500
|
24
|
+
response.parse
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
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,56 @@
|
|
1
|
+
module Ghtk::Validations
|
2
|
+
class OrderValidation
|
3
|
+
|
4
|
+
def initialize(hash)
|
5
|
+
@hash = hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def validate!
|
9
|
+
blank_params = []
|
10
|
+
REQUIRED_PARAMS.each do |key, sub_keys|
|
11
|
+
sub_keys.each do |sub_key|
|
12
|
+
blank_params << "#{key}.#{sub_key}" if Ghtk.is_blank?(hash.dig(key, sub_key))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
unless hash.dig(:order, :use_return_address).to_i.zero?
|
16
|
+
REQUIRED_RETURN_PARAMS.each do |key, sub_keys|
|
17
|
+
sub_keys.each do |sub_key|
|
18
|
+
blank_params << "#{key}.#{sub_key}" if Ghtk.is_blank?(hash.dig(key, sub_key))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
raise Ghtk::BadParamsError.new("Params: #{blank_params.join(', ')} is blank!") unless blank_params.empty?
|
23
|
+
return true
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :hash
|
29
|
+
|
30
|
+
REQUIRED_PARAMS = { order: [
|
31
|
+
:id,
|
32
|
+
:pick_name,
|
33
|
+
:pick_money,
|
34
|
+
:pick_address,
|
35
|
+
:pick_province,
|
36
|
+
:pick_district,
|
37
|
+
:pick_tel,
|
38
|
+
:name,
|
39
|
+
:address,
|
40
|
+
:province,
|
41
|
+
:district,
|
42
|
+
:tel,
|
43
|
+
:email,
|
44
|
+
] }
|
45
|
+
|
46
|
+
REQUIRED_RETURN_PARAMS = { order: [
|
47
|
+
:return_name,
|
48
|
+
:return_address,
|
49
|
+
:return_province,
|
50
|
+
:return_district,
|
51
|
+
:return_tel,
|
52
|
+
:return_email,
|
53
|
+
] }
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ghtk::Validations
|
2
|
+
class ShippingFeeValidation
|
3
|
+
|
4
|
+
def initialize(hash)
|
5
|
+
@hash = hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def validate!
|
9
|
+
blank_params = REQUIRED_PARAMS.select { |key| Ghtk.is_blank?(hash[key]) }
|
10
|
+
raise Ghtk::BadParamsError.new("Params: #{blank_params.join(', ')} is blank!") unless blank_params.empty?
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :hash
|
17
|
+
|
18
|
+
REQUIRED_PARAMS = [
|
19
|
+
:pick_province,
|
20
|
+
:pick_district,
|
21
|
+
:province,
|
22
|
+
:district,
|
23
|
+
:weight
|
24
|
+
]
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/ghtk/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghtk
|
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: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Ruby gem for call GHTK API
|
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
|
+
- ghtk.gemspec
|
88
|
+
- lib/ghtk.rb
|
89
|
+
- lib/ghtk/config.rb
|
90
|
+
- lib/ghtk/error.rb
|
91
|
+
- lib/ghtk/flexible_params.rb
|
92
|
+
- lib/ghtk/order.rb
|
93
|
+
- lib/ghtk/request.rb
|
94
|
+
- lib/ghtk/shipping_fee.rb
|
95
|
+
- lib/ghtk/support/hash.rb
|
96
|
+
- lib/ghtk/validations/order_validation.rb
|
97
|
+
- lib/ghtk/validations/shipping_fee_validation.rb
|
98
|
+
- lib/ghtk/version.rb
|
99
|
+
homepage: https://github.com/ThanhKhoaIT/ghtk
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/ThanhKhoaIT/ghtk
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.7.10
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: GHTK API Caller
|
124
|
+
test_files: []
|