vncpost_api 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f818eb7aa98bf14e740e787f2b4a3fa01a02d3fb9d21db37a8335f0b41403fa
4
- data.tar.gz: 97817de460715644959343f4311a5d7878bde714cad6c172343bec96122124d4
3
+ metadata.gz: 9bbe9fcf75e261d11678cbdc15b9b81437585aa9523759e81619b71f2df3c22a
4
+ data.tar.gz: 28589dfa40030fe7c0b2e66d1d207c1547636dfae57f0592dc451088c12a7ab3
5
5
  SHA512:
6
- metadata.gz: 79b9f520a1154bcc81119a1aa8a7bf10d5fcab9985a2704c9507365316e6ba7b73d9e765c198f6d29a5370a6ef206335761cc2e556ecc0a793d3d8514a0d5a29
7
- data.tar.gz: 4cfa77b46bbbaf778f7e133d86aa26ab6548022450809dd7c20b2c34a97687ff8898e95c5645ab1aeaa40f57386af991768c731dd1f9d84a1fb4fbe7025a0c31
6
+ metadata.gz: 5760460c1448296ffd68417b87d8d2bd451654f0c54597ef4d98cb73f7c68a78ef7cea5c967be3419e4fb86ea024a044a46ced38f8f792d2286e8685c7285423
7
+ data.tar.gz: 5badd01e5a8dfff3a6b6fef626cbff5f15a4485076e2fac8455b2f5d16ec3687d8b4e2b763cbb969063cf462abc10a2c7dd34f1090a97eb1406dd67a7a15f6d7
@@ -13,7 +13,7 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- ruby: ["2.5", "2.6", "2.7"]
16
+ ruby: ["2.7", "3.0", "3.1"]
17
17
  fail-fast: true
18
18
  steps:
19
19
  - name: Checkout to repo
data/.gitignore CHANGED
@@ -10,4 +10,5 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .env
13
- .pryrc
13
+ .pryrc
14
+ .tool-versions
data/Gemfile.lock CHANGED
@@ -1,62 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vncpost_api (0.2.0)
5
- activeresource
4
+ vncpost_api (0.3.1)
5
+ activeresource (>= 4.1.0)
6
+ jwt
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- activemodel (6.0.3)
11
- activesupport (= 6.0.3)
11
+ activemodel (7.0.2.4)
12
+ activesupport (= 7.0.2.4)
12
13
  activemodel-serializers-xml (1.0.2)
13
14
  activemodel (> 5.x)
14
15
  activesupport (> 5.x)
15
16
  builder (~> 3.1)
16
- activeresource (5.1.1)
17
- activemodel (>= 5.0, < 7)
17
+ activeresource (6.0.0)
18
+ activemodel (>= 6.0)
18
19
  activemodel-serializers-xml (~> 1.0)
19
- activesupport (>= 5.0, < 7)
20
- activesupport (6.0.3)
20
+ activesupport (>= 6.0)
21
+ activesupport (7.0.2.4)
21
22
  concurrent-ruby (~> 1.0, >= 1.0.2)
22
- i18n (>= 0.7, < 2)
23
- minitest (~> 5.1)
24
- tzinfo (~> 1.1)
25
- zeitwerk (~> 2.2, >= 2.2.2)
23
+ i18n (>= 1.6, < 2)
24
+ minitest (>= 5.1)
25
+ tzinfo (~> 2.0)
26
26
  builder (3.2.4)
27
- byebug (11.1.1)
28
- coderay (1.1.2)
29
- concurrent-ruby (1.1.6)
30
- diff-lcs (1.3)
31
- dotenv (2.7.5)
32
- i18n (1.8.2)
27
+ byebug (11.1.3)
28
+ coderay (1.1.3)
29
+ concurrent-ruby (1.1.10)
30
+ diff-lcs (1.5.0)
31
+ dotenv (2.7.6)
32
+ i18n (1.10.0)
33
33
  concurrent-ruby (~> 1.0)
34
+ jwt (2.3.0)
34
35
  method_source (1.0.0)
35
- minitest (5.14.1)
36
- pry (0.13.1)
36
+ minitest (5.15.0)
37
+ pry (0.14.1)
37
38
  coderay (~> 1.1)
38
39
  method_source (~> 1.0)
39
- pry-byebug (3.9.0)
40
+ pry-byebug (3.8.0)
40
41
  byebug (~> 11.0)
41
- pry (~> 0.13.0)
42
+ pry (~> 0.10)
42
43
  rake (12.3.3)
43
- rspec (3.9.0)
44
- rspec-core (~> 3.9.0)
45
- rspec-expectations (~> 3.9.0)
46
- rspec-mocks (~> 3.9.0)
47
- rspec-core (3.9.1)
48
- rspec-support (~> 3.9.1)
49
- rspec-expectations (3.9.1)
44
+ rspec (3.11.0)
45
+ rspec-core (~> 3.11.0)
46
+ rspec-expectations (~> 3.11.0)
47
+ rspec-mocks (~> 3.11.0)
48
+ rspec-core (3.11.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-expectations (3.11.0)
50
51
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.9.0)
52
- rspec-mocks (3.9.1)
52
+ rspec-support (~> 3.11.0)
53
+ rspec-mocks (3.11.1)
53
54
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.9.0)
55
- rspec-support (3.9.2)
56
- thread_safe (0.3.6)
57
- tzinfo (1.2.7)
58
- thread_safe (~> 0.1)
59
- zeitwerk (2.3.0)
55
+ rspec-support (~> 3.11.0)
56
+ rspec-support (3.11.0)
57
+ tzinfo (2.0.4)
58
+ concurrent-ruby (~> 1.0)
59
+ zeitwerk (2.5.4)
60
60
 
61
61
  PLATFORMS
62
62
  ruby
@@ -68,6 +68,7 @@ DEPENDENCIES
68
68
  rake (~> 12.0)
69
69
  rspec (~> 3.0)
70
70
  vncpost_api!
71
+ zeitwerk
71
72
 
72
73
  BUNDLED WITH
73
- 2.1.4
74
+ 2.2.33
data/lib/dev/config.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  def set_config
2
2
  VNCPostAPI.configure do |config|
3
- config.testing = true
3
+ config.testing = true
4
4
  config.username = ENV["VNCPOST_USERNAME"]
5
5
  config.password = ENV["VNCPOST_PASSWORD"]
6
6
  end
@@ -9,6 +9,7 @@ loader.push_dir("./lib")
9
9
  loader.collapse("./lib/vncpost_api/resources")
10
10
  loader.ignore("#{__dir__}/config.rb")
11
11
  loader.ignore("./lib/vncpost_api/exceptions.rb")
12
+ loader.ignore("./lib/vncpost_api/cache.rb")
12
13
  loader.enable_reloading
13
14
  # loader.log!
14
15
  loader.setup
@@ -0,0 +1,5 @@
1
+ module VNCPostAPI
2
+ mattr_accessor :cache
3
+
4
+ self.cache = ActiveSupport::Cache::MemoryStore.new
5
+ end
@@ -4,23 +4,35 @@ module VNCPostAPI
4
4
  alias_method :testing?, :testing
5
5
  end
6
6
 
7
- def self.config
8
- @config ||= Configuration.new
9
- end
7
+ class << self
8
+ def config
9
+ @config ||= Configuration.new
10
+ end
10
11
 
11
- def self.config=(config)
12
- @config = config
13
- end
12
+ def configure
13
+ yield config
14
+
15
+ after_configure
16
+ end
17
+
18
+ private
19
+
20
+ def after_configure
21
+ if config.testing?
22
+ test_site = "http://sgp-seaedi-test.800best.com"
23
+ VNCPostAPI::Base.site = test_site
24
+ VNCPostAPI::UserLogin.site = test_site
25
+ else
26
+ production_site = "http://sgp-seaedi.800best.com"
27
+ VNCPostAPI::Base.site = production_site
28
+ VNCPostAPI::UserLogin.site = production_site
29
+ end
30
+ # Tracking is only available on production
31
+ VNCPostAPI::Tracking.site = "http://pt.vncpost.com"
32
+
33
+ return unless defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache.is_a?(ActiveSupport::Cache::Store)
14
34
 
15
- def self.configure
16
- yield config
17
- # set the site once user configure
18
- if config.testing?
19
- VNCPostAPI::Base.site = "http://api.v3.vncpost.com"
20
- VNCPostAPI::Tracking.site ="https://pt.v.vncpost.com"
21
- else
22
- VNCPostAPI::Base.site = "http://u.api.vncpost.com"
23
- VNCPostAPI::Tracking.site = "https://pt.vncpost.com"
35
+ VNCPostAPI.cache = Rails.cache
24
36
  end
25
37
  end
26
38
  end
@@ -4,13 +4,14 @@ module VNCPostAPI
4
4
  body = JSON.parse(response.body)
5
5
  if body["Message"]
6
6
  message = "Failed.".dup
7
- message << " Error message: #{body["Message"]}"
7
+ message << " Message: #{body["Message"]}"
8
8
  message
9
9
  else
10
10
  super
11
11
  end
12
12
  end
13
13
  end
14
+
14
15
  class Connection < ActiveResource::Connection
15
16
  private
16
17
 
@@ -3,9 +3,10 @@ module VNCPostAPI
3
3
  self.include_root_in_json = false
4
4
  self.include_format_in_path = false
5
5
  self.connection_class = VNCPostAPI::Connection
6
+ self.auth_type = :bearer
6
7
 
7
8
  def create
8
- self.class.retrieve_token
9
+ connection.bearer_token = UserLogin.get_bearer_token
9
10
  format_before_send_request
10
11
  super
11
12
  rescue => e
@@ -23,26 +24,6 @@ module VNCPostAPI
23
24
 
24
25
  private
25
26
 
26
- def self.retrieve_token
27
- clear_auth_token
28
-
29
- if VNCPostAPI.config&.username && VNCPostAPI.config&.password
30
- response = connection.post("#{Base.site}/User/Login", {
31
- Username: VNCPostAPI.config.username,
32
- Password: VNCPostAPI.config.password
33
- }.to_json)
34
- connection.auth_type = :bearer
35
- connection.bearer_token = JSON.parse(response.body)["token"]
36
- else
37
- raise ArgumentError, "Please set the username and password in the config file under the initializer dir"
38
- end
39
- end
40
-
41
- def self.clear_auth_token
42
- connection.auth_type = nil
43
- connection.bearer_token = nil
44
- end
45
-
46
27
  def format_before_send_request
47
28
  @attributes.deep_transform_keys!(&:camelcase)
48
29
  end
@@ -55,6 +36,5 @@ module VNCPostAPI
55
36
  super
56
37
  reset_attributes_format
57
38
  end
58
-
59
39
  end
60
40
  end
@@ -44,7 +44,7 @@ module VNCPostAPI
44
44
  return_phone_number: nil
45
45
  }
46
46
 
47
- self.prefix = "/Order/Add"
47
+ self.prefix = "/VietNamV3/v3/api/process/sears/Order/Add"
48
48
  self.element_name = ""
49
49
 
50
50
  def initialize(attributes = {}, persisted = false)
@@ -1,17 +1,17 @@
1
1
  module VNCPostAPI
2
+ # Tracking is only available on production
2
3
  class Tracking < Base
3
4
  self.prefix = "/Track/Order"
4
5
  self.element_name = ""
6
+ self.connection_class = VNCPostAPI::Connection
5
7
 
6
8
  def self.find(code)
7
9
  body = {
8
10
  Code: code
9
11
  }
10
-
11
- self.retrieve_token
12
-
12
+ connection.bearer_token = UserLogin.get_bearer_token(username: "V9Cus327141793", password: "8DBNvF9Y56nnjNTU")
13
13
  response = connection.post(collection_path, body.to_json)
14
14
  new(self.format.decode(response.body).deep_transform_keys!(&:underscore))
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -0,0 +1,33 @@
1
+ require "jwt"
2
+
3
+ module VNCPostAPI
4
+ class UserLogin < ::ActiveResource::Base
5
+ self.include_root_in_json = false
6
+ self.include_format_in_path = false
7
+ self.prefix = "/VietNamV3/v3/api/process/sears/User/Login"
8
+ self.element_name = ""
9
+
10
+ class << self
11
+ def get_bearer_token(username: VNCPostAPI.config.username, password: VNCPostAPI.config.password)
12
+ cache_key = "VNCPostAPI/bearer_token"
13
+ cached_token = VNCPostAPI.cache.read(cache_key)
14
+ return cached_token if cached_token
15
+
16
+ token = create(Username: username, Password: password).token
17
+ VNCPostAPI.cache.write(
18
+ cache_key,
19
+ token,
20
+ expires_in: expires_in(token) - 15
21
+ )
22
+
23
+ token
24
+ end
25
+
26
+ private
27
+
28
+ def expires_in(jwt)
29
+ Time.at(JWT.decode(jwt, nil, false)[0]["exp"])
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module VNCPostAPI
2
- VERSION = "0.2.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/vncpost_api.rb CHANGED
@@ -2,11 +2,11 @@ require "vncpost_api/version"
2
2
  require "active_resource"
3
3
 
4
4
  module VNCPostAPI
5
+ require "vncpost_api/cache"
5
6
  require "vncpost_api/configuration"
6
-
7
7
  require "vncpost_api/connection"
8
-
9
8
  require "vncpost_api/resources/base"
10
- require "vncpost_api/resources/tracking"
11
9
  require "vncpost_api/resources/order"
10
+ require "vncpost_api/resources/tracking"
11
+ require "vncpost_api/resources/user_login"
12
12
  end
data/vncpost_api.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.summary = "Ruby object based VNCPost API wrapper."
10
10
  spec.homepage = "https://github.com/PostCo/vncpost_api"
11
11
  spec.license = "MIT"
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
13
13
 
14
14
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
15
15
 
@@ -26,10 +26,12 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_dependency "activeresource"
29
+ spec.add_dependency "activeresource", ">= 4.1.0"
30
+ spec.add_dependency "jwt"
30
31
 
31
32
  spec.add_development_dependency "rspec", "~> 3.2"
32
33
  spec.add_development_dependency "dotenv"
34
+ spec.add_development_dependency "zeitwerk"
33
35
  spec.add_development_dependency "pry-byebug"
34
36
  spec.add_development_dependency "pry"
35
37
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vncpost_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: zeitwerk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: pry-byebug
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +108,7 @@ dependencies:
80
108
  - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
- description:
111
+ description:
84
112
  email:
85
113
  - andygg1996personal@gmail.com
86
114
  executables: []
@@ -103,11 +131,13 @@ files:
103
131
  - lib/dev/config.rb
104
132
  - lib/dev/zeitwerk_loader.rb
105
133
  - lib/vncpost_api.rb
134
+ - lib/vncpost_api/cache.rb
106
135
  - lib/vncpost_api/configuration.rb
107
136
  - lib/vncpost_api/connection.rb
108
137
  - lib/vncpost_api/resources/base.rb
109
138
  - lib/vncpost_api/resources/order.rb
110
139
  - lib/vncpost_api/resources/tracking.rb
140
+ - lib/vncpost_api/resources/user_login.rb
111
141
  - lib/vncpost_api/version.rb
112
142
  - vncpost_api.gemspec
113
143
  homepage: https://github.com/PostCo/vncpost_api
@@ -118,7 +148,7 @@ metadata:
118
148
  homepage_uri: https://github.com/PostCo/vncpost_api
119
149
  source_code_uri: https://github.com/PostCo/vncpost_api
120
150
  changelog_uri: https://github.com/PostCo/vncpost_api/releases
121
- post_install_message:
151
+ post_install_message:
122
152
  rdoc_options: []
123
153
  require_paths:
124
154
  - lib
@@ -126,15 +156,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
156
  requirements:
127
157
  - - ">="
128
158
  - !ruby/object:Gem::Version
129
- version: 2.3.0
159
+ version: 2.7.0
130
160
  required_rubygems_version: !ruby/object:Gem::Requirement
131
161
  requirements:
132
162
  - - ">="
133
163
  - !ruby/object:Gem::Version
134
164
  version: '0'
135
165
  requirements: []
136
- rubygems_version: 3.0.3
137
- signing_key:
166
+ rubygems_version: 3.2.33
167
+ signing_key:
138
168
  specification_version: 4
139
169
  summary: Ruby object based VNCPost API wrapper.
140
170
  test_files: []