source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
somleng/somleng
https://github.com/somleng/somleng
app/jobs/per_minute_job.rb
Ruby
mit
95
develop
537
class PerMinuteJob < ApplicationJob queue_as AppSettings.fetch(:aws_sqs_low_priority_queue_name) def perform ExecuteWorkflowJob.perform_later(ProcessOutboundCallsQueue.to_s) ExecuteWorkflowJob.perform_later(PublishOutboundCallsQueueMetrics.to_s) ExecuteWorkflowJob.perform_later(FailSendingMessages.to_s...
github
somleng/somleng
https://github.com/somleng/somleng
app/jobs/update_live_call_job.rb
Ruby
mit
95
develop
915
class UpdateLiveCallJob < ApplicationJob self.queue_adapter = :async class RetryJob < StandardError; end def perform(phone_call, call_service_client: CallService::Client.new) response = if phone_call.user_terminated? call_service_client.end_call( id: phone_call.external_id, host: phone...
github
somleng/somleng
https://github.com/somleng/somleng
app/jobs/create_phone_call_event_job.rb
Ruby
mit
95
develop
1,221
class CreatePhoneCallEventJob < ApplicationJob class Handler class PhoneCallNotFoundError < StandardError; end class InvalidStateTransitionError < StandardError; end attr_reader :phone_call_external_id, :params def initialize(phone_call_external_id:, **params) @phone_call_external_id = phone_c...
github
somleng/somleng
https://github.com/somleng/somleng
app/jobs/outbound_call_job.rb
Ruby
mit
95
develop
2,274
class OutboundCallJob < ApplicationJob class SessionLimitExceededError < StandardError; end queue_as AppSettings.fetch(:aws_sqs_outbound_calls_queue_name) class Handler attr_reader :account, :queue, :rate_limiters, :session_limiters, :logger def initialize(account, **options) @account = account ...
github
somleng/somleng
https://github.com/somleng/somleng
app/jobs/scheduler_job.rb
Ruby
mit
95
develop
363
class SchedulerJob include Shoryuken::Worker shoryuken_options( queue: AppSettings.fetch(:aws_sqs_scheduler_queue_name), auto_delete: true, body_parser: :json ) def perform(_sqs_message, params) job_class = params.fetch("job_class") Shoryuken.logger.info("Performing #{job_class}") job...
github
somleng/somleng
https://github.com/somleng/somleng
app/jobs/hourly_job.rb
Ruby
mit
95
develop
327
class HourlyJob < ApplicationJob queue_as AppSettings.fetch(:aws_sqs_low_priority_queue_name) def perform ExecuteWorkflowJob.perform_later(ExpireInitiatingPhoneCalls.to_s) ExecuteWorkflowJob.perform_later(RevokeSIPTrunkPermissions.to_s) ExecuteWorkflowJob.perform_later(RescheduleOutboundCalls.to_s) e...
github
somleng/somleng
https://github.com/somleng/somleng
app/types/phone_number_type.rb
Ruby
mit
95
develop
1,629
class PhoneNumberType < ActiveRecord::Type::String AREA_CODE_COUNTRY_PREFIXES = [ "1" ].freeze PhoneNumber = Struct.new(:value, :country_code, :area_code, :e164, :sip, :sip_address, keyword_init: true) do def to_s value end def e164? e164 end def sip? sip end def ==...
github
somleng/somleng
https://github.com/somleng/somleng
app/types/sha256_type.rb
Ruby
mit
95
develop
553
require "digest" class SHA256Type < ActiveRecord::Type::String SHA256Digest = Struct.new(:value, :digest, keyword_init: true) do def initialize(value: nil, digest: nil) super self.digest ||= Digest::SHA256.hexdigest(value) end def to_s digest end end def cast(value) return...
github
somleng/somleng
https://github.com/somleng/somleng
app/types/form_collection_type.rb
Ruby
mit
95
develop
740
class FormCollectionType < ActiveRecord::Type::Value attr_reader :form, :reject_if def initialize(form:, reject_if: nil, **) @form = form @reject_if = reject_if super(**) end def cast(value) return value if value.is_a?(FormCollection) items = if value.is_a?(Hash) value.values.any? {...
github
somleng/somleng
https://github.com/somleng/somleng
app/types/tts_voice_type.rb
Ruby
mit
95
develop
256
class TTSVoiceType < ActiveRecord::Type::String def cast(value) return if value.blank? value.is_a?(TTSVoices::Voice) ? value : TTSVoices::Voice.find(value) end def serialize(value) return if value.blank? value.identifier end end
github
somleng/somleng
https://github.com/somleng/somleng
app/types/tariff_schedule_category_type.rb
Ruby
mit
95
develop
1,718
class TariffScheduleCategoryType < ActiveRecord::Type::String TariffScheduleCategory = Data.define(:value, :tariff_category, :rate_unit, :type, :description, :direction, :diagram_direction_symbol, :diagram_category) do delegate :to_s, :to_sym, to: :value end def cast(value) return value if value.is_a?(Ta...
github
somleng/somleng
https://github.com/somleng/somleng
app/types/region_type.rb
Ruby
mit
95
develop
263
class RegionType < ActiveRecord::Type::String def cast(value) return if value.blank? return value if value.is_a?(SomlengRegion::Region) SomlengRegion::Region.find_by(alias: value.to_s) end def serialize(value) cast(value)&.alias end end
github
somleng/somleng
https://github.com/somleng/somleng
app/types/ip_address_array_type.rb
Ruby
mit
95
develop
202
class IPAddressArrayType < ActiveRecord::Type::String def cast(value) return [] if value.blank? Array(value).select { |ip| ip.is_a?(IPAddr) || Resolv::IPv4::Regex.match?(ip) }.uniq end end
github
somleng/somleng
https://github.com/somleng/somleng
app/types/currency_type.rb
Ruby
mit
95
develop
280
class CurrencyType < ActiveRecord::Type::String def cast(value) return if value.blank? value.is_a?(Money::Currency) ? value : Money::Currency.new(value) rescue Money::Currency::UnknownCurrency nil end def serialize(value) cast(value)&.iso_code end end
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/notify_sms_gateway_down.rb
Ruby
mit
95
develop
384
class NotifySMSGatewayDown < ApplicationWorkflow attr_reader :sms_gateway def initialize(sms_gateway) @sms_gateway = sms_gateway end def call return if sms_gateway.connected? CreateErrorLog.call( type: :sms_gateway_disconnect, carrier: sms_gateway.carrier, error_message: "SMS Ga...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_call_service_capacity.rb
Ruby
mit
95
develop
417
class UpdateCallServiceCapacity < ApplicationWorkflow attr_reader :region, :capacity, :call_service_capacity def initialize(params, **options) super(**options) @region = params.fetch(:region) @capacity = params.fetch(:capacity) @call_service_capacity = options.fetch(:call_service_capacity) { CallSe...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_message.rb
Ruby
mit
95
develop
437
class UpdateMessage < ApplicationWorkflow attr_reader :message, :params def initialize(message, params = {}) super() @message = message @params = params end def call RedactMessage.call(message) if redact? UpdateMessageStatus.new(message).call { message.cancel! } if cancel? message en...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_phone_calls_from_outbound_dial.rb
Ruby
mit
95
develop
1,325
class CreatePhoneCallsFromOutboundDial < ApplicationWorkflow attr_reader :parent_call, :from, :incoming_phone_number, :destinations, :session_limiters def initialize(params, **options) super() @parent_call = params.fetch(:parent_call) @from = params.fetch(:from) @incoming_phone_number = params.fetc...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/schedule_outbound_call.rb
Ruby
mit
95
develop
410
class ScheduleOutboundCall < ApplicationWorkflow attr_reader :phone_call, :queue def initialize(phone_call, **options) super() @phone_call = phone_call @queue = options.fetch(:queue) { OutboundCallsQueue.new(account) } end def call return unless queue.enqueue(phone_call.id) OutboundCallJo...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/delete_sip_trunk.rb
Ruby
mit
95
develop
452
class DeleteSIPTrunk < ApplicationWorkflow attr_reader :sip_trunk, :call_service_client delegate :username, to: :sip_trunk def initialize(sip_trunk, **options) @sip_trunk = sip_trunk @call_service_client = options.fetch(:call_service_client) { CallService::Client.new } end def call delete_subsc...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_tariff_package_wizard_form.rb
Ruby
mit
95
develop
721
class CreateTariffPackageWizardForm < ApplicationWorkflow attr_reader :resource, :client def initialize(resource, **options) super() @resource = resource @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do return unless resource.save ...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/queue_outbound_message.rb
Ruby
mit
95
develop
1,252
class QueueOutboundMessage < ApplicationWorkflow class MessagingServiceError < StandardError def code message.to_sym end end attr_reader :message def initialize(message) super() @message = message end def call message.transaction do resolve_sender if message.phone_number.b...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_balance_transaction_charge_source.rb
Ruby
mit
95
develop
517
class UpdateBalanceTransactionChargeSource < ApplicationWorkflow attr_reader :balance_transaction def initialize(balance_transaction) super() @balance_transaction = balance_transaction end def call return if charge_source.price.present? charge_source.update_columns( price_cents: balance...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_message.rb
Ruby
mit
95
develop
810
class CreateMessage < ApplicationWorkflow attr_reader :params def initialize(params = {}) super() @params = params end def call message = Message.create!(params) process_message(message) message end private def process_message(message) if message.queued? send_message(mess...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/destroy_tariff_plan.rb
Ruby
mit
95
develop
431
class DestroyTariffPlan < ApplicationWorkflow attr_reader :tariff_plan, :client def initialize(tariff_plan, **options) super() @tariff_plan = tariff_plan @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do tariff_plan.destroy cl...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_account.rb
Ruby
mit
95
develop
371
class CreateAccount < ApplicationWorkflow attr_reader :params, :client def initialize(params, **options) super() @params = params @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do account = Account.create!(params) client.upser...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/process_recording.rb
Ruby
mit
95
develop
1,366
require "open3" class ProcessRecording < ApplicationWorkflow attr_reader :recording, :s3_client def initialize(recording, s3_client: Aws::S3::Client.new) @recording = recording @s3_client = s3_client end def call Tempfile.create([recording.id, ".wav"]) do |raw_file| download_raw_recording_f...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/send_outbound_message.rb
Ruby
mit
95
develop
945
class SendOutboundMessage < ApplicationWorkflow attr_reader :message, :channel def initialize(message, **options) super() @message = message @channel = options.fetch(:channel) { SMSMessageChannel } end def call return unless message.queued? return mark_as_failed(:validity_period_expired) i...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_destination_group_form.rb
Ruby
mit
95
develop
373
class UpdateDestinationGroupForm < ApplicationWorkflow attr_reader :resource, :client def initialize(resource, **options) super() @resource = resource @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do client.upsert_destination_group...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_tariff_package_plan_with_defaults.rb
Ruby
mit
95
develop
1,303
class CreateTariffPackagePlanWithDefaults < ApplicationWorkflow attr_reader :package, :category, :rate delegate :carrier, :name, to: :package, private: true def initialize(package:, category:, rate:) super() @package = package @category = category @rate = rate end def call plan = create...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/handle_call_heartbeats.rb
Ruby
mit
95
develop
267
class HandleCallHeartbeats < ApplicationWorkflow attr_reader :call_ids def initialize(call_ids) super() @call_ids = call_ids end def call PhoneCall .where(external_id: call_ids) .update_all(last_heartbeat_at: Time.current) end end
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/fail_sending_messages.rb
Ruby
mit
95
develop
227
class FailSendingMessages < ApplicationWorkflow def call Message.sending.where(sending_at: ..5.minutes.ago).find_each do |message| UpdateMessageStatus.new(message).call { message.mark_as_failed! } end end end
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/destroy_account.rb
Ruby
mit
95
develop
483
class DestroyAccount < ApplicationWorkflow attr_reader :account, :client def initialize(account, **options) super() @account = account @client = options.fetch(:client) { RatingEngineClient.new } end def call destroy_account end private def destroy_account ApplicationRecord.transact...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_phone_call.rb
Ruby
mit
95
develop
258
class CreatePhoneCall < ApplicationWorkflow attr_reader :params def initialize(params = {}) super() @params = params end def call phone_call = PhoneCall.create!(params) ScheduleOutboundCall.call(phone_call) phone_call end end
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_verification.rb
Ruby
mit
95
develop
2,510
class CreateVerification < ApplicationWorkflow class Error < StandardError; end attr_reader :params def initialize(params) super() @params = params end def call ApplicationRecord.transaction do verification = create_or_update_verification! delivery_attempt = create_delivery_attempt!...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/publish_interaction_data.rb
Ruby
mit
95
develop
1,301
require "csv" class PublishInteractionData < ApplicationWorkflow attr_reader :api_key, :chart_id def initialize(**options) super() @api_key = options.fetch(:api_key) { AppSettings[:datawrapper_api_key] } @chart_id = options.fetch(:chart_id) { AppSettings[:datawrapper_chart_id] } end def call ...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_event.rb
Ruby
mit
95
develop
670
class CreateEvent < ApplicationWorkflow attr_reader :eventable, :type, :event def initialize(eventable:, type:) super() @eventable = eventable @type = type end def call create_event notify_webhook if carrier.webhooks_enabled? event end private def create_event @event = Even...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/execute_messaging_twiml.rb
Ruby
mit
95
develop
2,046
class ExecuteMessagingTwiML < ApplicationWorkflow class Error < StandardError; end SLEEP_BETWEEN_REDIRECTS = 1 attr_reader :message, :url, :http_method, :twiml_parser, :error_message def initialize(options) @message = options.fetch(:message) @url = options.fetch(:url) @http_method = options.fetch...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/resolve_phone_number_country.rb
Ruby
mit
95
develop
599
class ResolvePhoneNumberCountry < ApplicationWorkflow FALLBACK_COUNTRIES = %w[US AU NF FI NO MA FK GB IT RU NZ RE].freeze attr_reader :phone_number, :fallback_country def initialize(phone_number, fallback_country:) @phone_number = phone_number @fallback_country = fallback_country end def call r...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/destroy_tariff_schedule.rb
Ruby
mit
95
develop
471
class DestroyTariffSchedule < ApplicationWorkflow attr_reader :tariff_schedule, :client def initialize(tariff_schedule, **options) super() @tariff_schedule = tariff_schedule @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do tariff_s...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_phone_call.rb
Ruby
mit
95
develop
948
class UpdatePhoneCall < ApplicationWorkflow attr_reader :phone_call, :client, :params def initialize(phone_call, client: UpdateLiveCallJob, **params) super() @phone_call = phone_call @client = client @params = params end def call return unless phone_call.uncompleted? params[:status].p...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_tariff_schedule_form.rb
Ruby
mit
95
develop
369
class UpdateTariffScheduleForm < ApplicationWorkflow attr_reader :resource, :client def initialize(resource, **options) super() @resource = resource @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do client.upsert_tariff_schedule(res...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/notify_recording_status_callback.rb
Ruby
mit
95
develop
536
class NotifyRecordingStatusCallback < ApplicationWorkflow attr_reader :recording def initialize(recording) @recording = recording end def call TwilioAPI::NotifyWebhook.call( account: recording.phone_call.account, url: recording.status_callback_url, http_method: recording.status_callb...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_message_status.rb
Ruby
mit
95
develop
963
class UpdateMessageStatus < ApplicationWorkflow CALLBACK_STATES = %w[queued canceled failed sent delivered].freeze attr_reader :message def initialize(message) super() @message = message end def call(&) message.transaction do yield(message) RedactMessage.call(message) if redact? ...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_account_balance_form.rb
Ruby
mit
95
develop
369
class UpdateAccountBalanceForm < ApplicationWorkflow attr_reader :resource, :client def initialize(resource, **options) super() @resource = resource @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do client.update_account_balance(res...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_sip_trunk.rb
Ruby
mit
95
develop
829
class UpdateSIPTrunk < ApplicationWorkflow attr_reader :sip_trunk, :call_service_client delegate :region, :username, :password, :previous_changes, to: :sip_trunk def initialize(sip_trunk, **options) @sip_trunk = sip_trunk @call_service_client = options.fetch(:call_service_client) { CallService::Client.n...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/initiate_outbound_call.rb
Ruby
mit
95
develop
3,589
class InitiateOutboundCall < ApplicationWorkflow class Error < StandardError; end attr_reader :phone_call, :call_service_client, :session_limiters, :logger def initialize(**options) super() @phone_call = options.fetch(:phone_call) { PhoneCall.find(options.fetch(:phone_call_id)) } @call_service_clien...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/expire_in_progress_phone_calls.rb
Ruby
mit
95
develop
955
class ExpireInProgressPhoneCalls < ApplicationWorkflow attr_reader :session_limiters def initialize(**options) super() @session_limiters = options.fetch(:session_limiters) { [ AccountCallSessionLimiter.new, GlobalCallSessionLimiter.new ] } end def call stale_heartbeat = PhoneCall.in_progress.where...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_tariff_plan_form.rb
Ruby
mit
95
develop
361
class UpdateTariffPlanForm < ApplicationWorkflow attr_reader :resource, :client def initialize(resource, **options) super() @resource = resource @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do client.upsert_tariff_plan(resource.ob...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/export_csv.rb
Ruby
mit
95
develop
1,726
require "csv" class ExportCSV < ApplicationWorkflow include ActionView::Helpers::NumberHelper include ActionView::Helpers::TextHelper attr_reader :export def initialize(export) @export = export end def call Tempfile.open do |tmpfile| write_csv(tmpfile) attach_file(tmpfile) end ...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/update_account_form.rb
Ruby
mit
95
develop
354
class UpdateAccountForm < ApplicationWorkflow attr_reader :resource, :client def initialize(resource, **options) super() @resource = resource @client = options.fetch(:client) { RatingEngineClient.new } end def call ApplicationRecord.transaction do client.upsert_account(resource.object) i...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/publish_outbound_calls_queue_metrics.rb
Ruby
mit
95
develop
982
class PublishOutboundCallsQueueMetrics < ApplicationWorkflow attr_reader :logger, :call_service_capacity, :regions def initialize(**options) super() @logger = options.fetch(:logger) { Rails.logger } @call_service_capacity = options.fetch(:call_service_capacity) { CallServiceCapacity } @regions = op...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/process_outbound_calls_queue.rb
Ruby
mit
95
develop
272
class ProcessOutboundCallsQueue < ApplicationWorkflow def call OutboundCallsQueue.each_queue do |queue| queue.recover!(processing_longer_than: 1.minute.ago) [ queue.size, 60 ].min.times { OutboundCallJob.perform_later(queue.account) } end end end
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_sip_trunk.rb
Ruby
mit
95
develop
504
class CreateSIPTrunk < ApplicationWorkflow attr_reader :sip_trunk, :call_service_client delegate :inbound_source_ips, :region, :username, :password, to: :sip_trunk def initialize(sip_trunk, **options) @sip_trunk = sip_trunk @call_service_client = options.fetch(:call_service_client) { CallService::Client...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/notify_webhook_endpoint.rb
Ruby
mit
95
develop
2,268
class NotifyWebhookEndpoint < ApplicationWorkflow MAX_ATTEMPTS = 9 RETRY_PERIOD = 5.days attr_accessor :webhook_endpoint, :event def initialize(webhook_endpoint, event) self.webhook_endpoint = webhook_endpoint self.event = event end def call response = notify_webhook_endpoint webhook_req...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/delete_expired_carriers.rb
Ruby
mit
95
develop
458
class DeleteExpiredCarriers < ApplicationWorkflow def call expired_users.each do |expired_user| next unless expired_user.carrier.carrier_users.one? expired_user.destroy! expired_user.carrier.destroy! end end private def expired_users User .where(carrier_role: :owner) .wh...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/import_csv.rb
Ruby
mit
95
develop
782
require "csv" class ImportCSV < ApplicationWorkflow attr_reader :import def initialize(import) @import = import end def call import_csv rescue Errors::ImportError => e import.error_message = "Line #{import.error_line}: #{e.message}" import.fail! end private def import_csv import...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_phone_number_plan.rb
Ruby
mit
95
develop
1,129
class CreatePhoneNumberPlan < ApplicationWorkflow attr_reader :phone_number, :account, :amount, :configuration, :phone_number_formatter def initialize(phone_number:, account:, **configuration) @phone_number = phone_number @account = account @amount = configuration.delete(:amount) @phone_number_form...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/process_media_stream_event.rb
Ruby
mit
95
develop
432
class ProcessMediaStreamEvent < ApplicationWorkflow attr_reader :event, :media_stream def initialize(event) @event = event @media_stream = event.media_stream end def call case event.type when "connect" media_stream.connect! when "start" media_stream.start! when "disconnect"...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/import_phone_number.rb
Ruby
mit
95
develop
2,643
class ImportPhoneNumber < ApplicationWorkflow attr_reader :import, :data class Error < Errors::ImportError; end def initialize(import:, data:) @import = import @data = data.with_indifferent_access end def call marked_for_deletion? ? delete_phone_number! : create_phone_number! end private ...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/refresh_carrier_rates.rb
Ruby
mit
95
develop
347
class RefreshCarrierRates < ApplicationWorkflow attr_reader :client def initialize(**options) super() @client = options.fetch(:client) { RatingEngineClient.new } end def call Carrier.joins(:accounts).merge(Account.billing_enabled).distinct.find_each do |carrier| client.refresh_carrier_rates(...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_error_log.rb
Ruby
mit
95
develop
1,118
class CreateErrorLog < ApplicationWorkflow attr_reader :params def initialize(params) @params = params end def call ErrorLog.transaction do error_log = create_error_log notify_subscribed_recipients(error_log) error_log end end private def create_error_log ErrorLog.cre...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_inbound_message.rb
Ruby
mit
95
develop
1,287
class CreateInboundMessage < ApplicationWorkflow attr_reader :params def initialize(params) super() @params = params end def call return if drop_message? message = nil ApplicationRecord.transaction do message = Message.create!(params) create_interaction(message) CreateM...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_message_charge.rb
Ruby
mit
95
develop
1,353
class CreateMessageCharge < ApplicationWorkflow class Error < StandardError attr_reader :record def initialize(message, record:) super(message) @record = record end end class CreditValidator def sufficient_balance?(...) true end end attr_reader :message, :client, :acco...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/create_inbound_phone_call.rb
Ruby
mit
95
develop
774
class CreateInboundPhoneCall < ApplicationWorkflow attr_reader :params, :session_limiters def initialize(params, **options) super() @params = params @session_limiters = options.fetch(:session_limiters) { [ AccountCallSessionLimiter.new, GlobalCallSessionLimiter.new ] } end def call phone_call ...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/sync_rating_engine_transactions.rb
Ruby
mit
95
develop
2,362
class SyncRatingEngineTransactions < ApplicationWorkflow CDR = Data.define( :id, :origin_id, :category, :account, :amount, :message, :phone_call ) attr_reader :client, :batch_size, :cursor_start def initialize(**options) super() @client = options.fetch(:client) { RatingEngi...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/reschedule_outbound_calls.rb
Ruby
mit
95
develop
360
class RescheduleOutboundCalls < ApplicationWorkflow attr_reader :workflow def initialize(workflow: ScheduleOutboundCall) super() @workflow = workflow end def call PhoneCall.queued.where(created_at: ..30.minutes.ago, initiation_queued_at: nil).includes(:account).find_each do |phone_call| work...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/onboard_carrier.rb
Ruby
mit
95
develop
1,611
class OnboardCarrier < ApplicationWorkflow attr_reader :name, :country_code, :owner_params, :restricted, :website, :subdomain, :billing_currency, :rating_engine_client def initialize(**params) super() @name = params.fetch(:name) @country_code = params.fetch(:country_code) @restricted = params.fetch...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/check_verification_code.rb
Ruby
mit
95
develop
552
class CheckVerificationCode < ApplicationWorkflow attr_reader :verification, :code def initialize(verification:, code:) @verification = verification @code = code end def call ApplicationRecord.transaction do verification_attempt = create_verification_attempt approve_verification if ver...
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/get_account_balance.rb
Ruby
mit
95
develop
279
class GetAccountBalance < ApplicationWorkflow attr_reader :account, :client def initialize(account, **options) super() @account = account @client = options.fetch(:client) { RatingEngineClient.new } end def call client.account_balance(account) end end
github
somleng/somleng
https://github.com/somleng/somleng
app/workflows/twilio_api/notify_webhook.rb
Ruby
mit
95
develop
1,663
module TwilioAPI class NotifyWebhook < ApplicationWorkflow HTTP_METHODS = { "GET" => :get, "POST" => :post }.freeze attr_reader :account, :url, :http_method, :params def initialize(account:, url:, http_method:, params:) super() @account = account @url = url @http_...
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/email_uniqueness_validator.rb
Ruby
mit
95
develop
228
class EmailUniquenessValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return unless User.exists?(email: value) record.errors.add(attribute, options.fetch(:message, :taken)) end end
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/country_subdivision_validator.rb
Ruby
mit
95
develop
432
class CountrySubdivisionValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return if value.blank? country = ISO3166::Country.new(options.fetch(:country_code).call(record)) return record.errors.add(options.fetch(:country_attribute, :country), :blank) if country.blank? r...
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/phone_number_type_validator.rb
Ruby
mit
95
develop
366
class PhoneNumberTypeValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return record.errors.add(attribute, :blank) if value.blank? return if record.number.blank? return if value.to_sym.in?(record.number.e164? ? PhoneNumber::E164_TYPES : PhoneNumber::NON_164_TYPES) rec...
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/email_format_validator.rb
Ruby
mit
95
develop
223
class EmailFormatValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return if value =~ User::EMAIL_FORMAT record.errors.add(attribute, options.fetch(:message, :invalid)) end end
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/subdomain_validator.rb
Ruby
mit
95
develop
454
class SubdomainValidator < ActiveModel::EachValidator MIN_LENGTH = 3 def validate_each(record, attribute, value) return record.errors.add(attribute, :blank) if value.blank? return record.errors.add(attribute, :too_short, count: MIN_LENGTH) if value.length < MIN_LENGTH scope = options.fetch(:scope) { -...
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/lata_validator.rb
Ruby
mit
95
develop
241
class LATAValidator < ActiveModel::EachValidator FORMAT = /\A[1-9]{1}\d{2}\z/ def validate_each(record, attribute, value) return if FORMAT.match?(value) record.errors.add(attribute, options.fetch(:message, :invalid)) end end
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/phone_number_country_validator.rb
Ruby
mit
95
develop
342
class PhoneNumberCountryValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return record.errors.add(attribute, :blank) if value.blank? return if record.number.blank? return if ISO3166::Country.new(value).in?(record.number.possible_countries) record.errors.add(attribute...
github
somleng/somleng
https://github.com/somleng/somleng
app/validators/url_format_validator.rb
Ruby
mit
95
develop
289
class URLFormatValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) validator = options.fetch(:validator) { URLValidator.new(options) } return if validator.valid?(value) record.errors.add(attribute, options.fetch(:message, :invalid)) end end
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/phone_number_form.rb
Ruby
mit
95
develop
3,779
class PhoneNumberForm include ActiveModel::Model include ActiveModel::Attributes extend Enumerize VISIBILITIES = { private: "Private <div class='form-text'>Only available for private use within your organization.</div>", public: "Public <div class='form-text'>Available for private use within your orga...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/carrier_form.rb
Ruby
mit
95
develop
1,747
class CarrierForm include ActiveModel::Model include ActiveModel::Attributes COUNTRIES = ISO3166::Country.all.map(&:alpha2).freeze CURRENCIES = ISO3166::Country.all.map { |country| Money::Currency.new(country.currency_code) if Money::Currency.find(country.currency_code) }.reject(&:blank?).uniq.freeze attrib...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/account_membership_form.rb
Ruby
mit
95
develop
1,748
class AccountMembershipForm include ActiveModel::Model include ActiveModel::Attributes extend Enumerize enumerize :role, in: AccountMembership.role.values attribute :account attribute :name attribute :email attribute :role, default: :admin attribute :current_user attribute :account_membership, de...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/balance_transaction_form.rb
Ruby
mit
95
develop
1,657
class BalanceTransactionForm < ApplicationForm attribute :object, default: -> { BalanceTransaction.new } attribute :carrier attribute :account_id attribute :type attribute :amount, :decimal attribute :description attribute :created_by enumerize :type, in: [ :topup, :adjustment ] delegate :new_record...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/sip_trunk_form.rb
Ruby
mit
95
develop
3,108
require "resolv" class SIPTrunkForm include ActiveModel::Model include ActiveModel::Attributes extend Enumerize DIAL_STRING_PREFIX_FORMAT = /\A\d+\z/ COUNTRIES = ISO3166::Country.all.map(&:alpha2).freeze attribute :carrier attribute :sip_trunk, default: -> { SIPTrunk.new } attribute :name attribut...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/account_settings_form.rb
Ruby
mit
95
develop
657
class AccountSettingsForm include ActiveModel::Model include ActiveModel::Attributes attribute :name attribute :account attribute :default_tts_voice, TTSVoiceType.new delegate :persisted?, :id, to: :account validates :name, :default_tts_voice, presence: true def self.model_name ActiveModel::Name...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/sms_gateway_channel_group_form.rb
Ruby
mit
95
develop
2,596
class SMSGatewayChannelGroupForm class IntegerArrayType < ActiveRecord::Type::String def cast(value) Array(value).reject(&:blank?).map(&:to_i) end end include ActiveModel::Model include ActiveModel::Attributes attribute :carrier attribute :channel_group, default: -> { SMSGatewayChannelGroup....
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/forgot_subdomain_form.rb
Ruby
mit
95
develop
592
class ForgotSubdomainForm include ActiveModel::Model include ActiveModel::Attributes attribute :email validates :email, presence: true validate :validate_email_exists def self.model_name ActiveModel::Name.new(self, nil, "User") end def save return false if invalid? carriers = Carrier.jo...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/user_form.rb
Ruby
mit
95
develop
1,002
class UserForm include ActiveModel::Model include ActiveModel::Attributes extend Enumerize attribute :name attribute :email attribute :role attribute :user, default: -> { User.new } attribute :carrier attribute :inviter enumerize :role, in: User.carrier_role.values, presence: true validates :na...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/two_factor_authentication_form.rb
Ruby
mit
95
develop
613
class TwoFactorAuthenticationForm include ActiveModel::Model include ActiveModel::Attributes attribute :user attribute :otp_attempt validates :otp_attempt, presence: true validate :validate_otp_attempt def self.model_name ActiveModel::Name.new(self, nil, "TwoFactorAuthentication") end def pers...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/tariff_plan_subscription_form.rb
Ruby
mit
95
develop
437
class TariffPlanSubscriptionForm < TariffPlanAssignmentForm attribute :account attribute :object, default: -> { TariffPlanSubscription.new } delegate :carrier, to: :account def self.model_name ActiveModel::Name.new(self, nil, "TariffPlanSubscription") end def self.initialize_with(object) form = s...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/form_collection.rb
Ruby
mit
95
develop
243
class FormCollection include Enumerable delegate :[], :each, :find, :first, :last, :empty?, :size, :count, to: :@items def initialize(items, form:) @items = items.map { |item| item.is_a?(form) ? item : form.new(**item) } end end
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/tariff_package_tariff_form.rb
Ruby
mit
95
develop
1,384
class TariffPackageTariffForm < ApplicationForm attribute :parent_form attribute :package attribute :rate, :decimal attribute :enabled, :boolean attribute :category delegate :carrier, :name, to: :parent_form delegate :billing_currency, to: :carrier enumerize :category, in: TariffSchedule.category.valu...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/tariff_package_wizard_form.rb
Ruby
mit
95
develop
1,609
class TariffPackageWizardForm < ApplicationForm attribute :object, default: -> { TariffPackage.new } attribute :carrier attribute :name attribute :description attribute :tariffs, FormCollectionType.new(form: TariffPackageTariffForm), default: [] validates :name, presence: true validate :validate_name ...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/multi_select_form_component.rb
Ruby
mit
95
develop
566
class MultiSelectFormComponent attr_reader :selected_values, :available_values, :existing_values def initialize(selected_values:, available_values:, existing_values:) @selected_values = selected_values @available_values = available_values @existing_values = existing_values end def valid? (sele...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/notification_preferences_form.rb
Ruby
mit
95
develop
1,159
class NotificationPreferencesForm NotificationTopic = Struct.new(:name, :category, keyword_init: true) do def self.parse(value) category, name = value.split(".", 2) new(category:, name:) end def identifier "#{category}.#{name}" end end include ActiveModel::Model include Activ...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/tariff_schedule_form.rb
Ruby
mit
95
develop
2,701
class TariffScheduleForm < ApplicationForm attribute :carrier attribute :category attribute :object, default: -> { TariffSchedule.new } attribute :name attribute :description attribute :destination_tariffs, FormCollectionType.new(form: DestinationTariffForm), default: [] enumerize...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/verification_service_form.rb
Ruby
mit
95
develop
2,016
class VerificationServiceForm include ActiveModel::Model include ActiveModel::Attributes extend Enumerize attribute :carrier attribute :friendly_name attribute :code_length, default: -> { VerificationService::DEFAULT_CODE_LENGTH } attribute :account_id attribute :account attribute :verification_servi...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/account_form.rb
Ruby
mit
95
develop
5,777
class AccountForm < ApplicationForm attribute :carrier attribute :name attribute :enabled, :boolean, default: true attribute :billing_enabled, :boolean attribute :billing_mode attribute :object, default: -> { Account.new(type: :carrier_managed, access_token: Doorkeeper::AccessToken.new) } attribute :sip_t...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/tariff_plan_tier_form.rb
Ruby
mit
95
develop
1,709
class TariffPlanTierForm < ApplicationForm attribute :object, default: -> { TariffPlanTier.new } attribute :id attribute :_destroy, :boolean, default: false attribute :tariff_plan attribute :tariff_schedule_id attribute :weight, :decimal, default: -> { TariffPlanTier::DEFAULT_WEIGHT } validates :tariff_s...
github
somleng/somleng
https://github.com/somleng/somleng
app/forms/tariff_package_form.rb
Ruby
mit
95
develop
2,188
class TariffPackageForm < ApplicationForm attribute :carrier attribute :object, default: -> { TariffPackage.new } attribute :name attribute :description attribute :plans, FormCollectionType.new(form: TariffPackagePlanForm), default: [] validates :name, presence: true validate :val...