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 58a1555
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 17 additions & 0 deletions stone/backends/swift_rsrc/ObjCRoutes.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,29 @@ public class {{ fmt_route_objc_class(namespace, route, args_data) }}: NSObject,
self.response(queue: nil, completionHandler: completionHandler)
}

{% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %}
@objc
@discardableResult public func response(
queue: DispatchQueue?,
completionHandler: @escaping ({{ result_type }}) -> Void
) -> Self {
self.response(queue: nil, analyticsBlock: nil, completionHandler: completionHandler)
}
{% endif %}

@objc
@discardableResult public func response(
queue: DispatchQueue? = nil,
{% 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 58a1555

Please sign in to comment.