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/serializers/services/outbound_phone_call_serializer.rb | Ruby | mit | 95 | develop | 1,421 | module Services
class OutboundPhoneCallSerializer < ResourceSerializer
def serializable_hash(options = nil)
serializable_is_collection? ? hash_for_collection(options) : super
end
alias to_hash serializable_hash
def attributes
super.merge(
"sid" => nil,
"account_sid" => nil... |
github | somleng/somleng | https://github.com/somleng/somleng | app/serializers/services/inbound_phone_call_serializer.rb | Ruby | mit | 95 | develop | 982 | module Services
class InboundPhoneCallSerializer < ResourceSerializer
def attributes
super.merge(
"voice_url" => nil,
"voice_method" => nil,
"status_callback_url" => nil,
"status_callback_method" => nil,
"twiml" => nil,
"to" => nil,
"from" => nil,
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/serializers/services/request_errors_serializer.rb | Ruby | mit | 95 | develop | 220 | module Services
class RequestErrorsSerializer < ApplicationSerializer
def attributes
{
message: nil
}
end
def message
errors(full: true).map(&:text).to_sentence
end
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/serializers/services/resource_serializer.rb | Ruby | mit | 95 | develop | 397 | module Services
class ResourceSerializer < ApplicationSerializer
def attributes
super.merge(
"created_at" => nil,
"updated_at" => nil
)
end
def created_at
format_time(super)
end
def updated_at
format_time(super)
end
private
def format_time(va... |
github | somleng/somleng | https://github.com/somleng/somleng | app/serializers/services/recording_serializer.rb | Ruby | mit | 95 | develop | 411 | module Services
class RecordingSerializer < ResourceSerializer
def attributes
super.merge(
"sid" => nil,
"duration" => nil,
"url" => nil
)
end
def url
url_helpers.api_twilio_account_phone_call_recording_url(
object.account,
object.phone_call,
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/application_request_schema.rb | Ruby | mit | 95 | develop | 1,033 | class ApplicationRequestSchema < Dry::Validation::Contract
option :schema_helper, default: -> { RequestSchemaHelper.new }
attr_reader :input_params
delegate :success?, :errors, :context, to: :result
module Types
include Dry.Types()
Number = String.constructor do |string|
string.gsub(/\D/, "") ... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/request_schema_helper.rb | Ruby | mit | 95 | develop | 272 | class RequestSchemaHelper
def build_schema_error(error_code, **options)
error = fetch_error(error_code)
{ text: options.fetch(:text, error.message), code: error.code }
end
def fetch_error(error_code)
ApplicationError::Errors.fetch(error_code)
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/jsonapi_request_schema.rb | Ruby | mit | 95 | develop | 982 | class JSONAPIRequestSchema < ApplicationRequestSchema
option :resource, optional: true
def self.attribute_rule(*args, &block)
args = args.first if args.one?
rule(data: { attributes: args }) do |context:|
attributes = values.dig(:data, :attributes)
instance_exec(attributes, context:, &block) if ... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/phone_call_request_schema.rb | Ruby | mit | 95 | develop | 3,395 | module TwilioAPI
class PhoneCallRequestSchema < TwilioAPIRequestSchema
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
option :url_validator, default: -> { URLValidator.new(allow_http: true) }
option :twiml_validator, default: -> { TwiMLValidator.new }
option :phone_call_desti... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/delete_message_request_schema.rb | Ruby | mit | 95 | develop | 255 | module TwilioAPI
class DeleteMessageRequestSchema < TwilioAPIRequestSchema
option :message
params { }
rule do
next if message.complete?
base.failure(schema_helper.build_schema_error(:delete_before_complete))
end
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/available_phone_number_filter_request_schema.rb | Ruby | mit | 95 | develop | 1,365 | module TwilioAPI
class AvailablePhoneNumberFilterRequestSchema < TwilioAPIRequestSchema
def self.error_serializer_class
TwilioAPI::BadRequestErrorSerializer
end
params do
required(:type).value(:str?, included_in?: PhoneNumber.type.values.map(&:camelize))
required(:country_code).value(:s... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/update_message_request_schema.rb | Ruby | mit | 95 | develop | 775 | module TwilioAPI
class UpdateMessageRequestSchema < TwilioAPIRequestSchema
option :message
params do
optional(:Body).value(:string, eql?: "")
optional(:Status).value(:string, eql?: "canceled")
end
rule(:Body) do
next unless value == ""
next if message.complete?
base.fa... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/incoming_phone_number_filter_request_schema.rb | Ruby | mit | 95 | develop | 393 | module TwilioAPI
class IncomingPhoneNumberFilterRequestSchema < TwilioAPIRequestSchema
def self.error_serializer_class
TwilioAPI::BadRequestErrorSerializer
end
params do
optional(:PhoneNumber).filled(ApplicationRequestSchema::Types::Number)
end
def output
params = super
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/message_destination_schema_rules.rb | Ruby | mit | 95 | develop | 972 | module TwilioAPI
class MessageDestinationSchemaRules
attr_reader :sms_gateway_resolver, :error_code, :account_billing_policy, :sms_gateway
def initialize(**options)
@sms_gateway_resolver = options.fetch(:sms_gateway_resolver) { SMSGatewayResolver.new }
@account_billing_policy = options.fetch(:acc... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/update_phone_call_request_schema.rb | Ruby | mit | 95 | develop | 2,380 | module TwilioAPI
class UpdatePhoneCallRequestSchema < TwilioAPIRequestSchema
class UpdatePhoneCallRules
attr_reader :error_code
def valid?(phone_call)
return true if phone_call.uncompleted?
@error_code = :invalid_call_state
error_code.blank?
end
end
option :ph... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/incoming_phone_number_request_schema.rb | Ruby | mit | 95 | develop | 2,480 | module TwilioAPI
class IncomingPhoneNumberRequestSchema < TwilioAPIRequestSchema
option :incoming_phone_number, optional: true
option :url_validator, default: -> { URLValidator.new(allow_http: true) }
params do
optional(:PhoneNumber).maybe(ApplicationRequestSchema::Types::Number, :filled?)
op... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/message_request_schema.rb | Ruby | mit | 95 | develop | 5,191 | module TwilioAPI
class MessageRequestSchema < TwilioAPIRequestSchema
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
option :phone_number_configuration_rules,
default: -> { PhoneNumberConfigurationRules.new }
option :sms_encoding,
default: -> { SMSEncoding.ne... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/verify/verification_check_request_schema.rb | Ruby | mit | 95 | develop | 1,169 | module TwilioAPI
module Verify
class VerificationCheckRequestSchema < TwilioAPIRequestSchema
option :verification_service
option :verifications_scope
params do
required(:Code).filled(:str?)
optional(:To).value(ApplicationRequestSchema::Types::Number, :filled?)
optional(:... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/verify/verification_request_schema.rb | Ruby | mit | 95 | develop | 2,751 | module TwilioAPI
module Verify
class VerificationRequestSchema < TwilioAPIRequestSchema
option :verification_service
option :verifications_scope
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
option :phone_number_configuration_rules,
default: -> { Pho... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/verify/update_verification_request_schema.rb | Ruby | mit | 95 | develop | 1,216 | module TwilioAPI
module Verify
class UpdateVerificationRequestSchema < TwilioAPIRequestSchema
class VerificationStatusEvent
attr_reader :verification
EVENTS = {
"approved" => :approve,
"canceled" => :cancel
}.freeze
def initialize(verification)
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/verify/update_service_request_schema.rb | Ruby | mit | 95 | develop | 554 | module TwilioAPI
module Verify
class UpdateServiceRequestSchema < TwilioAPIRequestSchema
option :service
params do
optional(:FriendlyName).filled(:str?, max_size?: 32)
optional(:CodeLength).filled(:integer, gteq?: 4, lteq?: 10)
end
def output
params = super
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/twilio_api/verify/service_request_schema.rb | Ruby | mit | 95 | develop | 683 | module TwilioAPI
module Verify
class ServiceRequestSchema < TwilioAPIRequestSchema
params do
required(:FriendlyName).filled(:str?, max_size?: VerificationService::MAX_NAME_LENGTH)
optional(:CodeLength).filled(
:integer,
gteq?: VerificationService::VALID_CODE_LENGTHS.min,
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/schema_rules/phone_call_destination_schema_rules.rb | Ruby | mit | 95 | develop | 1,152 | module SchemaRules
class PhoneCallDestinationSchemaRules
attr_reader :error_code, :account_billing_policy
def initialize(**options)
@account_billing_policy = options.fetch(:account_billing_policy) { AccountBillingPolicy.new }
end
def valid?(account:, destination:)
@destination_rules = De... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/outbound_phone_calls_request_schema.rb | Ruby | mit | 95 | develop | 3,277 | module Services
class OutboundPhoneCallsRequestSchema < ServicesRequestSchema
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
option :phone_call_destination_schema_rules, default: -> { SchemaRules::PhoneCallDestinationSchemaRules.new }
option :phone_number_configuration_rules, def... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/call_service_capacity_request_schema.rb | Ruby | mit | 95 | develop | 256 | module Services
class CallServiceCapacityRequestSchema < ServicesRequestSchema
params do
required(:region).value(:str?, included_in?: SomlengRegion::Region.all.map(&:alias))
required(:capacity).value(:integer, gteq?: 0)
end
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/inbound_phone_call_request_schema.rb | Ruby | mit | 95 | develop | 5,630 | module Services
class InboundPhoneCallRequestSchema < ServicesRequestSchema
option :error_log_messages
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
option :phone_number_configuration_rules,
default: -> { PhoneNumberConfigurationRules.new }
option :sip_trunk_resol... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/recording_request_schema.rb | Ruby | mit | 95 | develop | 932 | module Services
class RecordingRequestSchema < ServicesRequestSchema
option :url_validator, default: proc { URLValidator.new(allow_http: true) }
params do
required(:phone_call_id).filled(:str?)
optional(:status_callback_url).filled(:str?)
optional(:status_callback_method).value(
App... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/media_stream_event_request_schema.rb | Ruby | mit | 95 | develop | 748 | module Services
class MediaStreamEventRequestSchema < ServicesRequestSchema
params do
required(:media_stream_id).filled(:str?)
required(:event).schema do
required(:type).value(:string)
optional(:details).maybe(:hash)
end
end
rule(:media_stream_id) do |context:|
con... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/inbound_message_request_schema.rb | Ruby | mit | 95 | develop | 2,525 | module Services
class InboundMessageRequestSchema < ServicesRequestSchema
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
option :phone_number_configuration_rules,
default: -> { PhoneNumberConfigurationRules.new }
option :inbound_message_behavior,
default: ->... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/media_stream_request_schema.rb | Ruby | mit | 95 | develop | 784 | module Services
class MediaStreamRequestSchema < ServicesRequestSchema
params do
required(:phone_call_id).filled(:str?)
required(:url).filled(:str?)
required(:tracks).value(:str?, included_in?: MediaStream.tracks.values)
optional(:custom_parameters).maybe(:hash)
end
rule(:phone_ca... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/phone_call_event_request_schema.rb | Ruby | mit | 95 | develop | 527 | module Services
class PhoneCallEventRequestSchema < ServicesRequestSchema
params do
required(:type).value(:str?, included_in?: PhoneCallEvent.type.values)
required(:phone_call).value(:str?)
optional(:variables).maybe(:hash?)
end
def output
params = super
result = {}
re... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/tts_event_request_schema.rb | Ruby | mit | 95 | develop | 684 | module Services
class TTSEventRequestSchema < ServicesRequestSchema
params do
required(:tts_voice).value(:str?, included_in?: TTSVoices::Voice.all.map(&:identifier))
required(:phone_call).value(:str?)
required(:num_chars).value(:integer, gteq?: 0)
end
def output
params = super
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/services/update_recording_request_schema.rb | Ruby | mit | 95 | develop | 400 | module Services
class UpdateRecordingRequestSchema < ServicesRequestSchema
option :url_validator, default: proc { URLValidator.new }
params do
required(:raw_recording_url).filled(:str?)
required(:external_id).filled(:str?)
end
rule(:raw_recording_url) do
next if url_validator.valid... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/phone_number_request_schema.rb | Ruby | mit | 95 | develop | 5,015 | module CarrierAPI
class PhoneNumberRequestSchema < CarrierAPIRequestSchema
class TypeValidator
include ActiveModel::Model
include ActiveModel::Attributes
attribute :number, PhoneNumberType.new
attribute :type
def self.model_name
ActiveModel::Name.new(self, nil, name.to_s)
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/update_account_request_schema.rb | Ruby | mit | 95 | develop | 1,344 | module CarrierAPI
class UpdateAccountRequestSchema < CarrierAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "account")
required(:id).filled(:str?)
required(:attributes).value(:hash).schema do
optional(:name).filled(:str?... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/phone_call_filter_request_schema.rb | Ruby | mit | 95 | develop | 760 | module CarrierAPI
class PhoneCallFilterRequestSchema < ApplicationRequestSchema
option :interaction_filter,
default: -> { SchemaRules::InteractionFilter.new(decorator_class: PhoneCallDecorator) }
params do
optional(:filter).value(:hash).hash do
optional(:account).filled(:string)
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/tts_event_filter_request_schema.rb | Ruby | mit | 95 | develop | 798 | module CarrierAPI
class TTSEventFilterRequestSchema < ApplicationRequestSchema
params do
optional(:filter).value(:hash).hash do
optional(:account).filled(:string)
optional(:phone_call).filled(:string)
optional(:from_date).value(:time)
optional(:to_date).value(:time)
end... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/update_phone_call_request_schema.rb | Ruby | mit | 95 | develop | 701 | module CarrierAPI
class UpdatePhoneCallRequestSchema < CarrierAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:type).filled(:string, eql?: "phone_call")
required(:id).filled(:string)
required(:attributes).value(:hash).schema do
optional(:price).fi... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/account_request_schema.rb | Ruby | mit | 95 | develop | 866 | module CarrierAPI
class AccountRequestSchema < CarrierAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "account")
required(:attributes).value(:hash).schema do
required(:name).filled(:str?)
optional(:billing_enabled).fil... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/update_message_request_schema.rb | Ruby | mit | 95 | develop | 696 | module CarrierAPI
class UpdateMessageRequestSchema < CarrierAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:type).filled(:string, eql?: "message")
required(:id).filled(:string)
required(:attributes).value(:hash).schema do
optional(:price).filled(... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/phone_number_stats_request_schema.rb | Ruby | mit | 95 | develop | 2,475 | module CarrierAPI
class PhoneNumberStatsRequestSchema < ApplicationRequestSchema
Group = Struct.new(:name, :column, keyword_init: true)
COUNTRY_GROUP = Group.new(name: "country", column: :iso_country_code)
REGION_GROUP = Group.new(name: "region", column: :iso_region_code)
LOCALITY_GROUP = Group.new(n... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/message_filter_request_schema.rb | Ruby | mit | 95 | develop | 752 | module CarrierAPI
class MessageFilterRequestSchema < ApplicationRequestSchema
option :interaction_filter,
default: -> { SchemaRules::InteractionFilter.new(decorator_class: MessageDecorator) }
params do
optional(:filter).value(:hash).hash do
optional(:account).filled(:string)
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/request_schemas/carrier_api/schema_rules/interaction_filter.rb | Ruby | mit | 95 | develop | 764 | module CarrierAPI
module SchemaRules
class InteractionFilter
attr_reader :decorator_class
def initialize(decorator_class:)
@decorator_class = decorator_class
end
def output(params)
result = {}
result[:account_id] = params.fetch(:account) if params.key?(:account)
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/destination_group_decorator.rb | Ruby | mit | 95 | develop | 250 | class DestinationGroupDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :DestinationGroup
end
def prefixes
object.prefixes.pluck(:prefix)
end
private
def object
__getobj__
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/decorated_collection.rb | Ruby | mit | 95 | develop | 229 | class DecoratedCollection
include Enumerable
delegate :size, :to_sentence, to: :@items
def initialize(items)
@items = items
end
def each(&)
@items.each do |item|
yield(item.decorated)
end
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/sip_trunk_form_decorator.rb | Ruby | mit | 95 | develop | 517 | class SIPTrunkFormDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :SIPTrunkForm
end
def source_ip_addresses_formatted
comma_separated_list_formatter.format(object.source_ip_addresses)
end
def route_prefixes_formatted
comma_separated_list_formatter.forma... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/tts_event_decorator.rb | Ruby | mit | 95 | develop | 231 | class TTSEventDecorator < SimpleDelegator
def sid
id
end
def account_sid
account_id
end
def phone_call_sid
phone_call_id
end
def characters
num_chars
end
def voice
tts_voice.to_s
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/verification_decorator.rb | Ruby | mit | 95 | develop | 852 | class VerificationDecorator < SimpleDelegator
STATUSES = %w[
pending canceled approved expired
].freeze
class << self
delegate :model_name, :human_attribute_name, to: :Verification
def statuses
STATUSES
end
end
def status
expired? ? "expired" : super
end
def to
phone_numb... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/tariff_decorator.rb | Ruby | mit | 95 | develop | 471 | class TariffDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :Tariff
end
def rate
[ display_rate(object.rate), rate_unit ].compact.join(" ")
end
def rate_unit(with_currency: false)
[ (object.currency.symbol if with_currency), ("/ min" if call?) ].compact... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/destination_tariff_decorator.rb | Ruby | mit | 95 | develop | 495 | class DestinationTariffDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :DestinationTariff
end
def destination_group_name
decorated_destination_group.name
end
def tariff_rate
decorated_tariff.rate
end
private
def decorated_tariff
@decorated_t... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/sms_gateway_channel_group_decorator.rb | Ruby | mit | 95 | develop | 547 | class SMSGatewayChannelGroupDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :SMSGatewayChannelGroup
end
def route_prefixes_formatted
comma_separated_list_formatter.format(object.route_prefixes)
end
def configured_channel_slots_formatted
comma_separated_... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/sms_gateway_decorator.rb | Ruby | mit | 95 | develop | 393 | class SMSGatewayDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :SMSGateway
end
def default_sender_formatted
phone_number_formatter.format(object.default_sender, format: :international)
end
private
def phone_number_formatter
@phone_number_formatter |... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/tariff_plan_decorator.rb | Ruby | mit | 95 | develop | 369 | class TariffPlanDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :TariffPlan
end
def category
object.category.text
end
def name
"#{category} (#{object.name})"
end
def schedules
object.schedules.order(tariff_plan_tiers: { weight: :desc })
end
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/recording_decorator.rb | Ruby | mit | 95 | develop | 511 | class RecordingDecorator < SimpleDelegator
STATUS_MAPPINGS = {
"in_progress" => "processing",
"completed" => "completed"
}.freeze
def sid
object.id
end
def duration
object.file.metadata[:duration].to_i.to_s if object.file.attached?
end
def start_time
created_at
end
def channels... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/incoming_phone_number_decorator.rb | Ruby | mit | 95 | develop | 782 | class IncomingPhoneNumberDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :IncomingPhoneNumber
end
delegate :type_formatted, :formatted_location, :region_name, :locality, to: :phone_number, allow_nil: true
def number
phone_number_formatter.format(object.number... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/sms_gateway_channel_group_form_decorator.rb | Ruby | mit | 95 | develop | 432 | class SMSGatewayChannelGroupFormDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :SMSGatewayChannelGroupForm
end
def route_prefixes_formatted
comma_separated_list_formatter.format(object.route_prefixes)
end
private
def comma_separated_list_formatter
@... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/tariff_schedule_decorator.rb | Ruby | mit | 95 | develop | 378 | class TariffScheduleDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :TariffSchedule
end
def category
object.category.text
end
def destination_tariffs
DecoratedCollection.new(object.destination_tariffs)
end
def name
"#{category} (#{object.name})... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/sip_trunk_decorator.rb | Ruby | mit | 95 | develop | 737 | class SIPTrunkDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :SIPTrunk
end
def default_sender_formatted
phone_number_formatter.format(object.default_sender, format: :international)
end
def inbound_source_ips_formatted
comma_separated_list_formatter.for... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/phone_number_decorator.rb | Ruby | mit | 95 | develop | 989 | class PhoneNumberDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :PhoneNumber
end
def number
phone_number_formatter.format(object.number, format: :e164)
end
def number_formatted
phone_number_formatter.format(object.number, format: :international)
end
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/verification_service_decorator.rb | Ruby | mit | 95 | develop | 359 | class VerificationServiceDecorator < SimpleDelegator
def sample_message(locale:)
code = verification_code_generator.generate_code(code_length: object.code_length)
object.default_template(code:, locale:).render_message
end
private
def verification_code_generator
VerificationCodeGenerator.new
end
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/phone_call_decorator.rb | Ruby | mit | 95 | develop | 2,296 | class PhoneCallDecorator < SimpleDelegator
NullCallDataRecord = Struct.new(:bill_sec, :start_time, :end_time)
TWILIO_CALL_STATUS_MAPPINGS = {
"queued" => "queued",
"initiating" => "queued",
"initiated" => "queued",
"ringing" => "ringing",
"answered" => "in-progress",
"busy" => "busy",
"... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/phone_number_plan_decorator.rb | Ruby | mit | 95 | develop | 510 | class PhoneNumberPlanDecorator < SimpleDelegator
class << self
delegate :model_name, :human_attribute_name, to: :PhoneNumberPlan
end
def number_formatted
phone_number_formatter.format(object.number, format: :international)
end
def status_color
active? ? :success : :secondary
end
def phone_n... |
github | somleng/somleng | https://github.com/somleng/somleng | app/decorators/message_decorator.rb | Ruby | mit | 95 | develop | 2,023 | class MessageDecorator < SimpleDelegator
TWILIO_MESSAGE_DIRECTIONS = {
"inbound" => "inbound",
"outbound_api" => "outbound-api",
"outbound_call" => "outbound-call",
"outbound_reply" => "outbound-reply",
"outbound" => "outbound"
}.freeze
TWILIO_MESSAGE_STATUS_MAPPINGS = {
"accepted" => "ac... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/sms_gateway_resolver.rb | Ruby | mit | 95 | develop | 1,442 | class SMSGatewayResolver
class LoadBalancer
def select_channel(channels)
channels.sample
end
end
attr_reader :load_balancer
def initialize(load_balancer: LoadBalancer.new)
@load_balancer = load_balancer
end
def resolve(carrier:, destination:)
channel_groups = carrier.sms_gateway_cha... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/sip_trunk_resolver.rb | Ruby | mit | 95 | develop | 1,241 | class SIPTrunkResolver
class Finder
attr_reader :source_ip, :destination_number
def initialize(**options)
@source_ip = options.fetch(:source_ip)
@destination_number = options[:destination_number]
end
def execute
return find_sip_trunk(carrier_id: carriers.pluck(:carrier_id)) if carr... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/balance_transaction.rb | Ruby | mit | 95 | develop | 666 | class BalanceTransaction < ApplicationRecord
extend Enumerize
self.inheritance_column = :_type_disabled
belongs_to :account
belongs_to :carrier
belongs_to :created_by, class_name: "User", optional: true
belongs_to :message, optional: true
belongs_to :phone_call, optional: true
enumerize :type, in: [ :... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/sms_encoding.rb | Ruby | mit | 95 | develop | 575 | class SMSEncoding
attr_reader :encoding_detector
Result = Struct.new(:segments, :encoding, keyword_init: true)
def initialize(encoding_detector: default_encoding_detector)
@encoding_detector = encoding_detector
end
def detect(body)
detector = encoding_detector.new(body)
Result.new(
segmen... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/billing_parameters.rb | Ruby | mit | 95 | develop | 311 | class BillingParameters
attr_reader :phone_call
def initialize(phone_call)
@phone_call = phone_call
end
def to_h
{
enabled: phone_call.account.billing_enabled?,
category: phone_call.tariff_schedule_category.to_s,
billing_mode: phone_call.account.billing_mode
}
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/rating_engine_client.rb | Ruby | mit | 95 | develop | 9,355 | class RatingEngineClient
attr_reader :client
LOAD_ID = "somleng.org"
BALANCE_TYPE = "*monetary"
ROUNDING_DECIMALS = 4
ROUNDING_METHOD = "*up"
RATE_UNIT = "60s"
RATE_INCREMENT = "60s"
RATE_ATTRIBUTES = {
call: {
unit: "60s",
increment: "60s",
tor: "*voice"
},
message: {
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/raw_recording_presigned_url.rb | Ruby | mit | 95 | develop | 317 | class RawRecordingPresignedURL
attr_reader :object_key
def initialize(object_key)
@object_key = object_key
end
def presigned_url
s3_object = Aws::S3::Object.new(
Rails.configuration.app_settings.fetch(:raw_recordings_bucket),
object_key
)
s3_object.presigned_url(:get)
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/webhook_endpoint.rb | Ruby | mit | 95 | develop | 226 | class WebhookEndpoint < ApplicationRecord
belongs_to :oauth_application
before_create :generate_signing_secret
private
def generate_signing_secret
self.signing_secret ||= SecureRandom.alphanumeric(32)
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/phone_number_plan.rb | Ruby | mit | 95 | develop | 571 | class PhoneNumberPlan < ApplicationRecord
extend Enumerize
attribute :number, PhoneNumberType.new
belongs_to :carrier
belongs_to :account
belongs_to :phone_number, optional: true
has_one :incoming_phone_number
enumerize :status, in: [ :active, :canceled ], default: :active, scope: :shallow, predicates:... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/sip_trunk.rb | Ruby | mit | 95 | develop | 2,626 | class SIPTrunk < ApplicationRecord
DIAL_STRING_FORMAT = "%<plus_prefix>s%<dial_string_prefix>s%<national_prefix>s%<local_number>s@%<host>s".freeze
extend Enumerize
has_many :phone_calls
has_many :sip_trunk_inbound_source_ip_addresses, autosave: true, dependent: :delete_all
belongs_to :carrier
encrypts :pa... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/verification_locales.rb | Ruby | mit | 95 | develop | 5,989 | class VerificationLocales
Locale = Struct.new(:iso_code, :language_name, keyword_init: true)
CountryLocale = Struct.new(:country_code, :locale, keyword_init: true)
DEFAULT_COUNTRY_LOCALE = CountryLocale.new(country_code: "US", locale: "en").freeze
COUNTRY_LOCALES = [
CountryLocale.new(country_code: "AD", ... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/global_call_session_limiter.rb | Ruby | mit | 95 | develop | 482 | class GlobalCallSessionLimiter < CallSessionLimiter
attr_reader :scope
def initialize(**options)
super(limit_per_capacity_unit: AppSettings.fetch(:global_call_sessions_limit), **options)
@scope = options.fetch(:scope, :global)
end
def add_session_to(*, **)
super(*, scope:)
end
def remove_sess... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/export.rb | Ruby | mit | 95 | develop | 411 | class Export < ApplicationRecord
extend Enumerize
enumerize :resource_type, in: %w[Account PhoneNumber PhoneCall Message TTSEvent PhoneNumberPlan]
belongs_to :user
before_create :generate_name
has_one_attached :file
def ready?
file.attached?
end
private
def generate_name
self.name ||= fo... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/twiml_validator.rb | Ruby | mit | 95 | develop | 229 | class TwiMLValidator
attr_reader :options
def valid?(value)
Nokogiri::XML(value) do |c|
c.options = Nokogiri::XML::ParseOptions::STRICT
end
rescue Nokogiri::XML::SyntaxError => _e
false
end
true
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/import.rb | Ruby | mit | 95 | develop | 564 | class Import < ApplicationRecord
extend Enumerize
include AASM
attr_accessor :error_line
enumerize :resource_type, in: %w[PhoneNumber]
belongs_to :user
belongs_to :carrier
has_one_attached :file
validates :file, presence: true, attached: true, content_type: "text/csv"
aasm column: :status do
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/call_service_capacity.rb | Ruby | mit | 95 | develop | 755 | class CallServiceCapacity
class Instance
attr_reader :backend
def initialize(**options)
@backend = options.fetch(:backend) { AppSettings.redis }
end
def current_for(region)
backend.with do |connection|
connection.exists?(capacity_key(region)) ? connection.get(capacity_key(region)... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/tariff_plan_subscription.rb | Ruby | mit | 95 | develop | 281 | class TariffPlanSubscription < ApplicationRecord
extend Enumerize
belongs_to :account, inverse_of: :tariff_plan_subscriptions
belongs_to :plan, class_name: "TariffPlan"
enumerize :category, in: TariffSchedule.category.values, value_class: TariffScheduleCategoryValue
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/sip_trunk_channel_manager.rb | Ruby | mit | 95 | develop | 490 | class SIPTrunkChannelManager
class << self
def allocate_sip_trunk_channel(sip_trunk, options = {}, &block)
with_lock("allocate_sip_trunk_channel:#{sip_trunk.id}", options, &block)
end
private
def with_lock(key, options, &block)
options.with_defaults!(
timeout_seconds: 15.seconds,... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/application_record.rb | Ruby | mit | 95 | develop | 318 | class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
self.implicit_order_column = :sequence_number
include SerializableResource
include DecoratableResource
scope :latest_first, -> { order(sequence_number: :desc) }
def self.filter_class
"#{model_name}Filter".constantize
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/account_call_session_limiter.rb | Ruby | mit | 95 | develop | 552 | class AccountCallSessionLimiter < CallSessionLimiter
def initialize(**)
super(limit_per_capacity_unit: AppSettings.fetch(:account_call_sessions_limit), **)
end
def add_session_to(*, scope:)
super(*, scope: scope_key(scope))
end
def remove_session_from(*, scope:)
super(*, scope: scope_key(scope))... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/tariff.rb | Ruby | mit | 95 | develop | 257 | class Tariff < ApplicationRecord
extend Enumerize
belongs_to :carrier
attribute :currency, CurrencyType.new
enumerize :category, in: [ :message, :call ], predicates: true
def rate
InfinitePrecisionMoney.new(rate_cents, currency)
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/verification.rb | Ruby | mit | 95 | develop | 2,047 | class Verification < ApplicationRecord
include AASM
extend Enumerize
MAX_CHECK_ATTEMPTS = 5
MAX_DELIVERY_ATTEMPTS = 5
belongs_to :carrier
belongs_to :account
belongs_to :verification_service
has_many :verification_attempts
has_many :delivery_attempts, class_name: "VerificationDeliveryAttempt"
en... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/sms_gateway.rb | Ruby | mit | 95 | develop | 935 | class SMSGateway < ApplicationRecord
belongs_to :carrier
has_many :messages
has_many :channel_groups, class_name: "SMSGatewayChannelGroup"
has_many :channels, class_name: "SMSGatewayChannel"
encrypts :device_token, deterministic: true, downcase: true
attribute :default_sender, PhoneNumberType.new
befor... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/tariff_schedule_category_value.rb | Ruby | mit | 95 | develop | 327 | class TariffScheduleCategoryValue < Enumerize::Value
delegate :tariff_category, :rate_unit, :type, :description, :direction, :diagram_direction_symbol, :diagram_category, to: :@tariff_schedule_category
def initialize(...)
super(...)
@tariff_schedule_category = TariffScheduleCategoryType.new.cast(value)
e... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/tariff_plan_tier.rb | Ruby | mit | 95 | develop | 283 | class TariffPlanTier < ApplicationRecord
DEFAULT_WEIGHT = 10.0
belongs_to :plan, class_name: "TariffPlan"
belongs_to :schedule, class_name: "TariffSchedule"
before_create :set_default_weight
private
def set_default_weight
self.weight ||= DEFAULT_WEIGHT
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/destination_group.rb | Ruby | mit | 95 | develop | 705 | class DestinationGroup < ApplicationRecord
DEFAULT_CATCH_ALL_NAME = "Catch all"
CATCH_ALL_PREFIXES = (0..9).map(&:to_s).to_a
belongs_to :carrier
has_many :prefixes, class_name: "DestinationPrefix", dependent: :destroy, autosave: true, inverse_of: :destination_group
has_many :destination_tariffs, dependent: :... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/aggregate_data_query.rb | Ruby | mit | 95 | develop | 1,063 | class AggregateDataQuery
attr_reader :named_scopes, :conditions, :groups, :having
def initialize(**options)
@named_scopes = Array(options[:named_scopes])
@conditions = options.fetch(:conditions, {})
@groups = Array(options.fetch(:groups))
@having = options.fetch(:having, {})
end
def apply(scop... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/phone_call_status_event.rb | Ruby | mit | 95 | develop | 350 | class PhoneCallStatusEvent
attr_reader :phone_call
EVENTS = {
"completed" => :complete,
"canceled" => :cancel
}.freeze
def initialize(phone_call)
@phone_call = phone_call
end
def may_transition_to?(new_state)
return false unless EVENTS.key?(new_state)
phone_call.may_fire_event?(EVENT... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/error_log.rb | Ruby | mit | 95 | develop | 370 | class ErrorLog < ApplicationRecord
self.inheritance_column = :_type_disabled
extend Enumerize
belongs_to :carrier, optional: true
belongs_to :account, optional: true
has_many :notifications, class_name: "ErrorLogNotification"
enumerize :type, in: [ :inbound_message, :inbound_call, :sms_gateway_disconnect... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/simple_counter.rb | Ruby | mit | 95 | develop | 1,020 | class SimpleCounter
attr_reader :tag, :key, :limit, :expiry, :backend
def initialize(**options)
@key = options.fetch(:key)
@tag = "{counter:#{key}}"
@limit = options.fetch(:limit, nil)
@expiry = options.fetch(:expiry, 5.minutes)
@backend = options.fetch(:backend) { AppSettings.redis }
end
... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/verification_template.rb | Ruby | mit | 95 | develop | 1,816 | class VerificationTemplate
DEFAULT_VOICE_LANGUAGE = "en-US".freeze
LOCALE_TO_VOICE_LANGUAGE_MAPPING = {
zh: :cmn,
"zh-cn": :cmn,
"zh-hk": :yue,
ar: :arb
}.freeze
attr_reader :friendly_name, :code, :locale, :country_code, :template
def initialize(friendly_name:, code:, locale:, country_code: ... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/phone_number_validator.rb | Ruby | mit | 95 | develop | 229 | class PhoneNumberValidator
attr_reader :validator
def initialize(validator: Phony)
@validator = validator
end
def valid?(value)
return false if value.starts_with?("0")
validator.plausible?(value)
end
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/app_request.rb | Ruby | mit | 95 | develop | 626 | class AppRequest
attr_reader :request
def initialize(request)
@request = ActionDispatch::Request.new(request.env.except("HTTP_X_FORWARDED_HOST"))
end
def carrier_subdomain_request?
_subdomain, *namespace = request.subdomains
namespace == [ AppSettings.fetch(:app_subdomain) ]
end
def find_carr... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/messaging_service.rb | Ruby | mit | 95 | develop | 311 | class MessagingService < ApplicationRecord
extend Enumerize
belongs_to :account
belongs_to :carrier
has_many :incoming_phone_numbers
has_many :messages
enumerize :inbound_request_method, in: %w[POST GET]
enumerize :inbound_message_behavior,
in: %i[defer_to_sender drop webhook]
end |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/message.rb | Ruby | mit | 95 | develop | 2,716 | class Message < ApplicationRecord
include AASM
extend Enumerize
before_create :set_beneficiary_data, :set_status_timestamp
attribute :beneficiary_fingerprint, SHA256Type.new
attribute :to, PhoneNumberType.new
attribute :from, PhoneNumberType.new
belongs_to :carrier
belongs_to :account
belongs_to :s... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/fuzzy_search.rb | Ruby | mit | 95 | develop | 397 | class FuzzySearch
attr_reader :scope, :column
def initialize(scope, column:)
@scope = scope
@column = column
end
def apply(search_term)
return scope if search_term.blank?
term = "%#{scope.model.sanitize_sql_like(search_term.squish)}%"
scope.where(arel_table[column].matches(term, nil, fals... |
github | somleng/somleng | https://github.com/somleng/somleng | app/models/feature_flag.rb | Ruby | mit | 95 | develop | 915 | class FeatureFlag
PERMISSIONS = {
"d28bb460-1324-4aa5-860a-8ef48fb5ca7f" => [ :broadcasts ],
"32217a9c-c578-45ce-acd9-550e5b4a8f0f" => [ :broadcasts ],
"d1bc9915-ed19-4152-bf7c-b651979e4491" => [ :broadcasts ],
"973e2da2-df4e-43b4-ab50-8d4ca091c116" => [ :broadcasts ],
"5c9889cf-5f84-4547-b2bf-fbd... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.