This file contains 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 DoorsStateController < ApplicationController | |
def toggle | |
event = Doors.toggle | |
render json: { | |
status: 'success', | |
body: event | |
} | |
end | |
def read |
This file contains 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
module Firebase | |
class PushToAndroid | |
SERVER_KEY = ENV.fetch('FIREBASE_APP_SERVER_KEY') | |
def call | |
registration_ids = User.all.map(&:registration_id) | |
options = { data: { state: Doors.last_event.attributes }, collapse_key: 'updated_score' } | |
fcm = FCM.new(SERVER_KEY) | |
fcm.send(registration_ids, options) | |
end | |
end |
This file contains 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
module Slack | |
class MessageReceivedEventHandler | |
attr_reader :message | |
def initialize(message) | |
@message = message | |
end | |
def handle | |
if message_implicate_that_doors_were_just_opened? | |
Doors.open! |
This file contains 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
<receiver android:name=".widget.LockWidgetProvider"> | |
<intent-filter> | |
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> | |
</intent-filter> | |
<meta-data android:name="android.appwidget.provider" | |
android:resource="@xml/appwidget_info"/> | |
</receiver> |
This file contains 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
open class LockWidgetProvider : AppWidgetProvider() { | |
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { | |
for (id in appWidgetIds) { | |
appWidgetManager.updateAppWidget(id, createLockRemoteViews(context, AppCache.lockState)) | |
} | |
} | |
override fun onReceive(context: Context, intent: Intent) { | |
super.onReceive(context, intent) |
This file contains 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 LockWidgetJobService : JobIntentService() { | |
companion object { | |
... | |
private val SUPPORTED_ACTIONS = listOf(ACTION_TOGGLE, ACTION_REFRESH) | |
fun handleAction(context: Context, action: String?) { | |
if (!canHandle(action)) return |
This file contains 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 ApiClient private constructor(context: Context) { | |
val apiService = createApiService(context) | |
private fun createApiService(context: Context): ApiService { | |
return Retrofit.Builder() | |
.baseUrl(context.getString(R.string.api_base_url)) | |
.addConverterFactory(createConverterFactory()) | |
.client(createHttpClient(context)) | |
.build() |
This file contains 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
<service | |
android:name=".push.AppMessagingService"> | |
<intent-filter> | |
<action android:name="com.google.firebase.MESSAGING_EVENT"/> | |
</intent-filter> | |
</service> |
This file contains 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 AppMessagingService : FirebaseMessagingService() { | |
override fun onNewToken(token: String?) { | |
val registrationId = token ?: return | |
val userId = UUIDProvider.provide(this) // described later | |
// request push registration | |
} | |
override fun onMessageReceived(remoteMessage: RemoteMessage) { |
This file contains 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
object AppCache { | |
var lockState: LockState? = null | |
set(value) { | |
if (value == null) return | |
if (field == null || field!!.created_at.before(value.created_at)) { | |
field = value | |
} | |
} |