Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e978714
Add EntitySet class to perform lazy loading of child properties/entit…
tomas Apr 28, 2020
19b9788
Merge stuff from stubbing branch
tomas Apr 28, 2020
88bc8ae
Add PropertySet/EntitySet/RelationSet
tomas Apr 29, 2020
856fef2
Entity: Alias #[] to #try
tomas Apr 29, 2020
bf3f96a
Add Entity::PropertySet#to_hash
tomas Apr 29, 2020
a589ae5
Add PropertySet#dig
tomas Apr 29, 2020
9161bf6
Make PropertySets enumerable
tomas Apr 30, 2020
e1b9500
Enumerating over PropertySet should return key,val
tomas Apr 30, 2020
3b9fde4
Map #as_json to #to_hash in Entity and PropertyHash
tomas May 1, 2020
5465be3
Duh, as_json receives an options argument
tomas May 1, 2020
d57d962
Avoid initializing embedded items immediately on Entity initializiati…
tomas May 1, 2020
b038d79
Make EntityArray inherit from Array so we get .empty? et-al when usin…
tomas May 1, 2020
1bdc009
EntityArray: Revert to previous behaviour, but forward some methods t…
tomas May 1, 2020
426cca7
Rename 'props' to 'properties' and 'rels' to 'relations' for clarity.…
tomas May 1, 2020
d1002d1
Overwrite PropertySet#count to avoid breaking behaviour of some entit…
tomas May 4, 2020
f9545a8
Use require relative in main require for easier local testing
tomas May 4, 2020
7cf2d01
EntityArray: Don't forward #any? to @items directly as we'd lose the …
tomas May 6, 2020
6c0a1bf
Allow method? access for boolean properties
tomas May 7, 2020
f5b9ff0
Retry requests on connection failure, and allow setting open/read tim…
tomas Aug 13, 2020
d7db068
Move retry logic to client.rb
tomas Aug 13, 2020
8eeaca5
Merged master
tomas Mar 9, 2022
194e28f
Alias to_h to to_hash in entity properties
tomas Feb 2, 2023
accf4ba
Merge branch 'master' into lazy-loading
tomas Feb 2, 2023
c035f5a
Alias to_hash to to_h in Entity
tomas May 23, 2023
9758354
Change && for and
tomas May 23, 2023
de6fbbf
Merge branch 'master' into lazy-loading
tomas Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/bootic_client.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'logger'
require "bootic_client/version"
require "bootic_client/entity"
require "bootic_client/relation"
require "bootic_client/client"
require "bootic_client/configuration"
require_relative './bootic_client/version'
require_relative './bootic_client/entity'
require_relative './bootic_client/relation'
require_relative './bootic_client/client'
require_relative './bootic_client/configuration'

module BooticClient
class << self
Expand All @@ -13,6 +13,7 @@ def strategies

def client(strategy_name, client_opts = {}, &on_new_token)
return @stubber if @stubber

opts = client_opts.dup
opts[:logging] = configuration.logging
opts[:logger] = configuration.logger if configuration.logging
Expand Down
21 changes: 19 additions & 2 deletions lib/bootic_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ def self.load(string)

private

DEFAULT_TIMEOUT = 20.freeze # seconds

def conn(&block)
@conn ||= Faraday.new do |f|
cache_options = {serializer: SafeCacheSerializer, shared_cache: false, store: options[:cache_store]}
request_opts = {
timeout: (options[:timeout] || DEFAULT_TIMEOUT).to_i, # both read/open timeout
open_timeout: (options[:open_timeout] || DEFAULT_TIMEOUT).to_i # only open timeout
}

@conn ||= Faraday.new(request: request_opts) do |f|
cache_options = { serializer: SafeCacheSerializer, shared_cache: false, store: options[:cache_store] }
cache_options[:logger] = options[:logger] if options[:logging]

f.use :http_cache, **cache_options
Expand All @@ -102,6 +109,8 @@ def request_headers
end

def validated_request!(verb, href, &block)
retries ||= 0

resp = conn.send(verb) do |req|
req.url href
req.headers.update request_headers
Expand All @@ -110,6 +119,14 @@ def validated_request!(verb, href, &block)

raise_if_invalid! resp
resp

rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
if (retries += 1) < 3 # max retries
puts "Got #{e.class} error, attempt #{retries}, retrying..."
retry
else
raise
end
end

def raise_if_invalid!(resp)
Expand Down
Loading