* Add fakeredis gem * Mock Pusher::PushNotifications in specs * Remove Redis from Travis * Add Android tests to ConsumerApp specs * Use mock for push notification tests and refactor ConsumerApp and Device code * Fix remaining broken specs * Use symbols * Cleanup rpush helpers * Pusher::PushNotifications is no more * Use human friendly platform in Admin::ConsumerApps index page
52 lines
1.3 KiB
Ruby
52 lines
1.3 KiB
Ruby
module ConsumerApps
|
|
class RpushAppQuery
|
|
def self.call(app_bundle:, platform:)
|
|
new(app_bundle: app_bundle, platform: platform).call
|
|
end
|
|
|
|
def initialize(app_bundle:, platform:)
|
|
@app_bundle = app_bundle
|
|
@platform = platform
|
|
|
|
@consumer_app = ConsumerApps::FindOrCreateByQuery.call(
|
|
app_bundle: @app_bundle,
|
|
platform: @platform,
|
|
)
|
|
end
|
|
|
|
def call
|
|
if consumer_app.android?
|
|
android_app = Rpush::Gcm::App.where(name: app_bundle).first
|
|
android_app || recreate_android_app!
|
|
elsif consumer_app.ios?
|
|
ios_app = Rpush::Apns2::App.where(name: app_bundle).first
|
|
ios_app || recreate_ios_app!
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :app_bundle, :consumer_app
|
|
|
|
def recreate_ios_app!
|
|
app = Rpush::Apns2::App.new
|
|
app.name = app_bundle
|
|
app.certificate = consumer_app.auth_credentials.to_s.gsub("\\n", "\n")
|
|
app.environment = Rails.env
|
|
app.password = ""
|
|
app.bundle_id = app_bundle
|
|
app.connections = 1
|
|
app.save!
|
|
app
|
|
end
|
|
|
|
def recreate_android_app!
|
|
app = Rpush::Gcm::App.new
|
|
app.name = app_bundle
|
|
app.auth_key = consumer_app.auth_credentials.to_s
|
|
app.connections = 1
|
|
app.save!
|
|
app
|
|
end
|
|
end
|
|
end
|