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 | antiwork/gumroad | https://github.com/antiwork/gumroad | app/presenters/admin/product_presenter/card.rb | Ruby | mit | 8,966 | main | 2,019 | # frozen_string_literal: true
class Admin::ProductPresenter::Card
attr_reader :product, :pundit_user
def initialize(product:, pundit_user:)
@product = product
@pundit_user = pundit_user
end
def props
link_policy = Admin::Products::StaffPicked::LinkPolicy.new(pundit_user, product)
{
exte... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/presenters/admin/user_presenter/card.rb | Ruby | mit | 8,966 | main | 3,893 | # frozen_string_literal: true
class Admin::UserPresenter::Card
attr_reader :user, :pundit_user
def initialize(user:, pundit_user:)
@user = user
@pundit_user = pundit_user
end
def props
{
impersonatable: Admin::Impersonators::UserPolicy.new(pundit_user, user).create?,
# Identification... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/observers/email_delivery_observer.rb | Ruby | mit | 8,966 | main | 234 | # frozen_string_literal: true
class EmailDeliveryObserver
def self.delivered_email(message)
EmailDeliveryObserver::HandleEmailEvent.perform(message)
EmailDeliveryObserver::HandleCustomerEmailInfo.perform(message)
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/observers/email_delivery_observer/handle_email_event.rb | Ruby | mit | 8,966 | main | 314 | # frozen_string_literal: true
module EmailDeliveryObserver::HandleEmailEvent
extend self
def perform(message)
message.to.each do |email|
EmailEvent.log_send_events(email, message.date)
rescue => e
Rails.logger.error "Error logging email event - #{email} - #{e.message}"
end
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/observers/email_delivery_observer/handle_customer_email_info.rb | Ruby | mit | 8,966 | main | 3,395 | # frozen_string_literal: true
module EmailDeliveryObserver::HandleCustomerEmailInfo
class InvalidHeaderError < StandardError
attr_reader :metadata
def initialize(message, metadata)
super(message)
@metadata = metadata
end
def sentry_context
{ debug: metadata }
end
end
exte... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/instant_payouts_service.rb | Ruby | mit | 8,966 | main | 1,889 | # frozen_string_literal: true
class InstantPayoutsService
attr_reader :seller, :date
def initialize(seller, date: Date.today)
@seller = seller
@date = date
end
def perform
return { success: false, error: "Your account is not eligible for instant payouts at this time." } unless seller.instant_payo... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/discord_api.rb | Ruby | mit | 8,966 | main | 1,155 | # frozen_string_literal: true
class DiscordApi
def oauth_token(code, redirect_uri)
body = {
grant_type: "authorization_code",
code:,
client_id: DISCORD_CLIENT_ID,
client_secret: DISCORD_CLIENT_SECRET,
redirect_uri:
}
headers = { "Content-Type" => "application/x-www-form-url... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/update_user_country.rb | Ruby | mit | 8,966 | main | 1,266 | # frozen_string_literal: true
class UpdateUserCountry
attr_reader :new_country_code, :user
def initialize(new_country_code:, user:)
@old_country_code = user.alive_user_compliance_info.legal_entity_country_code
@new_country_code = new_country_code
@user = user
end
def process
keep_payment_addr... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/save_public_files_service.rb | Ruby | mit | 8,966 | main | 2,050 | # frozen_string_literal: true
class SavePublicFilesService
attr_reader :resource, :files_params, :content
def initialize(resource:, files_params:, content:)
@resource = resource
@files_params = files_params.presence || []
@content = content.to_s
end
def process
ActiveRecord::Base.transaction ... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/qst_validation_service.rb | Ruby | mit | 8,966 | main | 690 | # frozen_string_literal: true
class QstValidationService
attr_reader :qst_id
def initialize(qst_id)
@qst_id = qst_id
end
def process
return false if qst_id.blank?
Rails.cache.fetch("revenu_quebec_validation_#{qst_id}", expires_in: 10.minutes) do
valid_qst?
end
end
private
QST_... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/username_generator_service.rb | Ruby | mit | 8,966 | main | 1,930 | # frozen_string_literal: true
class UsernameGeneratorService
attr_reader :user
def initialize(user)
@user = user
end
def username
return if user_data.nil?
name = ensure_valid_username(openai_completion)
name += random_digit while User.exists?(username: name)
return if name.length > 20
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/seller_mobile_analytics_service.rb | Ruby | mit | 8,966 | main | 2,450 | # frozen_string_literal: true
class SellerMobileAnalyticsService
SALES_LIMIT = 300
def initialize(user, range: "day", query: nil, fields: [])
@user = user
@range = range
@query = query
@fields = fields
@result = {}
end
def process
@search_result = PurchaseSearchService.search(search_p... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/circle_api.rb | Ruby | mit | 8,966 | main | 1,348 | # frozen_string_literal: true
class CircleApi
include HTTParty
base_uri "https://app.circle.so/api/v1"
def initialize(api_key)
@api_key = api_key
end
def get_communities
rate_limited_call { self.class.get("/communities", headers:) }
end
def get_spaces(community_id)
rate_limited_call { sel... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/zoom_api.rb | Ruby | mit | 8,966 | main | 1,173 | # frozen_string_literal: true
class ZoomApi
include HTTParty
ZOOM_OAUTH_URL = "https://zoom.us/oauth/token"
base_uri "https://api.zoom.us/v2"
def oauth_token(code, redirect_uri)
body = {
grant_type: "authorization_code",
code:,
redirect_uri:
}
HTTParty.post(ZOOM_OAUTH_URL, body... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/gmail_abuse_filter.rb | Ruby | mit | 8,966 | main | 1,404 | # frozen_string_literal: true
class GmailAbuseFilter
REDIS_KEY = RedisKey.gmail_abuse_normalized_emails
class << self
def exists?(email)
normalized = User.normalize_gmail_address(email)
return false if normalized.nil?
_, domain = normalized.split("@", 2)
return false if User::EmailNor... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/user_balance_stats_service.rb | Ruby | mit | 8,966 | main | 2,957 | # frozen_string_literal: true
class UserBalanceStatsService
include ActionView::Helpers::TranslationHelper
include PayoutsHelper
attr_reader :user
DEFAULT_SALES_CACHING_THRESHOLD = 50_000
def initialize(user:)
@user = user
end
def fetch
if should_use_cache?
UpdateUserBalanceStatsCacheWork... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/email_redactor_service.rb | Ruby | mit | 8,966 | main | 431 | # frozen_string_literal: true
class EmailRedactorService
def self.redact(email)
username, domain = email.split("@")
domain_name, _, tld = domain.rpartition(".")
redacted_username = username.length > 1 ? "#{username[0]}#{'*' * (username.length - 2)}#{username[-1]}" : username
redacted_domain = "#{dom... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/product_indexing_service.rb | Ruby | mit | 8,966 | main | 742 | # frozen_string_literal: true
class ProductIndexingService
def self.perform(product:, action:, attributes_to_update: [], on_failure: :raise)
case action
when "index"
product.__elasticsearch__.index_document
when "update"
return if attributes_to_update.empty?
attributes = product.build_... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/gdpr_data_erasure_service.rb | Ruby | mit | 8,966 | main | 6,359 | # frozen_string_literal: true
class GdprDataErasureService
ANONYMIZED_EMAIL_DOMAIN = "deleted.gumroad.com"
ANONYMIZED_NAME = "[deleted]"
ANONYMIZED_VALUE = "[redacted]"
# Fields that must be retained for tax/legal compliance (Article 17(3)(b))
# Transaction records, payout history, tax documents are kept.
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/error_notifier.rb | Ruby | mit | 8,966 | main | 1,141 | # frozen_string_literal: true
class ErrorNotifier
class << self
def notify(exception_or_message, **context, &block)
notify_sentry(exception_or_message, **context, &block)
end
private
def notify_sentry(exception_or_message, **context, &block)
if exception_or_message.is_a?(Exception)
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/features_markdown_generator.rb | Ruby | mit | 8,966 | main | 10,670 | # frozen_string_literal: true
class FeaturesMarkdownGenerator
FEATURES_URL = "https://gumroad.com/features"
def self.call
new.call
end
def call
<<~MARKDOWN
# Gumroad features
> For the full visual experience, visit [gumroad.com/features](#{FEATURES_URL}).
> Source code: [github.com... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/rpush_apns_app_service.rb | Ruby | mit | 8,966 | main | 1,275 | # frozen_string_literal: true
class RpushApnsAppService
attr_reader :name
def initialize(name:)
@name = name
end
def first_or_create!
first || create!
end
private
def first
Rpush::Apns2::App.all.select { |app| app.name == name }.first
end
def create!
certificate = File.r... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/post_resend_api.rb | Ruby | mit | 8,966 | main | 9,800 | # frozen_string_literal: true
class PostResendApi
include Rails.application.routes.url_helpers
include ActionView::Helpers::SanitizeHelper
include MailerHelper, CustomMailerRouteBuilder
_routes.default_url_options = Rails.application.config.action_mailer.default_url_options
MAX_RECIPIENTS = 100 # Resend's ba... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/recommended_wishlists_service.rb | Ruby | mit | 8,966 | main | 1,250 | # frozen_string_literal: true
class RecommendedWishlistsService
def self.fetch(limit:, current_seller:, curated_product_ids: [], taxonomy_id: nil)
scope = Wishlist.where(recommendable: true).order(recent_follower_count: :desc)
scope = scope.where.not(user_id: current_seller.id) if current_seller.present?
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/update_user_compliance_info.rb | Ruby | mit | 8,966 | main | 11,896 | # frozen_string_literal: true
class UpdateUserComplianceInfo
COUNTRIES_REQUIRING_PHYSICAL_ADDRESS = {
"US" => "We require a valid physical US address. We cannot accept a P.O. Box as a valid address.",
"GH" => "We require a valid physical address in Ghana. We cannot accept a P.O. Box as a valid address.",
}... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/mailer_attachment_or_link_service.rb | Ruby | mit | 8,966 | main | 892 | # frozen_string_literal: true
# Given a file:
# - Check if file size is acceptable for direct attachment
# - Yes: Return file
# - No: Return temporary expiring S3 link
class MailerAttachmentOrLinkService
# https://sendgrid.com/docs/ui/sending-email/attachments-with-digioh/
# Can send upto 30 MB, but recommended is... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/cleanup_rpush_device_service.rb | Ruby | mit | 8,966 | main | 476 | # frozen_string_literal: true
class CleanupRpushDeviceService
def initialize(feedback)
@feedback = feedback
end
def process
Device.where(token: @feedback.device_token).destroy_all
@feedback.destroy
rescue => e
Rails.logger.error "Could not clean up a device token based on APN feedback #{@feedb... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/home_page_link_service.rb | Ruby | mit | 8,966 | main | 557 | # frozen_string_literal: true
class HomePageLinkService
PAGES = [:privacy, :terms, :about, :features, :university, :pricing, :affiliates, :prohibited]
private_constant :PAGES
ROOT_DOMAIN_WITH_PROTCOL = UrlService.root_domain_with_protocol
private_constant :ROOT_DOMAIN_WITH_PROTCOL
class << self
PAGES.e... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/update_payout_method.rb | Ruby | mit | 8,966 | main | 17,341 | # frozen_string_literal: true
class UpdatePayoutMethod
include AfterCommitEverywhere
attr_reader :params, :user
BANK_ACCOUNT_TYPES = {
AchAccount.name => { class: AchAccount, permitted_params: [:routing_number] },
CanadianBankAccount.name => { class: CanadianBankAccount, permitted_params: %i[institutio... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/save_files_service.rb | Ruby | mit | 8,966 | main | 2,751 | # frozen_string_literal: true
class SaveFilesService
delegate :product_files, to: :owner
attr_reader :owner, :params, :rich_content_params
def self.perform(*args)
new(*args).perform
end
# Params:
# +owner+ - an object of a model having the WithProductFiles mixin
# +params+ - a nested hash of produc... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/save_content_upsells_service.rb | Ruby | mit | 8,966 | main | 2,846 | # frozen_string_literal: true
class SaveContentUpsellsService
def initialize(seller:, content:, old_content:)
@seller = seller
@content = content
@old_content = old_content
end
def from_html
old_doc = Nokogiri::HTML.fragment(old_content)
new_doc = Nokogiri::HTML.fragment(content)
old_up... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/google_calendar_api.rb | Ruby | mit | 8,966 | main | 1,952 | # frozen_string_literal: true
class GoogleCalendarApi
include HTTParty
GOOGLE_CALENDAR_OAUTH_URL = "https://oauth2.googleapis.com"
base_uri "https://www.googleapis.com/"
def oauth_token(code, redirect_uri)
body = {
grant_type: "authorization_code",
code:,
redirect_uri:,
client_id:... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/user_custom_domain_request_service.rb | Ruby | mit | 8,966 | main | 279 | # frozen_string_literal: true
class UserCustomDomainRequestService
class << self
def valid?(request)
!GumroadDomainConstraint.matches?(request) && !DiscoverDomainConstraint.matches?(request) && CustomDomain.find_by_host(request.host)&.product.nil?
end
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/black_friday_stats_service.rb | Ruby | mit | 8,966 | main | 525 | # frozen_string_literal: true
class BlackFridayStatsService
CACHE_KEY = "black_friday_stats"
CACHE_EXPIRATION = 10.minutes
class << self
def fetch_stats
Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_EXPIRATION) do
calculate_stats
end
end
def calculate_stats
# TODO: Implem... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/admin_search_service.rb | Ruby | mit | 8,966 | main | 4,607 | # frozen_string_literal: true
class AdminSearchService
class InvalidDateError < StandardError; end
def search_purchases(query: nil, email: nil, product_title_query: nil, purchase_status: nil, creator_email: nil, license_key: nil, transaction_date: nil, last_4: nil, card_type: nil, price: nil, expiry_date: nil, li... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/subdomain_redirector_service.rb | Ruby | mit | 8,966 | main | 1,417 | # frozen_string_literal: true
class SubdomainRedirectorService
CACHE_KEY = "subdomain_redirects_cache_key"
private_constant :CACHE_KEY
REDIS_KEY = "subdomain_redirects_config"
private_constant :REDIS_KEY
PROTECTED_HOSTS = VALID_API_REQUEST_HOSTS + VALID_REQUEST_HOSTS
private_constant :PROTECTED_HOSTS
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/business_id_labels.rb | Ruby | mit | 8,966 | main | 1,055 | # frozen_string_literal: true
module BusinessIdLabels
COUNTRY_CODES = %w[
AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE
GB NO CH IS
CA AU NZ ZA
JP KR IN BR MX
].freeze
LABELS = {
"AT" => "VAT ID", "BE" => "VAT ID", "BG" => "VAT ID", "HR" => "VAT ID", "CY" =... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/bundle_search_products_service.rb | Ruby | mit | 8,966 | main | 1,169 | # frozen_string_literal: true
class BundleSearchProductsService
PER_PAGE = 10
attr_reader :bundle, :query, :page, :all, :seller
def initialize(bundle:, seller:, query: nil, page: 1, all: false)
@bundle = bundle
@seller = seller
@query = query
@page = [page.to_i, 1].max
@all = all
end
d... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/handle_email_event_info.rb | Ruby | mit | 8,966 | main | 708 | # frozen_string_literal: true
# Email provider-agnostic service to handle email event info.
# The logic should not handle any email provider (Sendgrid, Resend) specific logic.
# For that, user EmailEventInfo subclasses (SendgridEventInfo, ResendEventInfo).
#
class HandleEmailEventInfo
def self.perform(email_event_in... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/url_service.rb | Ruby | mit | 8,966 | main | 1,814 | # frozen_string_literal: true
class UrlService
class << self
def domain_with_protocol
"#{PROTOCOL}://#{DOMAIN}"
end
def root_domain_with_protocol
"#{PROTOCOL}://#{ROOT_DOMAIN}"
end
def discover_domain_with_protocol
"#{PROTOCOL}://#{DISCOVER_DOMAIN}"
end
def api_domain... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/community_chat_recap_generator_service.rb | Ruby | mit | 8,966 | main | 7,635 | # frozen_string_literal: true
class CommunityChatRecapGeneratorService
MAX_MESSAGES_TO_SUMMARIZE = 1000
MAX_SUMMARY_LENGTH = 500
MIN_SUMMARY_BULLET_POINTS = 1
MAX_SUMMARY_BULLET_POINTS = 5
OPENAI_REQUEST_TIMEOUT_IN_SECONDS = 10
DAILY_SUMMARY_SYSTEM_PROMPT = <<~PROMPT
You are an AI assistant that create... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/safe_redirect_path_service.rb | Ruby | mit | 8,966 | main | 827 | # frozen_string_literal: true
class SafeRedirectPathService
def initialize(path, request, allow_subdomain_host: true)
@path = path
@allow_subdomain_host = allow_subdomain_host
@request = request
end
def process
if (allow_subdomain_host && subdomain_host?) || same_host?
path
else
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/adult_keyword_detector.rb | Ruby | mit | 8,966 | main | 2,521 | # frozen_string_literal: true
class AdultKeywordDetector
# TODO: Add "pin-up" and "AB/DL". We may have to revisit our approach so we can include non-alphabet characters in the
# list of adult keywords
ADULT_KEYWORD_REGEX = Regexp.new(
"\\b(" +
["futa", "pussy", "bondage", "bdsm", "lewd", "ahegao", "nu... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/rpush_fcm_app_service.rb | Ruby | mit | 8,966 | main | 696 | # frozen_string_literal: true
class RpushFcmAppService
attr_reader :name
def initialize(name:)
@name = name
end
def first_or_create!
first || create!
end
private
def first
Rpush::Fcm::App.all.select { |app| app.name == name }.first
end
def create!
app = Rpush::Fcm::App.n... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/redis_key.rb | Ruby | mit | 8,966 | main | 4,452 | # frozen_string_literal: true
class RedisKey
class << self
def total_made = "homepage:total_made"
def number_of_creators = "company_page:number_of_creators"
def prev_week_payout_usd = "homepage:prev_week_payout_usd"
def balance_stats_sales_caching_threshold = "balance_stats:sales_caching_threshold"
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/tra_tin_validation_service.rb | Ruby | mit | 8,966 | main | 244 | # frozen_string_literal: true
class TraTinValidationService
attr_reader :tra_tin
def initialize(tra_tin)
@tra_tin = tra_tin
end
def process
return false if tra_tin.blank?
tra_tin.match?(/\A\d{2}-\d{6}-[A-Z]\z/)
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/robots_service.rb | Ruby | mit | 8,966 | main | 1,183 | # frozen_string_literal: true
class RobotsService
SITEMAPS_CACHE_EXPIRY = 1.week.to_i
private_constant :SITEMAPS_CACHE_EXPIRY
SITEMAPS_CACHE_KEY = "sitemap_configs"
private_constant :SITEMAPS_CACHE_KEY
def sitemap_configs
cache_fetch(SITEMAPS_CACHE_KEY, ex: SITEMAPS_CACHE_EXPIRY) do
generate_site... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/abn_validation_service.rb | Ruby | mit | 8,966 | main | 707 | # frozen_string_literal: true
class AbnValidationService
attr_reader :abn_id
def initialize(abn_id)
@abn_id = abn_id
end
def process
return false if abn_id.blank?
response = Rails.cache.fetch("vatstack_validation_#{abn_id}", expires_in: 10.minutes) do
url = "https://api.vatstack.com/v1/val... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/purchasing_power_parity_service.rb | Ruby | mit | 8,966 | main | 741 | # frozen_string_literal: true
class PurchasingPowerParityService
def get_factor(country_code, seller)
factor = if country_code.present?
(ppp_namespace.get(country_code).presence || 1).to_f
else
1.0
end
[factor, seller.min_ppp_factor].max
end
def set_factor(country_code, factor)
p... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/tax_id_validation_service.rb | Ruby | mit | 8,966 | main | 903 | # frozen_string_literal: true
class TaxIdValidationService
attr_reader :tax_id, :country_code
def initialize(tax_id, country_code)
@tax_id = tax_id
@country_code = country_code
end
def process
return false if tax_id.blank?
return false if country_code.blank?
Rails.cache.fetch("tax_id_va... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/save_installment_service.rb | Ruby | mit | 8,966 | main | 6,153 | # frozen_string_literal: true
class SaveInstallmentService
attr_reader :seller, :params, :installment, :product, :preview_email_recipient, :error
def initialize(seller:, params:, installment: nil, preview_email_recipient:)
@seller = seller
@params = params
@installment = installment
@preview_email... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/kra_pin_validation_service.rb | Ruby | mit | 8,966 | main | 242 | # frozen_string_literal: true
class KraPinValidationService
attr_reader :kra_pin
def initialize(kra_pin)
@kra_pin = kra_pin
end
def process
return false if kra_pin.blank?
kra_pin.match?(/\A[A-Z]\d{9}[A-Z]\z/)
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/vat_validation_service.rb | Ruby | mit | 8,966 | main | 1,300 | # frozen_string_literal: true
require "valvat"
class VatValidationService
VIES_LOOKUP_TIMEOUT_SECONDS = 30
attr_reader :vat_id, :valvat
def initialize(vat_id)
@vat_id = vat_id
@valvat = Valvat.new(vat_id)
end
def process
return false if vat_id.nil?
# If UK, just validate VAT id, no looku... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/auto_invoice_eligibility.rb | Ruby | mit | 8,966 | main | 314 | # frozen_string_literal: true
module AutoInvoiceEligibility
def self.eligible?(chargeable)
purchaser = chargeable&.purchaser
billing_detail = purchaser&.billing_detail
return false unless billing_detail&.auto_email_invoice_enabled
return false unless chargeable.has_invoice?
true
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/tip_options_service.rb | Ruby | mit | 8,966 | main | 1,243 | # frozen_string_literal: true
class TipOptionsService
DEFAULT_TIP_OPTIONS = [0, 15, 20, 25]
DEFAULT_DEFAULT_TIP_OPTION = 0
def self.get_tip_options
options = $redis.get(RedisKey.tip_options)
parsed_options = options ? JSON.parse(options) : DEFAULT_TIP_OPTIONS
are_tip_options_valid?(parsed_options) ?... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/notion_api.rb | Ruby | mit | 8,966 | main | 721 | # frozen_string_literal: true
class NotionApi
include HTTParty
base_uri "https://api.notion.com/v1"
def get_bot_token(code:, user:)
body = {
code:,
grant_type: "authorization_code",
external_account: {
key: user.external_id,
name: user.email
}
}
self.class.po... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/admin_funds_csv_report_service.rb | Ruby | mit | 8,966 | main | 729 | # frozen_string_literal: true
class AdminFundsCsvReportService
attr_reader :report
def initialize(report)
@report = report
end
def generate
CsvSafe.generate do |csv|
report.each do |(type, data)|
data.each do |payment_method|
transaction_type_key = type == "Purchases" ? "Sales... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/email_suppression_manager.rb | Ruby | mit | 8,966 | main | 2,506 | # frozen_string_literal: true
class EmailSuppressionManager
SUPPRESSION_LISTS = [:bounces, :spam_reports]
private_constant :SUPPRESSION_LISTS
def initialize(email)
@email = email
end
def reasons_for_suppression
# Scan all subusers for the email and note the reasons for suppressions
sendgrid_sub... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/sitemap_service.rb | Ruby | mit | 8,966 | main | 2,296 | # frozen_string_literal: true
class SitemapService
HOST = UrlService.root_domain_with_protocol
MAX_SITEMAP_LINKS = 50_000
SITEMAP_PATH_MONTHLY = "sitemap/products/monthly"
def generate(date = Date.current)
# Parse date from Sidekiq job argument
date = Date.parse(date) if date.is_a?(String)
period... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/custom_domain_verification_service.rb | Ruby | mit | 8,966 | main | 4,378 | # frozen_string_literal: true
class CustomDomainVerificationService
RESOLVER_TIMEOUT_IN_SECONDS = 5
SSL_CERT_CHECK_CACHE_EXPIRY = 10.days
attr_reader :domain
def initialize(domain:)
@domain = domain
@dns_resolver = Resolv::DNS.new
dns_resolver.timeouts = RESOLVER_TIMEOUT_IN_SECONDS
end
def ... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/stripe_tax_forms_api.rb | Ruby | mit | 8,966 | main | 1,679 | # frozen_string_literal: true
class StripeTaxFormsApi
include HTTParty
def initialize(stripe_account_id:, form_type:, year:)
@stripe_account_id = stripe_account_id
@form_type = form_type
@year = year
end
def download_tax_form
tax_form = tax_forms_by_year[year]
return if tax_form.nil?
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/post_sendgrid_api.rb | Ruby | mit | 8,966 | main | 12,700 | # frozen_string_literal: true
class PostSendgridApi
include Rails.application.routes.url_helpers
include ActionView::Helpers::SanitizeHelper
include MailerHelper, CustomMailerRouteBuilder
_routes.default_url_options = Rails.application.config.action_mailer.default_url_options
MAX_RECIPIENTS = 1_000 # SendGri... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/gst_validation_service.rb | Ruby | mit | 8,966 | main | 726 | # frozen_string_literal: true
class GstValidationService
attr_reader :gst_id
def initialize(gst_id)
@gst_id = gst_id
end
def process
return false if gst_id.blank?
Rails.cache.fetch("iras_validation_#{gst_id}", expires_in: 10.minutes) do
headers = {
"X-IBM-Client-Id" => IRAS_API_ID,... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/invoice_pdf_generator.rb | Ruby | mit | 8,966 | main | 1,026 | # frozen_string_literal: true
class InvoicePdfGenerator
def initialize(chargeable, billing_detail:)
@chargeable = chargeable
@billing_detail = billing_detail
end
def call
address_fields = @billing_detail.to_invoice_address_fields.merge(
country: ISO3166::Country[@billing_detail.country_code]&.... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/helper_user_info_service.rb | Ruby | mit | 8,966 | main | 5,264 | # frozen_string_literal: true
class HelperUserInfoService
include Rails.application.routes.url_helpers
def initialize(email:, recent_purchase_period: 1.year)
@email = email
@recent_purchase_period = recent_purchase_period
end
STRUCTURED_COMMENTS_LIMIT = 50
FALLBACK_AUTHOR_NAME = "System"
def sel... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/offer_code_discount_computing_service.rb | Ruby | mit | 8,966 | main | 4,973 | # frozen_string_literal: true
class OfferCodeDiscountComputingService
# While computing it rejects the product if quantity of the product is greater
# than the quantity left for the offer_code for e.g. Suppose seller adds a
# universal offer code which has 4 quantity left and a user adds three products
# in bu... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/purchase_search_service.rb | Ruby | mit | 8,966 | main | 17,819 | # frozen_string_literal: true
class PurchaseSearchService
DEFAULT_OPTIONS = {
# There must not be any active filters by default: calling .search without any options should return all purchases.
# Values - They can be an ActiveRecord object, an id, or an Array of both
seller: nil,
purchaser: nil,
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/firs_tin_validation_service.rb | Ruby | mit | 8,966 | main | 213 | # frozen_string_literal: true
class FirsTinValidationService
attr_reader :tin
def initialize(tin)
@tin = tin
end
def process
return false if tin.blank?
tin.match?(/^\d{8}-\d{4}$/)
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/regional_vat_id_validation_service.rb | Ruby | mit | 8,966 | main | 1,692 | # frozen_string_literal: true
class RegionalVatIdValidationService
attr_reader :vat_id, :country_code, :state_code
def initialize(vat_id, country_code: nil, state_code: nil)
@vat_id = vat_id
@country_code = country_code
@state_code = state_code
end
def process
return false if vat_id.blank?
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/subscribe_preview_generator_service.rb | Ruby | mit | 8,966 | main | 1,213 | # frozen_string_literal: true
# Used for OpenGraph consumers like: https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/summary-card-with-large-image
class SubscribePreviewGeneratorService
RETINA_PIXEL_RATIO = 2
ASPECT_RATIO = 128/67r
WIDTH = 512
HEIGHT = WIDTH / ASPECT_RATIO
CHROME_ARGS... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/recommended_products_service.rb | Ruby | mit | 8,966 | main | 1,154 | # frozen_string_literal: true
class RecommendedProductsService
MODELS = ["sales"]
MODELS.each do |key|
const_set("MODEL_#{key.upcase}", key)
end
# Returns a ActiveRecord::Relation of ordered products records.
#
# NOTES:
# 1- Because it returns an ActiveRecord::Relation, the result can be used to pre... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/paypal_balance_check_service.rb | Ruby | mit | 8,966 | main | 964 | # frozen_string_literal: true
class PaypalBalanceCheckService
def initialize
@payout_amount_cents = calculate_payout_amount_cents
@current_balance_cents = PaypalPayoutProcessor.current_paypal_balance_cents
@topup_in_transit_cents = PaypalPayoutProcessor.topup_amount_in_transit * 100
end
attr_reader ... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/best_offer_code_service.rb | Ruby | mit | 8,966 | main | 1,989 | # frozen_string_literal: true
class BestOfferCodeService
def initialize(product:, url_code: nil, quantity: 1)
@product = product
@url_code = url_code.presence
@quantity = quantity
@default_code = @product.default_offer_code&.code
end
def result
return nil if @url_code.blank? && @default_code... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/suo_semaphore.rb | Ruby | mit | 8,966 | main | 525 | # frozen_string_literal: true
class SuoSemaphore
class << self
def recurring_charge(subscription_id)
Suo::Client::Redis.new("locks:recurring_charge:#{subscription_id}", default_options)
end
def product_inventory(product_id, extra_options = {})
options = default_options.merge(stale_lock_expir... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/save_utm_link_service.rb | Ruby | mit | 8,966 | main | 1,043 | # frozen_string_literal: true
class SaveUtmLinkService
def initialize(seller:, params:, utm_link: nil)
@seller = seller
@params = params
@utm_link = utm_link
end
def perform
if utm_link.present?
utm_link.update!(params_permitted_for_update)
else
seller.utm_links.create!(params_pe... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/pdf_stamping_service.rb | Ruby | mit | 8,966 | main | 524 | # frozen_string_literal: true
module PdfStampingService
class Error < StandardError; end
extend self
ERRORS_TO_RESCUE = [
PdfStampingService::Stamp::Error,
PDF::Reader::MalformedPDFError
].freeze
def can_stamp_file?(product_file:)
PdfStampingService::Stamp.can_stamp_file?(product_file:)
end
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/expiring_s3_file_service.rb | Ruby | mit | 8,966 | main | 1,118 | # frozen_string_literal: true
class ExpiringS3FileService
DEFAULT_FILE_EXPIRY = 7.days
def initialize(file:,
filename: nil,
path: nil,
prefix: "File",
extension: nil,
expiry: DEFAULT_FILE_EXPIRY,
bucket: S3_BUCKE... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/balances_by_product_service.rb | Ruby | mit | 8,966 | main | 6,122 | # frozen_string_literal: true
class BalancesByProductService
def initialize(user)
@user = user
@products = Link.for_balance_page(@user).select(:id, :name, :user_id).order(id: :desc).load
end
def process
return [] if @products.empty?
aggregations = PurchaseSearchService.search(search_options).ag... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/payout_users_service.rb | Ruby | mit | 8,966 | main | 2,450 | # frozen_string_literal: true
class PayoutUsersService
attr_reader :date, :processor_type, :user_ids, :payout_type
def initialize(date_string:, processor_type:, user_ids:, payout_type: Payouts::PAYOUT_TYPE_STANDARD)
@date = date_string
@processor_type = processor_type
@user_ids = Array.wrap(user_ids)
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/oman_vat_number_validation_service.rb | Ruby | mit | 8,966 | main | 260 | # frozen_string_literal: true
class OmanVatNumberValidationService
attr_reader :vat_number
def initialize(vat_number)
@vat_number = vat_number
end
def process
return false if vat_number.blank?
vat_number.match?(/\AOM\d{10}\z/)
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/default_abandoned_cart_workflow_generator_service.rb | Ruby | mit | 8,966 | main | 1,122 | # frozen_string_literal: true
class DefaultAbandonedCartWorkflowGeneratorService
include Rails.application.routes.url_helpers
def initialize(seller:)
@seller = seller
end
def generate
return if seller.workflows.abandoned_cart_type.exists?
ActiveRecord::Base.transaction do
workflow = seller... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/secure_encrypt_service.rb | Ruby | mit | 8,966 | main | 1,631 | # frozen_string_literal: true
class SecureEncryptService
class Error < StandardError; end
class MissingKeyError < Error; end
class InvalidKeyError < Error; end
class << self
# Encrypts the given text.
#
# @param text [String] The text to encrypt.
# @return [String] The encrypted text.
def ... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/gumroad_daily_analytics_compiler.rb | Ruby | mit | 8,966 | main | 1,189 | # frozen_string_literal: true
class GumroadDailyAnalyticsCompiler
class << self
def compile_gumroad_price_cents(between: nil)
paid_purchases_between(between:)
.sum(:price_cents)
end
def compile_gumroad_fee_cents(between: nil)
purchase_cents = paid_purchases_between(between:)
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/merge_carts_service.rb | Ruby | mit | 8,966 | main | 2,353 | # frozen_string_literal: true
class MergeCartsService
attr_reader :source_cart, :target_cart, :user, :browser_guid, :email
def initialize(source_cart:, target_cart:, user: nil, browser_guid: nil)
@source_cart = source_cart
@target_cart = target_cart
@user = user || @target_cart&.user.presence || @sour... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/post_email_api.rb | Ruby | mit | 8,966 | main | 2,204 | # frozen_string_literal: true
class PostEmailApi
RESEND_EXCLUDED_DOMAINS = ["example.com", "example.org", "example.net", "test.com"]
private_constant :RESEND_EXCLUDED_DOMAINS
def self.process(**args)
post = args[:post]
recipients = args[:recipients]
if Feature.inactive?(:use_resend_for_post_emails,... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/mva_validation_service.rb | Ruby | mit | 8,966 | main | 707 | # frozen_string_literal: true
class MvaValidationService
attr_reader :mva_id
def initialize(mva_id)
@mva_id = mva_id
end
def process
return false if mva_id.blank?
response = Rails.cache.fetch("vatstack_validation_#{mva_id}", expires_in: 10.minutes) do
url = "https://api.vatstack.com/v1/val... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/installment_search_service.rb | Ruby | mit | 8,966 | main | 3,446 | # frozen_string_literal: true
class InstallmentSearchService
DEFAULT_OPTIONS = {
### Filters
# Values can be an ActiveRecord object, an id, or an Array of both
seller: nil,
### Fulltext search
q: nil, # String
### Booleans
exclude_deleted: false,
exclude_workflow_installments: false,
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/email_router_fallback_service.rb | Ruby | mit | 8,966 | main | 568 | # frozen_string_literal: true
class EmailRouterFallbackService
TTL = 5.minutes
class << self
def email_provider_for_two_factor(user:)
return nil unless Feature.active?(:resend_fallback_for_auth_emails)
return nil unless $redis.exists?(RedisKey.email_router_fallback(user.id))
MailerInfo::EMA... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/forfeit_balance_service.rb | Ruby | mit | 8,966 | main | 2,046 | # frozen_string_literal: true
class ForfeitBalanceService
include CurrencyHelper
attr_reader :user, :reason
def initialize(user:, reason:)
@user = user
@reason = reason
end
def process
return unless balance_amount_cents_to_forfeit > 0
balances_to_forfeit.each(&:mark_forfeited!)
balan... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/product_duplicator_service.rb | Ruby | mit | 8,966 | main | 12,863 | # frozen_string_literal: true
class ProductDuplicatorService
REDIS_STORAGE_NS = Redis::Namespace.new(:product_duplicator_service, redis: $redis)
private_constant :REDIS_STORAGE_NS
TIMEOUT_FOR_DUPLICATE_PRODUCT_CACHE = 10.minutes
private_constant :TIMEOUT_FOR_DUPLICATE_PRODUCT_CACHE
DUPLICATING = "product_d... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/clean_us_zip_code_database_file.rb | Ruby | mit | 8,966 | main | 1,384 | # frozen_string_literal: true
# This script manipulates the United States zip codes file to only include information we need (zip codes and states).
# It's only meant to be executed locally.
#
# Steps:
#
# 1. Ask Sahil to purchase an Enterprise license from https://www.unitedstateszipcodes.org/zip-code-database/ with ... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/ssl_certificates/lets_encrypt.rb | Ruby | mit | 8,966 | main | 3,306 | # frozen_string_literal: true
module SslCertificates
class LetsEncrypt < Base
CHALLENGE_TTL = 1.hour.to_i
attr_reader :domain, :certificate_private_key
def initialize(domain)
super()
@domain = domain
@certificate_private_key = OpenSSL::PKey::RSA.new(2048)
end
def process
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/ssl_certificates/generate.rb | Ruby | mit | 8,966 | main | 2,826 | # frozen_string_literal: true
module SslCertificates
class Generate < Base
attr_reader :custom_domain
include ActionView::Helpers::DateHelper
def initialize(custom_domain)
super()
@custom_domain = custom_domain
@domain_verification_service = CustomDomainVerificationService.new(domain... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/ssl_certificates/renew.rb | Ruby | mit | 8,966 | main | 297 | # frozen_string_literal: true
module SslCertificates
class Renew < Base
def process
custom_domains = CustomDomain.alive.certificate_absent_or_older_than(renew_in)
custom_domains.each do |custom_domain|
custom_domain.generate_ssl_certificate
end
end
end
end |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/ssl_certificates/base.rb | Ruby | mit | 8,966 | main | 2,205 | # frozen_string_literal: true
module SslCertificates
class Base
CONFIG_FILE = Rails.root.join("config", "ssl_certificates.yml.erb")
SECRETS_S3_BUCKET = "gumroad-secrets"
attr_reader :renew_in, :rate_limit, :acme_url, :sleep_duration, :rate_limit_hours,
:account_email, :max_retries, :ssl_... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/early_fraud_warning/update_service.rb | Ruby | mit | 8,966 | main | 1,788 | # frozen_string_literal: true
class EarlyFraudWarning::UpdateService
class AlreadyResolvedError < StandardError; end
def initialize(record)
@record = record
@chargeable = record.chargeable
end
def perform!
# We want to preserve the record in its original state just before it was processed by us.
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/follower/create_service.rb | Ruby | mit | 8,966 | main | 2,141 | # frozen_string_literal: true
class Follower::CreateService
delegate :followers, to: :followed_user
def self.perform(**args)
new(**args).perform
end
def initialize(followed_user:, follower_email:, follower_attributes: {}, logged_in_user: nil)
@followed_user = followed_user
@follower_email = follo... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/dispute_evidence/generate_access_activity_logs_service.rb | Ruby | mit | 8,966 | main | 2,508 | # frozen_string_literal: true
class DisputeEvidence::GenerateAccessActivityLogsService
def self.perform(purchase)
new(purchase).perform
end
include ActionView::Helpers::NumberHelper
def initialize(purchase)
@purchase = purchase
@url_redirect = purchase.url_redirect
end
def perform
[
... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/dispute_evidence/generate_uncategorized_text_service.rb | Ruby | mit | 8,966 | main | 2,148 | # frozen_string_literal: true
class DisputeEvidence::GenerateUncategorizedTextService
def self.perform(purchase)
new(purchase).perform
end
include ActionView::Helpers::NumberHelper
attr_reader :purchase
def initialize(purchase)
@purchase = purchase
end
def perform
rows = [
customer_... |
github | antiwork/gumroad | https://github.com/antiwork/gumroad | app/services/dispute_evidence/generate_refund_policy_image_service.rb | Ruby | mit | 8,966 | main | 3,596 | # frozen_string_literal: true
class DisputeEvidence::GenerateRefundPolicyImageService
class ImageTooLargeError < StandardError; end
def self.perform(url:, mobile_purchase:, open_fine_print_modal:, max_size_allowed:)
new(url, mobile_purchase:, open_fine_print_modal:, max_size_allowed:).perform
end
def ini... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.