This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIComponent(BaseModel, ABC): | |
# ... | |
def __init__(self, **data) -> None: | |
# SDUIContext is set as a context var when handling any request on the backend | |
current_context = SDUIContext.current() | |
if current_context is not None: | |
# Will raise an error if incompatible | |
current_context.validate_compatibility( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataRow(UIComponent): | |
title: str | |
subtitle: str | |
layout: Layout = Layout.HORIZONTAL | |
@classmethod | |
def component_type(cls) -> ComponentType: | |
return ComponentType.DATA_ROW_STACKED | |
class Layout(str, Enum): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIComponent(BaseModel, ABC): | |
sdui_component_type: ComponentType | |
def __init__(self, **data) -> None: | |
data['sdui_component_type'] = self.component_type() | |
super().__init__(**data) | |
@classmethod | |
@abstractmethod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A [CallAdapter.Factory] which allows [NetworkResponse] objects to be | |
* returned from RxJava streams created by Retrofit. | |
* | |
* Adding this class to [Retrofit] allows you to write service methods like: | |
* | |
* fun getTokens(): Single<NetworkResponse<AccessToken,Error>> | |
*/ | |
class KotlinRxJava2CallAdapterFactory : CallAdapter.Factory() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authApi.getTokens() | |
.subscribe { response : NetworkResponse<AccessToken, Error> -> | |
when (response) { | |
is NetworkResponse.Success<AccessToken> -> { | |
// A 2XX response that's guaranteed to have a body of type AccessToken. | |
} | |
is NetworkResponse.ServerError<Error> -> { | |
// A non-2XX response that may have an Error as its error body. | |
} | |
is NetworkResponse.NetworkError -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2019 Coinbase, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Decorates stream emissions from [delegateAdapter] in [CoinbaseResponse]. | |
*/ | |
internal class CoinbaseRxJava2CallAdapter( | |
private val successBodyType: Type, | |
private val delegateAdapter: CallAdapter<Any, Any>, | |
private val errorConverter: Converter<ResponseBody, Any?>, | |
private val supportedType: SupportedType<Any, Any> | |
) : CallAdapter<Any, Any> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A [CallAdapter.Factory] which allows [CoinbaseResponse] objects to be | |
* returned from RxJava streams. For the type | |
* [Observable<CoinbaseResponse<SuccessBody, ErrorBody>>], the following | |
* semantics are provided: | |
* | |
* 1. 2xx responses call onNext with the deserialized body set as | |
* [CoinbaseResponse.body] | |
* 2. non-2xx responses call onNext with the deserialized error body set as | |
* [CoinbaseResponse.errorBody] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A response from the Coinbase API. | |
* | |
* In the event that a 2xx is returned [isSuccessful] will be set to true | |
* and [body] will be set. | |
* In the event that a non-2xx response is returned [isSuccessful] will be | |
* set to false and [errorBody] will be set. | |
* In the event that a request did not result in a response from the monorail | |
* [networkError] will be set. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class CoinbaseRxJavaCallAdapter( | |
private val successBodyType: Type, | |
private val delegateAdapter: CallAdapter<Any, Any>, | |
private val errorConverterFactory: Converter<ResponseBody, Any?>, | |
private val isObservable: Boolean, | |
private val isFlowable: Boolean, | |
private val isSingle: Boolean, | |
private val isMaybe: Boolean | |
) : CallAdapter<Any, Any> { |