shiprocket_api 0.7.0 → 0.8.0

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: c89478ab280c57c06c2cad814d8527324ce2813e1b86d1ac366d435460c524f2
4
- data.tar.gz: 771eff728f0889bef92183361a69726282e7b0e3564a91d7fb0f77e45bdbabbe
3
+ metadata.gz: 96a88cfd89ff46caa8d68500d433c2535bb73816c16e3d26b39b769b22ea58c0
4
+ data.tar.gz: c96139061e67388fa02e0c9322a9cce9a0a60cf66687e7b17e0a245bc160bce9
5
5
  SHA512:
6
- metadata.gz: a2f324443ca90f4d84b8c991cebf1f09ff032cbf200d564226e9c2119e459df8673545fb8f993003caa9b5c9ed471e3b8d41901cfccd13e174ffa99f2414b80c
7
- data.tar.gz: 39438796c50f6b0f66104cb85234c3ffe5596093d33a9c784e12a1d08e929d1dc8ef284dc33b33f30fb605c95f3a4226164e92fdf145354010eae84bba6925f8
6
+ metadata.gz: c98d471f84e93c7096ad987c4f4b1ff4ad57529cb44e7233599dec0e5ea34b7d4f42d3c1fddb4ff4d90b9ebb6d104aedaf1678c73a9b37a8fb65ad679a3a0957
7
+ data.tar.gz: b4ef9231dff4b6b42fe617d2c675bb167477bdb0f6cffb2b8f30041728cfc07a659af9b6cb220382276058b097385730aba50c0a7bb605f873e656a1e9c5214a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiprocket_api (0.6.0)
4
+ shiprocket_api (0.7.0)
5
5
  activeresource (>= 4.1.0)
6
6
  http
7
7
 
data/lib/dev/config.rb CHANGED
@@ -1,8 +1,9 @@
1
- require "dotenv/load"
1
+ require 'dotenv/load'
2
2
 
3
3
  def set_config
4
4
  ShiprocketAPI.configure do |config|
5
- config.email = ENV["SHIPROCKET_API_EMAIL"]
6
- config.password = ENV["SHIPROCKET_API_PASSWORD"]
5
+ config.email = ENV['SHIPROCKET_API_EMAIL']
6
+ config.password = ENV['SHIPROCKET_API_PASSWORD']
7
+ config.cache = ActiveSupport::Cache::MemoryStore.new
7
8
  end
8
- end
9
+ end
@@ -1,6 +1,6 @@
1
1
  module ShiprocketAPI
2
2
  class Configuration
3
- attr_accessor :email, :password
3
+ attr_accessor :email, :password, :cache
4
4
  end
5
5
 
6
6
  def self.config
@@ -13,5 +13,6 @@ module ShiprocketAPI
13
13
 
14
14
  def self.configure
15
15
  yield config
16
+ Base.cache = config.cache || ActiveSupport::Cache::NullStore.new
16
17
  end
17
18
  end
@@ -1,6 +1,6 @@
1
1
  module ShiprocketAPI
2
2
  class Base < ActiveResource::Base
3
- cattr_accessor :session
3
+ # cattr_accessor :session
4
4
 
5
5
  self.connection_class = ShiprocketAPI::Connection
6
6
  self.include_root_in_json = false
@@ -8,11 +8,17 @@ module ShiprocketAPI
8
8
  self.site = 'https://apiv2.shiprocket.in'
9
9
  connection.auth_type = :bearer
10
10
  self.prefix = '/v1/external'
11
- self.session = nil
12
11
 
13
12
  class << self
13
+ include ThreadsafeAttributes
14
+ threadsafe_attribute :session, :cache
15
+
14
16
  def create_session(email: ShiprocketAPI.config.email, password: ShiprocketAPI.config.password)
15
- self.session = Session.create(email: email, password: password)
17
+ cache_key = Digest::SHA2.new(256).hexdigest("#{email}-#{password}")
18
+
19
+ self.session = cache.fetch(cache_key, expires_in: 9.days) do
20
+ Session.create(email: email, password: password)
21
+ end
16
22
  connection.bearer_token = session.token
17
23
  end
18
24
 
@@ -21,12 +27,13 @@ module ShiprocketAPI
21
27
  connection.bearer_token = nil
22
28
  end
23
29
 
24
- def with_temp_session(email:, password:, &block)
30
+ def temp_session(email:, password:, &block)
25
31
  raise ArgumentError, 'A block must be given' unless block
26
32
 
27
33
  create_session(email: email, password: password)
28
34
  yield
29
- clear_session
35
+ ensure
36
+ create_session
30
37
  end
31
38
 
32
39
  def set_prefix(prefix)
@@ -1,3 +1,3 @@
1
1
  module ShiprocketAPI
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiprocket_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource