Skip to content

Instantly share code, notes, and snippets.

View naturalwarren's full-sized avatar
🎯
Focusing

Warren Smith naturalwarren

🎯
Focusing
View GitHub Profile
@naturalwarren
naturalwarren / AccessTokenAuthenticator.kt
Last active October 30, 2023 15:14
An OkHttp Authenticator that performs token refreshes.
/**
* Authenticator that attempts to refresh the client's access token.
* In the event that a refresh fails and a new token can't be issued an error
* is delivered to the caller. This authenticator blocks all requests while a token
* refresh is being performed. In-flight requests that fail with a 401 are
* automatically retried.
*/
class AccessTokenAuthenticator(
private val tokenProvider: AccessTokenProvider
) : Authenticator {
@naturalwarren
naturalwarren / DataRow+ViewModelConvertible.swift
Last active April 19, 2023 00:19
DataRow+ViewModelConvertible
extension DataRow: ViewModelConvertible {
func viewModel(context: SDUIContext) -> some ViewModel {
return DataRowViewModel(
title: self.title,
titleURL: self.titleHyperlink,
subtitle: self.subtitle,
layout: self.layout.toNativeLayout(),
accessory: accessoryView?.viewModel(context: context)
)
}
@naturalwarren
naturalwarren / DataRow.swift
Last active April 18, 2023 23:31
Generated SDUIDataRow
public struct DataRow: Codable, Equatable {
public let title: String
public let subtitle: String
public let layout: Layout
public let titleHyperlink: URL?
public let accessoryView: SDUIComponent?
public enum Layout: String {
case vertical = "VERTICAL"
@naturalwarren
naturalwarren / DataRow.py
Last active April 18, 2023 23:13
Augmented SDUI DataRow
class DataRow(UIComponent):
title: str
subtitle: str
layout: Layout = Layout.HORIZONTAL
title_hyperlink: Optional[Url] = None
accessory_view = Optional[UIComponent] = None
@classmethod
def component_type(cls) -> ComponentType:
return ComponentType.DATA_ROW_STACKED
@naturalwarren
naturalwarren / DataRow.py
Last active April 18, 2023 23:05
SDUI DataRow Type
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):
@naturalwarren
naturalwarren / ViewModel.swift
Created April 8, 2023 19:33
SDUI viewModel function
func viewModel(context: SDUIContext) -> ViewModel
@naturalwarren
naturalwarren / Action.py
Created April 8, 2023 19:32
SDUI Action
class Action(BaseModel, ABC):
sdui_action_type: ActionType
def __init__(self, **data) -> None:
data['sdui_action_type'] = self.action_type()
super().__init__(**data)
@classmethod
@abstractmethod
def action_type(cls) -> ActionType:
@naturalwarren
naturalwarren / SDUIComponent.swift
Created April 8, 2023 19:31
SDUIComponent Helper
extension SDUIComponent {
private var concreteModel: Any {
switch self {
case .button(let button):
return button
case .row(let row):
return row
case .text(let text):
return text
}
@naturalwarren
naturalwarren / SDUIComponent.ts
Created April 8, 2023 19:28
TypeScript SDUIComponent
SDUIComponent = SDUIButton | SDUIRow | SDUIText
@naturalwarren
naturalwarren / SDUIComponent.kt
Created April 8, 2023 19:27
Kotlin SDUIComponent
sealed interface SDUIComponent
data class SDUIButton: SDUIComponent
data class SDUIRow: SDUIComponent
data class SDUIText: SDUIComponent