Class: Seekmodo::Sdk::Storefront::Transport
- Inherits:
-
Object
- Object
- Seekmodo::Sdk::Storefront::Transport
- Defined in:
- lib/seekmodo/sdk/storefront/transport.rb
Defined Under Namespace
Classes: AuthError, Error, NetworkError, QuotaError, RequestError, ServerError
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://gateway.seekmodo.com"- DEFAULT_TIMEOUT_MS =
8000
Instance Method Summary collapse
- #call(tool, args = {}, opts = {}) ⇒ Object
- #clear_token_cache ⇒ Object
-
#initialize(tenant_id:, get_token:, base_url: DEFAULT_BASE_URL, connection: nil, timeout_ms: DEFAULT_TIMEOUT_MS, signal: nil, on_error: nil, get_region: nil, user_agent: "seekmodo-ruby-sdk/0.5.0") ⇒ Transport
constructor
A new instance of Transport.
Constructor Details
#initialize(tenant_id:, get_token:, base_url: DEFAULT_BASE_URL, connection: nil, timeout_ms: DEFAULT_TIMEOUT_MS, signal: nil, on_error: nil, get_region: nil, user_agent: "seekmodo-ruby-sdk/0.5.0") ⇒ Transport
Returns a new instance of Transport.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/seekmodo/sdk/storefront/transport.rb', line 13 def initialize( tenant_id:, get_token:, base_url: DEFAULT_BASE_URL, connection: nil, timeout_ms: DEFAULT_TIMEOUT_MS, signal: nil, on_error: nil, get_region: nil, user_agent: "seekmodo-ruby-sdk/0.5.0" ) raise ArgumentError, "Seekmodo SDK: tenant_id is required" if tenant_id.to_s.empty? raise ArgumentError, "Seekmodo SDK: get_token callback is required" unless get_token.respond_to?(:call) @tenant_id = tenant_id @get_token = get_token @base_url = base_url.to_s.delete_suffix("/") @timeout_ms = timeout_ms @signal = signal @on_error = on_error @get_region = get_region @user_agent = user_agent @cached_token = nil @owns_connection = connection.nil? @connection = connection || Faraday.new do |f| f..timeout = timeout_ms / 1000.0 f.adapter Faraday.default_adapter end end |
Instance Method Details
#call(tool, args = {}, opts = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/seekmodo/sdk/storefront/transport.rb', line 47 def call(tool, args = {}, opts = {}) begin call_once(tool, args, opts, false) rescue AuthError => e clear_token_cache begin call_once(tool, args, opts, true) rescue StandardError => retry_err @on_error&.call(retry_err, tool: tool) raise retry_err end rescue StandardError => e @on_error&.call(e, tool: tool) raise e end end |
#clear_token_cache ⇒ Object
43 44 45 |
# File 'lib/seekmodo/sdk/storefront/transport.rb', line 43 def clear_token_cache @cached_token = nil end |