77require 'faraday/multipart'
88require 'faraday/retry'
99require 'sorbet-runtime'
10+ require_relative 'sdk_hooks/hooks'
1011require_relative 'utils/retries'
1112
1213module OpenApiSDK
@@ -21,8 +22,8 @@ def initialize(sdk_config)
2122 end
2223
2324
24- sig { params ( request : T . nilable ( ::OpenApiSDK ::Operations ::RetrieveAnalyticsRequest ) ) . returns ( ::OpenApiSDK ::Operations ::RetrieveAnalyticsResponse ) }
25- def retrieve ( request )
25+ sig { params ( request : T . nilable ( ::OpenApiSDK ::Operations ::RetrieveAnalyticsRequest ) , timeout_ms : T . nilable ( Integer ) ) . returns ( ::OpenApiSDK ::Operations ::RetrieveAnalyticsResponse ) }
26+ def retrieve ( request , timeout_ms = nil )
2627 # retrieve - Retrieve analytics for a link, a domain, or the authenticated workspace.
2728 # Retrieve analytics for a link, a domain, or the authenticated workspace. The response type depends on the `event` and `type` query parameters.
2829 url , params = @sdk_configuration . get_server_details
@@ -33,13 +34,61 @@ def retrieve(request)
3334 headers [ 'Accept' ] = 'application/json'
3435 headers [ 'user-agent' ] = @sdk_configuration . user_agent
3536
37+ security = !@sdk_configuration . nil? && !@sdk_configuration . security_source . nil? ? @sdk_configuration . security_source . call : nil
38+
39+ timeout = ( timeout_ms . to_f / 1000 ) unless timeout_ms . nil?
40+ timeout ||= @sdk_configuration . timeout
41+
3642 connection = @sdk_configuration . client
3743
38- r = connection . get ( url ) do |req |
39- req . headers = headers
40- req . params = query_params
41- security = !@sdk_configuration . nil? && !@sdk_configuration . security_source . nil? ? @sdk_configuration . security_source . call : nil
42- Utils . configure_request_security ( req , security ) if !security . nil?
44+ hook_ctx = SDKHooks ::HookContext . new (
45+ base_url : base_url ,
46+ oauth2_scopes : [ ] ,
47+ operation_id : 'retrieveAnalytics' ,
48+ security_source : @sdk_configuration . security_source
49+ )
50+
51+ error = T . let ( nil , T . nilable ( StandardError ) )
52+ r = T . let ( nil , T . nilable ( Faraday ::Response ) )
53+
54+ begin
55+ r = connection . get ( url ) do |req |
56+ req . headers . merge! ( headers )
57+ req . options . timeout = timeout unless timeout . nil?
58+ req . params = query_params
59+ Utils . configure_request_security ( req , security )
60+
61+ @sdk_configuration . hooks . before_request (
62+ hook_ctx : SDKHooks ::BeforeRequestHookContext . new (
63+ hook_ctx : hook_ctx
64+ ) ,
65+ request : req
66+ )
67+ end
68+ rescue StandardError => e
69+ error = e
70+ ensure
71+ if r . nil? || Utils . error_status? ( r . status )
72+ r = @sdk_configuration . hooks . after_error (
73+ error : error ,
74+ hook_ctx : SDKHooks ::AfterErrorHookContext . new (
75+ hook_ctx : hook_ctx
76+ ) ,
77+ response : r
78+ )
79+ else
80+ r = @sdk_configuration . hooks . after_success (
81+ hook_ctx : SDKHooks ::AfterSuccessHookContext . new (
82+ hook_ctx : hook_ctx
83+ ) ,
84+ response : r
85+ )
86+ end
87+
88+ if r . nil?
89+ raise error if !error . nil?
90+ raise 'no response'
91+ end
4392 end
4493
4594 content_type = r . headers . fetch ( 'Content-Type' , 'application/octet-stream' )
0 commit comments