QNE 0.4.1 → 0.5.2

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: '08af2240c5e32d2f70556448cfdfad22426d92148d3201ff00d9245cb28044cb'
4
- data.tar.gz: b1c2cef04320bf582664ee675c0fbdb674a56afa8503c8e3cc456e7e5ef165e8
3
+ metadata.gz: 5a03fcd46a6306a4b0e8e18433b0d60cdaaea726c28e0123c98d81f419a4bcfa
4
+ data.tar.gz: 28dee7da9e164b9c25d3daf21ed1764922ba1ffc3f61148babb70653de140e57
5
5
  SHA512:
6
- metadata.gz: 13fd75a27ded11b6951ce4ebcedf31bd1a12f440afba44efafc4a54b23e1eb2675a87c87f66aa0bc7ba2fabdb6478910ae0d376b939d9119177e68639816b68d
7
- data.tar.gz: 4ec19df06acf1d594bb0263f43996b264fb99675c383628d3000aa80b45f564b072b3084a749eb7cd889cf3bc3cd9ea738d0ee1123ae42585abac4d8ca382257
6
+ metadata.gz: 28554d4627be68ffd0e94353c7c15763d8286fdc2bbeaf76401aecaadc8792bd71bb6f4f0b51bdafbb894b0d842e50b94a84272adf2bc947365b7495e9a2f644
7
+ data.tar.gz: b56aea0997738e4f4ef37d4441fb5dfe6c6995aa81aa330ee3cb2cca63a6e71ed17c45e843a6e6f6821661d68ed019693b80fafdcb95caccee5711b1dc2d870b
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.5
3
+ SuggestExtensions: false
3
4
 
4
5
  Style/StringLiterals:
5
6
  Enabled: true
@@ -21,4 +22,9 @@ Style/Documentation:
21
22
  Enabled: false
22
23
 
23
24
  Naming/FileName:
24
- Enabled: false
25
+ Enabled: false
26
+
27
+ Style/FrozenStringLiteralComment:
28
+ Enabled: true
29
+ Exclude:
30
+ - 'Gemfile'
data/Gemfile CHANGED
@@ -1,12 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
1
  source 'https://rubygems.org'
4
2
 
5
3
  # Specify your gem's dependencies in QNE.gemspec
6
4
  gemspec
7
5
 
6
+ gem 'faraday-net_http_persistent', '~> 2.3'
7
+ gem 'faraday-retry', '~> 2.3'
8
+ gem 'net-http-persistent', '~> 4.0'
8
9
  gem 'rake', '~> 13.0'
9
-
10
10
  gem 'rspec', '~> 3.0'
11
-
12
11
  gem 'rubocop', '~> 1.21'
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- QNE (0.4.1)
4
+ QNE (0.5.1)
5
5
  faraday (>= 1.10)
6
6
  faraday-net_http_persistent (>= 1.2)
7
+ faraday-retry
7
8
  net-http-persistent (>= 4.0)
8
9
 
9
10
  GEM
@@ -27,6 +28,8 @@ GEM
27
28
  faraday-net_http_persistent (2.3.1)
28
29
  faraday (~> 2.5)
29
30
  net-http-persistent (>= 4.0.4, < 5)
31
+ faraday-retry (2.3.2)
32
+ faraday (~> 2.0)
30
33
  hashdiff (1.2.1)
31
34
  json (2.15.2)
32
35
  language_server-protocol (3.17.0.5)
@@ -89,6 +92,9 @@ PLATFORMS
89
92
 
90
93
  DEPENDENCIES
91
94
  QNE!
95
+ faraday-net_http_persistent (~> 2.3)
96
+ faraday-retry (~> 2.3)
97
+ net-http-persistent (~> 4.0)
92
98
  rake (~> 13.0)
93
99
  rspec (~> 3.0)
94
100
  rubocop (~> 1.21)
data/README.md CHANGED
@@ -30,6 +30,23 @@ then you can use it to perform desired operation
30
30
 
31
31
  ```ruby
32
32
  conn.customers.all(top: 10) # returns top 10 customers
33
+
34
+ # if you want to have a custom retry_block
35
+ # the retry block will be executed before retry happens
36
+ # for example i have a block for creating logs
37
+ def create_logs
38
+ puts 'Error Occurred'.
39
+ end
40
+
41
+ def retry_block
42
+ proc { create_logs }
43
+ end
44
+
45
+ # so now when you establish the connection you will
46
+ # pass the block in the qne_connection argument
47
+ # # when farday occur and it reached the first retry
48
+ # the block will be executed
49
+ conn = @integration.qne_connection(retry_block)
33
50
  ```
34
51
 
35
52
  you can also check if the `db_code` is valid:
data/lib/QNE/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QNE
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.2'
5
5
  end
data/lib/QNE.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
3
+ require 'faraday/retry'
4
4
  require 'faraday/net_http_persistent'
5
5
  require_relative 'QNE/version'
6
6
  require_relative 'query_builder'
@@ -9,7 +9,5 @@ require_relative 'connection'
9
9
 
10
10
  module QNE
11
11
  class Error < StandardError; end
12
- # Your code goes here...
13
-
14
12
  class UnathorizedError < Error; end
15
13
  end
data/lib/connection.rb CHANGED
@@ -18,9 +18,11 @@ module QNE
18
18
  class Connection
19
19
  BASE_URI = 'https://dev-api.qne.cloud'
20
20
 
21
- def initialize(options = {})
21
+ # You can provide your own block before executing retry function
22
+ def initialize(options = {}, &retry_block)
22
23
  @db_code = options.fetch(:db_code, nil) || ENV['QNE_DB_CODE']
23
24
  @api_token = options.fetch(:api_token, nil)
25
+ @retry_block = retry_block
24
26
  end
25
27
 
26
28
  def system_version
@@ -88,7 +90,10 @@ module QNE
88
90
  end
89
91
 
90
92
  def connection
91
- @connection ||= Faraday.new(faraday_params)
93
+ @connection ||= Faraday.new(faraday_params) do |conn|
94
+ conn.request :retry, retry_options
95
+ conn.adapter Faraday.default_adapter
96
+ end
92
97
  end
93
98
 
94
99
  private
@@ -101,6 +106,17 @@ module QNE
101
106
  }
102
107
  end
103
108
 
109
+ def retry_options
110
+ @retry_options ||= {
111
+ retry_statuses: [401, 409, 500],
112
+ max: ENV.fetch('MAX_REQUEST_RETRY', '3').to_i, # total request will be made is 4
113
+ interval: ENV.fetch('INTERVAL_RETRY_NUMBER', '10').to_i, # interval each retry request
114
+ backoff_factor: 0,
115
+ exceptions: [Faraday::ResourceNotFound, Faraday::UnauthorizedError, Faraday::TimeoutError, Faraday::ConnectionFailed],
116
+ retry_block: @retry_block
117
+ }
118
+ end
119
+
104
120
  def auth_method
105
121
  @api_token ? bearer_auth : dbcode_auth
106
122
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: QNE
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nujian Den Mark Meralpis
@@ -37,6 +37,20 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '1.2'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faraday-retry
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: net-http-persistent
42
56
  requirement: !ruby/object:Gem::Requirement