fantasticstay_api 0.1.8 → 0.1.10

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: 738b039ce921a5d93329f37ae2591232a237d77bbfb31ce9e77405800565ea4b
4
- data.tar.gz: 52ce2629fd1cbe2502996c08eaec1453f24fe194960f50cbd2e77a0380e190ea
3
+ metadata.gz: cf9be90bc43b625d86fc4f6a024a4031af806d435b7328499a88e24001d10b4d
4
+ data.tar.gz: '09745920add5e1e3c4ca23997b1ca75bf8a8e82ccd7b7bda24cf4ca7cacfa33c'
5
5
  SHA512:
6
- metadata.gz: f8fbc83b647ba08bfaaae2b609ff3d1e23fefe48d1f55e9ff15387f103ac95c0a7e12d775115b547849b1ba526a418a66a91b1ba8ac6a8a17c7d6173c53313d2
7
- data.tar.gz: da9ca9eb3fc3b60aa7a9f00601d21e8eac365be0aa15264410c13dec97853207addbb2ddf3cc67eb3cabf509a026a8b1b082d30ca7e2012910364d1cf27f206e
6
+ metadata.gz: 98c7479b0c84b51e96dce10274f338ba069c7952bfc977f26af804a51a8b5bb36e58192ccbcc4acdb2ca8fbaaacd8009178c801837eda640fbcde8c95112e780
7
+ data.tar.gz: 64dcd5e2faf0138e51a6544ae20c04519c143c3ee010dbf11548611c72b51ef7ddc10cc1bd60d2fe391ccb9593162eb6cb9d7d0d6545e1d869d8069075b3316a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fantasticstay_api (0.1.7)
4
+ fantasticstay_api (0.1.9)
5
5
  api_cache (~> 0.3.0)
6
6
  dry-configurable (~> 0.13)
7
7
  faraday (~> 2.6.0)
@@ -15,7 +15,7 @@ GEM
15
15
  api_cache (0.3.0)
16
16
  ast (2.4.2)
17
17
  base64 (0.2.0)
18
- bigdecimal (3.1.8)
18
+ bigdecimal (3.1.9)
19
19
  concurrent-ruby (1.3.4)
20
20
  crack (1.0.0)
21
21
  bigdecimal
@@ -31,26 +31,26 @@ GEM
31
31
  faraday-net_http (>= 2.0, < 3.1)
32
32
  ruby2_keywords (>= 0.0.4)
33
33
  faraday-net_http (3.0.2)
34
- hashdiff (1.1.1)
35
- oj (3.16.6)
34
+ hashdiff (1.1.2)
35
+ oj (3.16.9)
36
36
  bigdecimal (>= 3.0)
37
37
  ostruct (>= 0.2)
38
- ostruct (0.6.0)
38
+ ostruct (0.6.1)
39
39
  parallel (1.26.3)
40
- parser (3.3.5.0)
40
+ parser (3.3.6.0)
41
41
  ast (~> 2.4.1)
42
42
  racc
43
43
  public_suffix (6.0.1)
44
44
  racc (1.8.1)
45
45
  rainbow (3.1.1)
46
46
  rake (13.2.1)
47
- regexp_parser (2.9.2)
48
- rexml (3.3.8)
47
+ regexp_parser (2.10.0)
48
+ rexml (3.4.0)
49
49
  rspec (3.13.0)
50
50
  rspec-core (~> 3.13.0)
51
51
  rspec-expectations (~> 3.13.0)
52
52
  rspec-mocks (~> 3.13.0)
53
- rspec-core (3.13.1)
53
+ rspec-core (3.13.2)
54
54
  rspec-support (~> 3.13.0)
55
55
  rspec-expectations (3.13.3)
56
56
  diff-lcs (>= 1.2.0, < 2.0)
@@ -58,7 +58,7 @@ GEM
58
58
  rspec-mocks (3.13.2)
59
59
  diff-lcs (>= 1.2.0, < 2.0)
60
60
  rspec-support (~> 3.13.0)
61
- rspec-support (3.13.1)
61
+ rspec-support (3.13.2)
62
62
  rubocop (0.93.1)
63
63
  parallel (~> 1.10)
64
64
  parser (>= 2.7.1.5)
@@ -68,7 +68,7 @@ GEM
68
68
  rubocop-ast (>= 0.6.0)
69
69
  ruby-progressbar (~> 1.7)
70
70
  unicode-display_width (>= 1.4.0, < 2.0)
71
- rubocop-ast (1.32.3)
71
+ rubocop-ast (1.37.0)
72
72
  parser (>= 3.3.1.0)
73
73
  ruby-progressbar (1.13.0)
74
74
  ruby2_keywords (0.0.5)
@@ -24,7 +24,8 @@ module FantasticstayApi
24
24
  'default' => ApiError
25
25
  }.freeze
26
26
  API_ENDPOINT = 'https://api.fsapp.io'
27
- API_TIMEOUT = 30
27
+ API_TIMEOUT = 5 # API response timeout
28
+ API_STALE_VALIDITY = :forever # 604800 = 7 days - Maximum time to use old data
28
29
  API_TOKEN = 'TESTING'
29
30
 
30
31
  setting :follow_redirects, default: true
@@ -35,6 +36,9 @@ module FantasticstayApi
35
36
  # The timeout in requests made to fsapp
36
37
  setting :timeout, default: ENV['FANTASTICSTAY_API_TIMEOUT'] || API_TIMEOUT, reader: true
37
38
 
39
+ # The stale validity in requests that fail to fsapp
40
+ setting :stale_validity, default: ENV['FANTASTICSTAY_API_STALE_VALIDITY'] || API_STALE_VALIDITY, reader: true
41
+
38
42
  # The token included in request header 'x-api-key'
39
43
  setting :token, default: ENV['FANTASTICSTAY_API_TOKEN'] || API_TOKEN, reader: true
40
44
 
@@ -78,18 +82,24 @@ module FantasticstayApi
78
82
  @client ||= Faraday.new(config.endpoint) do |client|
79
83
  client.request :url_encoded
80
84
  client.adapter Faraday.default_adapter
81
- client.headers['Content-Type'] = 'application/json'
82
- client.headers['x-api-key'] = config.token
83
- client.headers['User-Agent'] = config.user_agent
84
85
  client.options.timeout = config.timeout
86
+ init_client_headers(client)
85
87
  client.response :raise_error # raise Faraday::Error on status code 4xx or 5xx
88
+ client.response :logger, ::Logger.new($stdout), body: true, bodies: { request: true, response: true }
86
89
  end
87
90
  end
88
91
 
92
+ def init_client_headers(client)
93
+ client.headers['Content-Type'] = 'application/json'
94
+ client.headers['x-api-key'] = config.token
95
+ client.headers['User-Agent'] = config.user_agent
96
+ end
97
+
89
98
  def request(http_method:, endpoint:, params: {}, cache_ttl: 3600)
90
99
  response = APICache.get(
91
100
  Digest::SHA256.bubblebabble(config.token) + http_method.to_s + endpoint + params.to_s,
92
101
  cache: cache_ttl,
102
+ valid: config.stale_validity,
93
103
  timeout: config.timeout
94
104
  ) do
95
105
  client.public_send(http_method, endpoint, params)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FantasticstayApi
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.10'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasticstay_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-14 00:00:00.000000000 Z
11
+ date: 2025-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_cache