Skip to content

Commit

Permalink
Add analytics block to shim response block helper
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlocke committed Oct 1, 2024
1 parent 0967c3e commit bd7e81e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions stone/backends/swift_rsrc/ObjCRoutes.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public class {{ fmt_route_objc_class(namespace, route, args_data) }}: NSObject,

@objc
@discardableResult public func response(
{% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %}
analyticsBlock: AnalyticsBlock? = nil,
{% endif %}
completionHandler: @escaping ({{ result_type }}) -> Void
) -> Self {
self.response(queue: nil, completionHandler: completionHandler)
Expand All @@ -107,9 +110,16 @@ public class {{ fmt_route_objc_class(namespace, route, args_data) }}: NSObject,
@objc
@discardableResult public func response(
queue: DispatchQueue?,
{% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %}
analyticsBlock: AnalyticsBlock? = nil,
{% endif %}
completionHandler: @escaping ({{ result_type }}) -> Void
) -> Self {
{% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %}
swift.response(queue: queue, analyticsBlock: analyticsBlock) { result, error in
{% else %}
swift.response(queue: queue) { result, error in
{% endif %}
{% if route.error_data_type.name != 'Void' %}
{% set error_type = 'DBX' + fmt_class(route.error_data_type.namespace.name) + fmt_class(route.error_data_type.name) %}
{% set error_call = 'routeError, callError' %}
Expand Down
11 changes: 6 additions & 5 deletions stone/backends/swift_rsrc/SwiftObjcShimHelpers.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import stone_sdk_swift_objc
public class SDKShimHelpers: NSObject {
// MARK: DBAPIRpcTask

@objc public static func setResponseBlockRPC(block: @escaping DBRpcResponseBlockImpl, on task: DBXRequest, with queue: OperationQueue?) -> Bool {
@objc
@discardableResult public static func setResponseBlockRPC(block: @escaping DBRpcResponseBlockImpl, on task: DBXRequest, with queue: OperationQueue?, analyticsBlock: AnalyticsBlock?) -> Bool {
{% for namespace in namespaces | selectattr('name', '!=', 'team') %}
{% for route in namespace.routes %}
{% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %}
Expand All @@ -22,21 +23,21 @@ public class SDKShimHelpers: NSObject {
{% set objc_error_mapper = objc_to_legacy_objc_mapper(route.error_data_type, 'routeError') %}
if let task = task as? {{ objc_request_class }} {
{% if route.result_data_type.name == 'Void' and route.error_data_type.name == 'Void' %}
task.response { networkError in
task.response(analyticsBlock: analyticsBlock) { networkError in
let mappedCallError = callErrorToDB(error: networkError)
let wrappedBlock = { block(networkError == nil ? DBNilObject() : nil, nil, mappedCallError) }
{% elif route.result_data_type.name == 'Void' %}
task.response { routeError, networkError in
task.response(analyticsBlock: analyticsBlock) { routeError, networkError in
let mappedError = {{ objc_error_mapper }}
let mappedCallError = callErrorToDB(error: networkError)
let wrappedBlock = { block((networkError == nil && routeError == nil) ? DBNilObject() : nil, mappedError, mappedCallError) }
{% elif route.error_data_type.name == 'Void' %}
task.response { result, networkError in
task.response(analyticsBlock: analyticsBlock) { result, networkError in
let mappedResult = {{ objc_result_mapper }}
let mappedCallError = callErrorToDB(error: networkError)
let wrappedBlock = { block(mappedResult, nil, mappedCallError) }
{% else %}
task.response { result, routeError, networkError in
task.response(analyticsBlock: analyticsBlock) { result, routeError, networkError in
let mappedResult = {{ objc_result_mapper }}
let mappedError = {{ objc_error_mapper }}
let mappedCallError = callErrorToDB(error: networkError)
Expand Down

0 comments on commit bd7e81e

Please sign in to comment.