v_shipping 0.0.1.pre.rc
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 +7 -0
- data/lib/v_shipping/ahamove.rb +127 -0
- data/lib/v_shipping/configuration.rb +78 -0
- data/lib/v_shipping/setup.rb +26 -0
- data/lib/v_shipping.rb +29 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d1e3d45460eb701a740e95e59a3a5b2b0d616fea55e91fd75ebeb4ee02c0addf
|
|
4
|
+
data.tar.gz: 80e72501f62bd3897311775ae5bcbad077eec92738aa88994231c5de325ab604
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5d78c791656c758706d780ad5d575e09e8b3362c4617a7c183512df6a56ac8c59533bb84001811e3ee3f32f8e1a3ae0b165aee925da1ad80c1220634b127c541
|
|
7
|
+
data.tar.gz: 00dbc70e626c496c80b76e50e2828951f6b93822f369967559ecb20c98f94713bdf1d6a8b618fe5e674348e5bed89ea99c2338c9ca993f5d1c0cb010e27a332f
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module VShipping
|
|
4
|
+
class Ahamove
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
include HTTParty
|
|
7
|
+
|
|
8
|
+
def initialize(api_key, config_url)
|
|
9
|
+
@api_key = api_key
|
|
10
|
+
@config = load_yaml(config_url)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def retrieved_token(params)
|
|
14
|
+
get(
|
|
15
|
+
'register_endpoint',
|
|
16
|
+
params.merge({
|
|
17
|
+
api_key: api_key
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create_order(params)
|
|
23
|
+
get('create_order_endpoint', params)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def retrieved_orders(params)
|
|
27
|
+
get('orders_endpoint', params)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def retrieved_order(params)
|
|
31
|
+
get('order_endpoint', params)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def retrieved_fee(params)
|
|
35
|
+
get('order_fee_endpoint', params)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def retrieved_fees(body)
|
|
39
|
+
post('orders_fee_endpoint', body)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def cancel_order(params)
|
|
43
|
+
get('cancel_order_endpoint', params)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def retrieved_city(params)
|
|
47
|
+
get('city_endpoint', params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def retrieved_services(params)
|
|
51
|
+
get('services_endpoint', params)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def retrieved_tracking_link(params)
|
|
55
|
+
get('order_tracking_endpoint', params)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def notify_supplier(params)
|
|
59
|
+
get('notify_supplier_endpoint', params)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def order_statuses
|
|
63
|
+
[
|
|
64
|
+
mapping_status('IDLE', 'confirmed'),
|
|
65
|
+
mapping_status('ASSIGNING', 'assigning'),
|
|
66
|
+
mapping_status('ACCEPTED', 'accepted'),
|
|
67
|
+
mapping_status('IN PROCESS', 'in_progress'),
|
|
68
|
+
mapping_status('COMPLETED', 'completed'),
|
|
69
|
+
mapping_status('CANCELLED', 'cancelled')
|
|
70
|
+
]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
attr_reader :config, :api_key
|
|
76
|
+
|
|
77
|
+
def mapping_url(name)
|
|
78
|
+
base_url + config.try(:fetch, 'register_endpoint').to_s
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def base_url
|
|
82
|
+
config.try(:fetch, 'base_api_url').to_s
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def load_yaml(url)
|
|
86
|
+
YAML::load(
|
|
87
|
+
ERB.new(
|
|
88
|
+
File.read(config_url)
|
|
89
|
+
).result
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def formmated(response)
|
|
94
|
+
[response.try(:status), response.try(:body)]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def get(endpoint, params)
|
|
98
|
+
response = self.class.get(
|
|
99
|
+
mapping_url(endpoint),
|
|
100
|
+
{ query: params }
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
formmated(response)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def post(endpoint, body)
|
|
107
|
+
response = self.class.post(
|
|
108
|
+
mapping_url(endpoint),
|
|
109
|
+
{
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json'
|
|
112
|
+
}
|
|
113
|
+
body: body
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
formmated(response)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def mapping_status(name, value)
|
|
121
|
+
{
|
|
122
|
+
name: name,
|
|
123
|
+
value: value
|
|
124
|
+
}
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module VShipping
|
|
2
|
+
module Configuration
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
add_config :ahamove_api_key
|
|
7
|
+
add_config :ahamove_config_path
|
|
8
|
+
|
|
9
|
+
# set default values
|
|
10
|
+
reset_config
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ClassMethods
|
|
14
|
+
def add_config(name)
|
|
15
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
16
|
+
@#{name} = nil
|
|
17
|
+
def self.#{name}(value=nil)
|
|
18
|
+
@#{name} = value if value
|
|
19
|
+
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
|
|
20
|
+
name = superclass.#{name}
|
|
21
|
+
return nil if name.nil? && !instance_variable_defined?(:@#{name})
|
|
22
|
+
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
|
23
|
+
end
|
|
24
|
+
def self.#{name}=(value)
|
|
25
|
+
@#{name} = value
|
|
26
|
+
end
|
|
27
|
+
def #{name}=(value)
|
|
28
|
+
@#{name} = value
|
|
29
|
+
end
|
|
30
|
+
def #{name}
|
|
31
|
+
value = @#{name} if instance_variable_defined?(:@#{name})
|
|
32
|
+
value = self.class.#{name} unless instance_variable_defined?(:@#{name})
|
|
33
|
+
if value.instance_of?(Proc)
|
|
34
|
+
value.arity >= 1 ? value.call(self) : value.call
|
|
35
|
+
else
|
|
36
|
+
value
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
RUBY
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def add_deprecated_config(name)
|
|
43
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
44
|
+
def self.#{name}(value=nil)
|
|
45
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
|
46
|
+
end
|
|
47
|
+
def self.#{name}=(value)
|
|
48
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
|
49
|
+
end
|
|
50
|
+
def #{name}=(value)
|
|
51
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
|
52
|
+
end
|
|
53
|
+
def #{name}
|
|
54
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
|
55
|
+
end
|
|
56
|
+
RUBY
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def configure
|
|
60
|
+
yield self
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
##
|
|
64
|
+
# sets configuration back to default
|
|
65
|
+
#
|
|
66
|
+
def reset_config
|
|
67
|
+
configure do |config|
|
|
68
|
+
config.ahamove_api_key = nil
|
|
69
|
+
config.ahamove_config_path = nil
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.included(base)
|
|
75
|
+
base.extend(ClassMethods)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "v_shipping/configuration"
|
|
2
|
+
|
|
3
|
+
module VShipping
|
|
4
|
+
class Setup
|
|
5
|
+
include VShipping::Configuration
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def ahamove
|
|
9
|
+
puts "Ahamove status: #{status}"
|
|
10
|
+
|
|
11
|
+
return unless ahamove_api_key
|
|
12
|
+
|
|
13
|
+
VShipping::Ahamove.new(ahamove_api_key, ahamove_config_path)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def status
|
|
19
|
+
ahamove_api_key.nil? ? 'is missing api key' : 'available'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
require 'v_shipping/ahamove'
|
data/lib/v_shipping.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
require 'active_support/core_ext/class/attribute'
|
|
3
|
+
|
|
4
|
+
module VShipping
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
module ClassMethods
|
|
8
|
+
@@ahamove = nil
|
|
9
|
+
|
|
10
|
+
def ahamove
|
|
11
|
+
return @@ahamove unless @@ahamove.nil?
|
|
12
|
+
|
|
13
|
+
@@ahamove = VShipping::Setup.ahamove
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
def configure(&block)
|
|
19
|
+
VShipping::Setup.configure(&block)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.included(base)
|
|
24
|
+
base.extend(ClassMethods)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
require 'v_shipping/ahamove'
|
|
29
|
+
require 'v_shipping/setup'
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: v_shipping
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.pre.rc
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- John Nguyễn
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-12-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: VN Shipping Gem
|
|
14
|
+
email: tainv.it93@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/v_shipping.rb
|
|
20
|
+
- lib/v_shipping/ahamove.rb
|
|
21
|
+
- lib/v_shipping/configuration.rb
|
|
22
|
+
- lib/v_shipping/setup.rb
|
|
23
|
+
homepage: https://rubygems.org/gems/v_shipping
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata: {}
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options:
|
|
29
|
+
- "--main"
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 1.3.1
|
|
42
|
+
requirements: []
|
|
43
|
+
rubygems_version: 3.0.8
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: VN Shipping!
|
|
47
|
+
test_files: []
|