vncpost_api 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4711251bf2f83d6f27bc258c6a9c7190ba56a3743d078ffe11b97725fe58c640
4
- data.tar.gz: 0d0febd554898baf313c4bfec8e5924be1424906de0a35a818e9fe3dc4566331
3
+ metadata.gz: 650cf96fee5d0224ceaf1641113b0aab2c2fd235d2bc29aad7ee2519332b43e4
4
+ data.tar.gz: f8148600472f359fadc878fcb2a1105692aab1294c37e90d5a1bc8a470cf3c00
5
5
  SHA512:
6
- metadata.gz: 33a58c22000f60b09363337b5af981b7712722607b162e702a3ca1e3d8fe7d30a37c83a65a588b1d36d941cb0c848557bba536a23cd8f4f74189cebaccfb286c
7
- data.tar.gz: cfe8e8dba531e438396b180c1ae0b4107aa095e77b561a5e1d31a100e371777b9765b1050705a5b12b8e6d3305a504bfa2f03b30c183bf23471a72695c66be0a
6
+ metadata.gz: b6a1caecf2665012c91742cd599677ee79f63815b465bc0fe20c5100adc3eada33542fa2a33c7138219584685e7f1f018e3f209401f13766bfe014315c8008f7
7
+ data.tar.gz: ba332c32e2769fb1c1d79b9aee2bcd080d12e56de4eb0e227a15b4f071eed7cff67e4569a2616b0ace3979df434f0ce96c51d01a372d9031c5e6b261abf95251
@@ -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.1.0)
5
- activeresource
4
+ vncpost_api (0.3.0)
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.2.2)
11
- activesupport (= 6.0.2.2)
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.0)
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.2.2)
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)
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.0)
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,33 @@ 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
+ VNCPostAPI::Base.site = "http://api.v3.vncpost.com"
23
+ VNCPostAPI::UserLogin.site = "http://api.v3.vncpost.com"
24
+ else
25
+ VNCPostAPI::Base.site = "https://u.api.vncpost.com"
26
+ VNCPostAPI::UserLogin.site = "https://u.api.vncpost.com"
27
+ end
28
+ # Tracking is only available on production
29
+ VNCPostAPI::Tracking.site = "http://pt.vncpost.com"
30
+
31
+ return unless defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache.is_a?(ActiveSupport::Cache::Store)
14
32
 
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"
33
+ VNCPostAPI.cache = Rails.cache
24
34
  end
25
35
  end
26
36
  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
@@ -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 = "/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.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/vncpost_api.rb CHANGED
@@ -2,10 +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
9
  require "vncpost_api/resources/order"
10
+ require "vncpost_api/resources/tracking"
11
+ require "vncpost_api/resources/user_login"
11
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.0
4
+ version: 0.3.1
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-04-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: []