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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dev/config.rb +5 -4
- data/lib/shiprocket_api/configuration.rb +2 -1
- data/lib/shiprocket_api/resources/base.rb +12 -5
- data/lib/shiprocket_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96a88cfd89ff46caa8d68500d433c2535bb73816c16e3d26b39b769b22ea58c0
|
|
4
|
+
data.tar.gz: c96139061e67388fa02e0c9322a9cce9a0a60cf66687e7b17e0a245bc160bce9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c98d471f84e93c7096ad987c4f4b1ff4ad57529cb44e7233599dec0e5ea34b7d4f42d3c1fddb4ff4d90b9ebb6d104aedaf1678c73a9b37a8fb65ad679a3a0957
|
|
7
|
+
data.tar.gz: b4ef9231dff4b6b42fe617d2c675bb167477bdb0f6cffb2b8f30041728cfc07a659af9b6cb220382276058b097385730aba50c0a7bb605f873e656a1e9c5214a
|
data/Gemfile.lock
CHANGED
data/lib/dev/config.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'dotenv/load'
|
|
2
2
|
|
|
3
3
|
def set_config
|
|
4
4
|
ShiprocketAPI.configure do |config|
|
|
5
|
-
config.email = ENV[
|
|
6
|
-
config.password = ENV[
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
35
|
+
ensure
|
|
36
|
+
create_session
|
|
30
37
|
end
|
|
31
38
|
|
|
32
39
|
def set_prefix(prefix)
|
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.
|
|
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-
|
|
11
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activeresource
|