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
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/searchable_resource.rb
Ruby
apache-2.0
187
the-future
6,773
# frozen_string_literal: true module SearchableResource extend ActiveSupport::Concern class_methods do attr_reader :_chewy_index, :_query_fields, :_search_service # Declare the Chewy index to use when searching this resource def index(index) @_chewy_index = index end def search_with(se...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/sti_resource.rb
Ruby
apache-2.0
187
the-future
656
module STIResource extend ActiveSupport::Concern def kind _model.type.demodulize.underscore.dasherize end def kind=(val) _model.type = type_for_kind(val) end def _replace_fields(field_data) type = type_for_kind(field_data[:attributes][:kind]).safe_constantize @model = @model.becomes(type)...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/ignore_preloading_nils.rb
Ruby
apache-2.0
187
the-future
6,516
# frozen_string_literal: true module IgnorePreloadingNils extend ActiveSupport::Concern class_methods do # rubocop:disable all # This beast is copied from jsonapi-resources and as such is subject to their # license (MIT) and not the Kitsu license (Apache-2). # # Why do we have this? Look for ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/authenticated_resource.rb
Ruby
apache-2.0
187
the-future
1,079
module AuthenticatedResource extend ActiveSupport::Concern def token # Sadly this is hardcoded into Pundit-Resources, so we just roll with it @context[:current_user] end def actual_current_user token&.resource_owner end def fetchable_fields all = super policy.try(:visible_attributes, ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/episodic_resource.rb
Ruby
apache-2.0
187
the-future
441
module EpisodicResource extend ActiveSupport::Concern included do attributes :episode_count, :episode_length, :total_length query :episode_count, MediaResource::NUMERIC_QUERY query :episode_length, MediaResource::NUMERIC_QUERY has_many :episodes end def episode_length _model.episode_leng...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/backport_find_records.rb
Ruby
apache-2.0
187
the-future
681
# Backport find_records from cerebris/jsonapi-resources#master module BackportFindRecords extend ActiveSupport::Concern class_methods do def find(filters, options = {}) resources_for(find_records(filters, options), options[:context]) end def find_records(filters, options = {}) context = op...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/resources/concerns/ranked_resource.rb
Ruby
apache-2.0
187
the-future
1,427
module RankedResource extend ActiveSupport::Concern included do class_attribute :_ranked_attributes end class_methods do def ranks(column_name) self._ranked_attributes ||= [] self._ranked_attributes << column_name position_name = "#{column_name}_position" define_method(column...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/oembed_embedder.rb
Ruby
apache-2.0
187
the-future
2,064
class OembedEmbedder < Embedder def to_h { url: url, kind: kind, site: site, title: oembed_data['title'], image: image || thumbnail, video: video }.reject { |_k, v| v.blank? } end def match? oembed_data.present? end private # Get providers from the Provider...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/giphy_media_embedder.rb
Ruby
apache-2.0
187
the-future
523
class GiphyMediaEmbedder < OpenGraphEmbedder GIPHY_MEDIA_URL = %r{\Ahttps?://media\d?\.giphy\.com/media/(?<id>[^/]+)/giphy.*}i def match? GIPHY_MEDIA_URL =~ @url end def kind 'video.gif' end private # Rewrite the Giphy URL from a direct media.giphy.com URL to a giphy.com URL and pull OpenGraph...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/kitsu_embedder.rb
Ruby
apache-2.0
187
the-future
1,731
class KitsuEmbedder < Embedder KITSU_URL = %r{\Ahttps?://(?:www\.|staging\.)?kitsu(?:\.io|\.app)/(?<type>[^/]+)/(?<id>[^/]+).*} def match? KITSU_URL.match(url).present? && subject end def to_h { kind: "link.kitsu.#{type.singularize}", url: url, title: title, description: descri...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/open_graph_embedder.rb
Ruby
apache-2.0
187
the-future
1,121
class OpenGraphEmbedder < Embedder def to_h { kind: kind, url: url, title: title, description: description, site: { name: site_name }, image: image, video: video, audio: audio }.reject { |_k, v| v.blank? } end def match? title.present? end private ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/twitter_card_embedder.rb
Ruby
apache-2.0
187
the-future
857
class TwitterCardEmbedder < Embedder def to_h { kind: kind, url: url, title: card('title'), description: card('description'), site: { name: card('site') }, image: image, video: video }.reject { |_k, v| v.blank? } end def match? kind.present? e...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/image_embedder.rb
Ruby
apache-2.0
187
the-future
508
class ImageEmbedder < Embedder def to_h { kind: 'image', url: url, title: url, image: { url: url, type: content_type, width: image.size[0], height: image.size[1] } } end def match? content_type.present? end private def content_type...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/meta_content_embedder.rb
Ruby
apache-2.0
187
the-future
407
class MetaContentEmbedder < Embedder def to_h { kind: 'link', url: url, title: title, description: meta['description'], site: meta['author'] }.reject { |_k, v| v.blank? } end def match? title.present? end private def meta(key) html.at_css("meta[name='#{key}']...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/nico_video_embedder.rb
Ruby
apache-2.0
187
the-future
415
class NicoVideoEmbedder < OpenGraphEmbedder NICO_URL = %r{\Ahttps?://(?:www\.)?nicovideo.jp/watch/(?<id>sm\d+)} def match? NICO_URL.match(url).present? end def nico_id NICO_URL.match(url)['id'] end def nico_embed_url "http://embed.nicovideo.jp/watch/#{nico_id}?autoplay=1&allowProgrammaticFull...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/embedders/oembed_embedder/providers_list.rb
Ruby
apache-2.0
187
the-future
1,645
class OembedEmbedder class ProvidersList # The source of the providers list on oembed.com PROVIDERS_URL = 'https://oembed.com/providers.json'.freeze # @param list [Array<Hash>] the list of providers from oembed.com def initialize(list) @list = list end # @return [Hash<Regex,Hash>] the ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/typesense_key_service.rb
Ruby
apache-2.0
187
the-future
667
# frozen_string_literal: true class TypesenseKeyService delegate :search_key, to: :@index def initialize(model, token) @model = model @token = token @index = model.typesense_index end def key @key ||= Typesensual.client.keys.generate_scoped_search_key( search_key, scope.query.exce...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/user_deletion_service.rb
Ruby
apache-2.0
187
the-future
2,391
# frozen_string_literal: true class UserDeletionService using UpdateInBatches DELETED_USER_ID = -10 attr_reader :user def initialize(user) @user = user.is_a?(User) ? user : User.find(user) end def delete delete_followers delete_following delete_likes anonymize_mod_stuff Post.uns...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/feed_serializer_service.rb
Ruby
apache-2.0
187
the-future
3,669
class FeedSerializerService class FeedSerializer < JSONAPI::ResourceSerializer def links_hash(source) if source.is_a? ActivityGroupResource {} else super end end def foreign_key_value(source, relationship) related_resource_id = if source.preloaded_fragments.has_key...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/manga_search_service.rb
Ruby
apache-2.0
187
the-future
4,318
# frozen_string_literal: true class MangaSearchService < TypesenseSearchService # Runs the search and returns the list of matching manga in order by their # relevance to the queries. # # @return [Array<Manga>] the list of matching manga def to_a result_ids.map do |id| result_media[id.to_i] end ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/error_i18n.rb
Ruby
apache-2.0
187
the-future
532
class ErrorI18n class << self def translate(error) klass = error.class unless error.is_a?(Class) # Filter ancestry to just descendants of StandardError ancestors = klass.ancestors.select { |c| c <= StandardError } # Convert the class names into I18n keys keys = ancestors.map { |c| c....
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/library_event_service.rb
Ruby
apache-2.0
187
the-future
1,722
# Takes a dirtied LibraryEntry and generates a list of LibraryEvents for the changes class LibraryEventService # The change values to store in the event CHANGES_FOR_EVENT = { rated: %w[rating], progressed: %w[progress reconsume_count volumes_owned time_spent], updated: %w[status reconsume_count], re...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/group_unread_fanout_service.rb
Ruby
apache-2.0
187
the-future
410
class GroupUnreadFanoutService using UpdateInBatches attr_reader :group, :source_user def initialize(group, source_user) @group = group @source_user = source_user end def run! members.update_in_batches('unread_count = unread_count + 1', of: 100) end def members if source_user gro...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/getstream_webhook_parser.rb
Ruby
apache-2.0
187
the-future
318
class GetstreamWebhookParser def initialize(data) @data = data end def each @data.each do |feed| feed['new'].each do |activity| yield feed['feed'], :new, activity end feed['deleted'].each do |activity| yield feed['feed'], :deleted, activity end end end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/feed_query_service.rb
Ruby
apache-2.0
187
the-future
2,871
class FeedQueryService MEDIA_VERBS = %w[updated rated progressed].freeze POST_VERBS = %w[post comment follow review].freeze attr_reader :params, :user def initialize(params, user) @params = params @user = user end def list return @list if @list list = feed.activities list = list.page(...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/search_service.rb
Ruby
apache-2.0
187
the-future
3,446
# Base class for all SearchServices. Abstracts away all the details of managing # a query so the subclasses can focus on just building a solid query. # # @abstract class SearchService include DSL # Builds the query to be used by {#total_count} and {#to_a} # # @abstract Subclass is expected to implement #query...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/one_signal_notification_service.rb
Ruby
apache-2.0
187
the-future
2,667
# frozen_string_literal: true class OneSignalNotificationService class OneSignalError < StandardError; end def initialize(user, activity) @user = user @activity = activity end def run! notification = notify! invalid_players = notification[:results].map do |res| crumb = Sentry::Breadcrum...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/imgix_purge_service.rb
Ruby
apache-2.0
187
the-future
517
module ImgixPurgeService API_KEY = ENV['IMGIX_API_KEY'] API_HOST = 'https://api.imgix.com/' PURGE_ENDPOINT = "#{API_HOST}v2/image/purger".freeze module_function def purge(url) url = url.sub('media.kitsu.app', 'kitsu.imgix.net') http.post(PURGE_ENDPOINT, url: url) end def http @http ||= Fara...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/typesense_search_service.rb
Ruby
apache-2.0
187
the-future
2,583
# frozen_string_literal: true # Provides a helpful base class for search services backed by typesense. # # @abstract class TypesenseSearchService < SearchService # This regex accepts a numerical range or single number # $1 = start, $2 = dot representing closed/open, $3 = end NUMBER = /(\d+(?:\.\d+)?)/ NUMERIC_...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro.rb
Ruby
apache-2.0
187
the-future
2,033
module Zorro # Connect to MongoDB if configured if ENV['AOZORA_MONGO_URL'].present? Client = Mongo::Client.new( ENV['AOZORA_MONGO_URL'], max_pool_size: 24, logger: Rails.logger ) end Cache = LookupCache.new module DB # Create shortcuts to various useful collections if we're con...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/apple_receipt_service.rb
Ruby
apache-2.0
187
the-future
1,293
class AppleReceiptService VERIFICATION_URL = ENV['APPLE_VERIFICATION_URL'] SECRET = ENV['APPLE_VERIFICATION_SECRET'] def initialize(receipt) @receipt = receipt raise AppleReceiptService::Error.for_code(verification_response['status']) unless receipt_valid? end def start_date DateTime.rfc3339(lat...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/google_play_renewal_service.rb
Ruby
apache-2.0
187
the-future
378
class GooglePlayRenewalService def initialize(token) @token = token end def subscription @subscription ||= ProSubscription::GooglePlaySubscription.find_by(billing_id: @token) end def service @service ||= GooglePlaySubscriptionService.new(@token) end def call ProRenewalService.new(user)....
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/pro_renewal_service.rb
Ruby
apache-2.0
187
the-future
877
# Manages the renewal of pro for a user, maintaining streak information, etc. class ProRenewalService # How long after expiration does the user have to renew their sub for the streak to be maintained STREAK_GRACE_PERIOD = 1.day attr_reader :user # @param user [User] the user whose subscription we want to mana...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/library_entry_diff.rb
Ruby
apache-2.0
187
the-future
2,084
# frozen_string_literal: true class LibraryEntryDiff # @param entry [LibraryEntry] the library entry to give difference methods on def initialize(entry) @entry = entry end # @return [Integer] the difference between the new progress and the previous def progress_diff return 0 unless @entry.progress_c...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/algolia_key_service.rb
Ruby
apache-2.0
187
the-future
627
class AlgoliaKeyService def initialize(model, token) @model = model @index = model.algolia_index.safe_constantize @token = token end def key @key ||= Algolia.generate_secured_api_key(search_key, restrictIndices: index, filters: scope) end def index @index.index_name end def scope ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/spamfilter_service.rb
Ruby
apache-2.0
187
the-future
982
# frozen_string_literal: true class SpamfilterService Result = Struct.new(:label, :confidence) do def spam? label == 'Spam' end def ham? label == 'Ham' end def spamminess if spam? confidence else # Ham has a hamminess score (inverse of spamminess) ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/hulu_import.rb
Ruby
apache-2.0
187
the-future
909
module HuluImport HULU_GUID = ENV['HULU_GUID'].freeze HULU_PREFIX = 'https://distribution.hulu.com/api/v1/'.freeze HULU_URL = Addressable::Template.new("#{HULU_PREFIX}/{+path*}?guid=#{HULU_GUID}{&query*}").freeze # @param path [String] the path of the API request to make # @return [String] the URL built for ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/google_play_notification_service.rb
Ruby
apache-2.0
187
the-future
1,116
# Handles processing the event we receive from GCP Pub/Sub, determining if it's a test notification # or a proper subscription notification, then processing the subscription notifications by their # event type. class GooglePlayNotificationService EVENTS = { 1 => :recovered, 2 => :renewed, 3 => :canceled, ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/algolia_graphql_search_service.rb
Ruby
apache-2.0
187
the-future
579
# frozen_string_literal: true class AlgoliaGraphqlSearchService def initialize(model, token) @model = model @index = model.algolia_index.safe_constantize @token = token end def search(query, restrict_searchable_attributes: nil, filters: nil, **opts) opts[:filters] = filters if filters.present? ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/library_gaps_service.rb
Ruby
apache-2.0
187
the-future
1,138
class LibraryGapsService JOINS = Arel.sql(<<-JOINS.squish) LEFT OUTER JOIN media_attribute_votes votes ON votes.media_id = library_entries.media_id AND votes.media_type = library_entries.media_type AND votes.user_id = library_entries.user_id AND votes.vote <> 0 LEFT OUTER JOIN media_re...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/media_follow_service.rb
Ruby
apache-2.0
187
the-future
477
class MediaFollowService attr_reader :user, :media def initialize(user, media) @user = user @media = media @klass = media.class end def create return if ignored? user.notifications.follow(media.airing_feed, scrollback: 0) unless media.status == :finished end def destroy user.noti...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/wordfilter_service.rb
Ruby
apache-2.0
187
the-future
1,019
# frozen_string_literal: true class WordfilterService def initialize(location, text) @location = location @text = text&.unicode_normalize end def hold? wordfilters[:hold].present? end def reject? wordfilters[:reject].present? end def hide? wordfilters[:hide].present? end def r...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/library_search_service.rb
Ruby
apache-2.0
187
the-future
4,393
# Encapsulates the task of searching library entries, taking a query and a user, # and handing us the result set as an Array. Normally, we wouldn't need this # much complexity just to search a model, but library entries are a special # case: we have millions of them, and indexing them directly is grossly # inefficient...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/mongo_processor.rb
Ruby
apache-2.0
187
the-future
1,477
class MongoProcessor include WithProgressBar def initialize(view, batch_size: 5000, in_threads: 20) @view = view @threads = in_threads @batch_size = batch_size @min_queue_size = @batch_size * 0.05 @enum = @view.respond_to?(:batch_size) ? @view.batch_size(batch_size).to_enum : @view.to_enum ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/media_activity_service.rb
Ruby
apache-2.0
187
the-future
1,135
class MediaActivityService attr_reader :library_entry delegate :media, to: :library_entry delegate :user, to: :library_entry def initialize(library_entry) @library_entry = library_entry end def status(status) fill_defaults user.profile_feed.activities.new( foreign_id: "LibraryEntry:#{library...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/google_play_subscription_service.rb
Ruby
apache-2.0
187
the-future
921
# frozen_string_literal: true require 'google/apis/androidpublisher_v3' class GooglePlaySubscriptionService API_KEY = ENV['GOOGLE_PLAY_API_KEY'].freeze PACKAGE_NAME = 'com.everfox.animetrackerandroid' def initialize(token, tier) @token = token @tier = tier end def cancel api.cancel_purchase_su...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/anime_search_service.rb
Ruby
apache-2.0
187
the-future
4,809
# frozen_string_literal: true class AnimeSearchService < TypesenseSearchService # Runs the search and returns the list of matching anime in order by their # relevance to the queries. # # @return [Array<Anime>] the list of matching anime def to_a result_ids.map do |id| result_media[id.to_i] end ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/embed_service.rb
Ruby
apache-2.0
187
the-future
3,148
# frozen_string_literal: true class EmbedService # User-Agent to use for the HTTP request. We list facebookexternalhit and Twitterbot as # compatible to ensure we get served a version with the correct meta tags USER_AGENT = <<-UA.squish.freeze kitsubot/1.0 (+kitsu.app) facebookexternalhit/1.1 (compatibl...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/feed_router.rb
Ruby
apache-2.0
187
the-future
913
# rubocop:disable Metrics/CyclomaticComplexity, Style/PerlBackrefs class FeedRouter def self.route(group, id) case group # Media Pages when 'media', 'media_aggr' case id when /Anime-(\d+)/ then AnimeFeed.new($1) when /Manga-(\d+)/ then MangaFeed.new($1) end # Media Unit Pages ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/stripe_event_service.rb
Ruby
apache-2.0
187
the-future
213
class StripeEventService def initialize(event) @event = event end def call case @event.type when 'invoice.payment_succeeded' StripeRenewalService.new(@event.object).call end end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/trending_service.rb
Ruby
apache-2.0
187
the-future
3,161
class TrendingService EPOCH = Date.new(2030, 1, 1).to_time.to_i ITEM_LIMIT = 200 NETWORK_LIMIT = 20 CATEGORY_LIMIT = 20 TRIM_PROBABILITY = 0.1 attr_reader :namespace, :half_life, :user, :token def initialize(namespace, half_life: 7.days.to_i, user: nil, token: nil) @namespace = namespace @half_l...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/regenerate_stat_service.rb
Ruby
apache-2.0
187
the-future
1,314
class RegenerateStatService class << self def anime_category_breakdown user_stat(:anime, 'Stat::AnimeCategoryBreakdown') end def manga_category_breakdown user_stat(:manga, 'Stat::MangaCategoryBreakdown') end def anime_amount_consumed user_stat(:anime, 'Stat::AnimeAmountConsumed...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/stripe_renewal_service.rb
Ruby
apache-2.0
187
the-future
336
class StripeRenewalService delegate :user, to: :subscription def initialize(invoice) @invoice = invoice end def subscription ProSubscription::StripeSubscription.find_by(billing_id: @invoice.subscription) end def call ProRenewalService.new(user).renew_for(@invoice.period_start, @invoice.period...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/the_tvdb_service.rb
Ruby
apache-2.0
187
the-future
5,931
# frozen_string_literal: true class TheTvdbService class NotFound < StandardError; end class MappingError < StandardError; end BASE_URL = 'https://api.thetvdb.com' API_KEY = ENV['THE_TVDB_API_KEY'].freeze # @return [ActiveRecord::Relation<Mapping>] a scope of Mappings to shows with missing thumbnails def...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/search_service/dsl.rb
Ruby
apache-2.0
187
the-future
2,323
# frozen_string_literal: true # Provides the DSL-like interactive query methods for SearchServices class SearchService module DSL extend ActiveSupport::Concern # @!attribute [r] _queries # @return [Hash] the queries to apply # @!attribute [r] _filters # @return [Hash] the filters to apply ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/hulu_import/hulu_series.rb
Ruby
apache-2.0
187
the-future
1,956
module HuluImport class HuluSeries PAGE_SIZE = 2000 # @param params [Hash] a list of params to pass in the query string to Hulu # @yield [HuluSeries] the series found on Hulu # @return [Enumerator] if no block is given, returns an Enumerator over the series list def self.each(params = {}) r...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/hulu_import/hulu_asset.rb
Ruby
apache-2.0
187
the-future
3,450
module HuluImport class HuluAsset PAGE_SIZE = 2000 EID_REGEX = /.*\?eid=([^&]*).*/ # @param series [HuluSeries] the Series to reference when performing imports # @param params [Hash] a list of params to pass in the query string to Hulu # @yield [HuluAsset] the asset found on Hulu # @return [E...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list.rb
Ruby
apache-2.0
187
the-future
2,242
module ListSync class MyAnimeList attr_reader :linked_account, :agent def initialize(linked_account) @linked_account = linked_account @agent = Mechanize.new do |a| a.user_agent_alias = 'Windows Chrome' end load_session! end def logged_in? track_session do ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/xml_downloader.rb
Ruby
apache-2.0
187
the-future
1,109
module ListSync class MyAnimeList class XMLDownloader def initialize(agent, kind) @agent = agent @kind = kind end def file export_page = @agent.get('https://myanimelist.net/panel.php?go=export') result_page = export_page.form_with(method: 'POST', action: /export/...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/mechanized_edit_page.rb
Ruby
apache-2.0
187
the-future
1,421
module ListSync class MyAnimeList module MechanizedEditPage extend ActiveSupport::Concern included do attr_reader :agent, :media end def initialize(agent, media) @agent = agent @media = media end private def check_authentication! raise ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/login.rb
Ruby
apache-2.0
187
the-future
1,226
module ListSync class MyAnimeList class Login attr_reader :error_message def initialize(agent, username, password) @agent = agent @username = username @password = password end def success? sign_in @signed_in end private def sign...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/library_remover.rb
Ruby
apache-2.0
187
the-future
595
module ListSync class MyAnimeList class LibraryRemover include MechanizedEditPage def run! check_authentication! return if delete_form.nil? && edit_page.uri.to_s.include?('add') copy_csrf_token_into(delete_form) results_page = delete_form.click_button if res...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/xml_generator.rb
Ruby
apache-2.0
187
the-future
1,051
module ListSync class MyAnimeList class XMLGenerator attr_reader :user, :kind def initialize(user, kind) @user = user @kind = kind end def to_xml Nokogiri::XML::Builder.new { |xml| xml.myanimelist do xml.myinfo do xml.user_expor...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/cookie_jar.rb
Ruby
apache-2.0
187
the-future
620
module ListSync class MyAnimeList class CookieJar attr_reader :jar def initialize(jar) @jar = jar end def load_from_linked_account(linked_account) load(linked_account.session_data) if linked_account.session_data end def save_to_linked_account(linked_account) ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/xml_uploader.rb
Ruby
apache-2.0
187
the-future
1,653
module ListSync class MyAnimeList class XMLUploader MEDIA_LINK = %r{(?<media>anime|manga)/(?<id>\d+)} def initialize(agent, xml) @agent = agent @xml = xml end def run! import_page = @agent.get('https://myanimelist.net/import.php') @results_page = import_pa...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/library_updater.rb
Ruby
apache-2.0
187
the-future
3,406
module ListSync class MyAnimeList class LibraryUpdater include MechanizedEditPage attr_reader :library_entry def initialize(agent, library_entry) super(agent, library_entry.media) @library_entry = library_entry end def run! check_authentication! fil...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/list_sync/my_anime_list/xml_generator/row.rb
Ruby
apache-2.0
187
the-future
2,936
module ListSync class MyAnimeList class XMLGenerator class Row attr_reader :entry, :kind, :media, :external_id def initialize(entry, external_id) @entry = entry @kind = entry.kind @media = entry.send(entry.kind) @external_id = external_id end ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/lookup_cache.rb
Ruby
apache-2.0
187
the-future
904
module Zorro class LookupCache def initialize(cache = ActiveSupport::Cache::MemoryStore.new) @cache = cache end def lookup(klass, *ids) ids = [ids].flatten # { 'abcdefjasfasdf' => 'User_abcdefjasfasdf'} klass_name = klass.name cache_keys = ids.map { |id| [id, key_for(klass_n...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer.rb
Ruby
apache-2.0
187
the-future
370
module Zorro module Importer def self.run! # Import Aozora Anime Mappings & Hashtag data AnimeMapper.run! # Create the Aozora groups Groups.create! # Import the users UserImporter.run! # Import posts, threads, and other feed content PostsImporter.run! # Import...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/groups.rb
Ruby
apache-2.0
187
the-future
1,966
module Zorro module Groups GROUP_NAMES = %w[AoTalk AoNews AoMeme AoOfficial AoArt].freeze module_function # Set up all the Aozora groups in the Kitsu database def create! misc = GroupCategory.find_by(slug: 'misc').id GROUP_NAMES.each do |name| # Make the group group = Gro...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/user_conflict_detector.rb
Ruby
apache-2.0
187
the-future
4,003
module Zorro # Service for detecting user conflicts, logging a user in, and displaying conflicts class UserConflictDetector AO_EPOCH = Date.new(2018, 2, 26) def initialize(email: nil, facebook_id: nil, ao_facebook_id: nil, user: nil) @email = email&.strip @facebook_id = facebook_id @ao_fa...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/user_conflict_resolver.rb
Ruby
apache-2.0
187
the-future
2,226
module Zorro # Service for handling the resolution of an account conflict, allowing a user to choose which # account (Aozora or Kitsu) they want to keep, merging UGC between them, and then taking the # profile and library data from the chosen one. class UserConflictResolver delegate :ao_id, to: :@user d...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper.rb
Ruby
apache-2.0
187
the-future
1,242
module Zorro class Wrapper FILE_PREFIX = 'https://aozora-assets.s3.amazonaws.com/'.freeze # @param [String] data The Data to wrap up def initialize(data, collection: nil) @data = data @collection = collection end # The Parse ID is 10 characters of base62, which means there's a 50% ch...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/anime_mapper.rb
Ruby
apache-2.0
187
the-future
3,763
module Zorro # Sets up Mapping data for Aozora, imports hashtags, and potentially creates new anime where we # don't already have them. class AnimeMapper include WithProgressBar SELECTED_FIELDS = %w[myAnimeListID traktID anilistID tvdbID hashtags].map { |k| [k, true] }.to_h.freeze class <<...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/post_wrapper.rb
Ruby
apache-2.0
187
the-future
1,477
module Zorro class Wrapper class PostWrapper < BasePost # Wrap a Post in whichever delegate knows how to handle it properly # # @return [PostWrapper,CommentWrapper,ReplyWrapper] the object wrapping the data def self.wrap(data) # Ignore posts involving Recommendations return...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/reply_wrapper.rb
Ruby
apache-2.0
187
the-future
571
module Zorro class Wrapper class ReplyWrapper < BasePost # @return [Post] the post that this is replying to def post comment.post end # @return [Comment] the comment that this is replying to def comment Zorro::Cache.lookup(Comment, @data['_p_parentPost']) end ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/follow_wrapper.rb
Ruby
apache-2.0
187
the-future
1,305
module Zorro class Wrapper class FollowWrapper < Wrapper # @param sources [Array<String>] Aozora IDs of the users to follow from # @param targets [Array<String>] Aozora IDs of the users to follow to def initialize(sources, targets) sources = Zorro::Cache.lookup(User, sources) tar...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/timeline_post_wrapper.rb
Ruby
apache-2.0
187
the-future
806
module Zorro class Wrapper class TimelinePostWrapper < BasePost # Wrap a TimelinePost in whichever delegate knows how to handle it properly # # @return [TimelinePostWrapper,CommentWrapper,ReplyWrapper] the object wrapping the data def self.wrap(data) # Delegate based on reply level...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/comment_wrapper.rb
Ruby
apache-2.0
187
the-future
479
module Zorro class Wrapper class CommentWrapper < BasePost # @return [Post] the post that this is replying to def post Zorro::Cache.lookup(Post, @data['_p_parentPost'] || @data['_p_thread']) end def to_h super.merge(post: post).compact end # Create the comment...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/thread_wrapper.rb
Ruby
apache-2.0
187
the-future
1,882
module Zorro class Wrapper # A thread on aozora is a top-level post in one of three places: # (1) implicitly wrapping episode discussion (has no content, is auto-generated) # (2) In an aoDiscussion page # (3) On an anime page (right-most tab) class ThreadWrapper < BasePost def self.wrap(d...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/user_wrapper.rb
Ruby
apache-2.0
187
the-future
4,161
module Zorro class Wrapper class UserWrapper < Wrapper # @return [Hash] the associated details document def details @details ||= @data['details'].presence || assoc(@data['_p_details']) || {} end # Aozora wasn't always strictly checking these, so about 15,000 users have non-ASCII c...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/wrapper/base_post.rb
Ruby
apache-2.0
187
the-future
4,477
module Zorro class Wrapper # An abstract class for wrapping common parts of posts from Aozora class BasePost < Wrapper # @return [String] the content for the post def content content = '' content << @data['content'] content << "\n[spoiler]#{@data['spoilerContent']}[/spoiler...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer/post_importer.rb
Ruby
apache-2.0
187
the-future
1,116
module Zorro module Importer # Imports a post from Aozora to Kitsu, and provides a way to import all posts in one fell swoop. class PostImporter include WithProgressBar # Import all posts from Aozora to Kitsu def self.run! Zorro::DB::POST_COLLECTIONS.each { |coll| run_for! coll } ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer/follow_importer.rb
Ruby
apache-2.0
187
the-future
1,815
module Zorro module Importer # Imports a follow from Aozora to Kitsu, and provides a way to import all follows at once. class FollowImporter include WithProgressBar # Import all follows into Kitsu def self.run! bar = progress_bar('Follows', follows_by_user) follows_by_user.e...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer/profile_importer.rb
Ruby
apache-2.0
187
the-future
1,431
module Zorro module Importer # Imports a profile from Aozora to Kitsu class ProfileImporter # Import all users from the Aozora database def self.run! Zorro::DB::User.find.each do |user| yield user new(user).run! end end # @param user [Hash] the user...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer/anime_importer.rb
Ruby
apache-2.0
187
the-future
2,873
module Zorro module Importer # Imports an anime from Aozora to Kitsu. Useful if we don't already have it in our database class AnimeImporter delegate :assoc, to: Zorro::DB # @param aozora_id [String] the ID of the anime in the Aozora database to be imported def initialize(aozora_id) ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer/favorites_importer.rb
Ruby
apache-2.0
187
the-future
1,425
module Zorro module Importer # Imports favorites from Aozora to Kitsu class FavoritesImporter include WithProgressBar # Import all follows into Kitsu def self.run! bar = progress_bar('Favorites', follows_by_user) follows_by_user.each do |follow| new(follow).run! ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/zorro/importer/user_importer.rb
Ruby
apache-2.0
187
the-future
3,840
module Zorro module Importer # Imports a user from the Aozora database into Kitsu, importing the profile and (if there's no # existing library entries) the library. class UserImporter # @param user [Hash] the user document from the Aozora database def initialize(user) @user_doc = user ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/youtube_service/notification_entry.rb
Ruby
apache-2.0
187
the-future
803
class YoutubeService class NotificationEntry attr_reader :entry def initialize(entry) @entry = entry.is_a?(String) ? Nokogiri::XML.fragment(entry) : entry end def channel_id entry.at_xpath('./yt:channelId').text end def video_id entry.at_xpath('./yt:videoId').text end ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/youtube_service/subscription.rb
Ruby
apache-2.0
187
the-future
1,521
class YoutubeService class Subscription TOPIC_URL = Addressable::Template.new( 'https://www.youtube.com/xml/feeds/videos.xml{?channel_id}' ).freeze CALLBACK_URL = Addressable::Template.new( 'https://kitsu.app/api/hooks/{?linked_account}' ).freeze SUBSCRIBE_URL = 'https://pubsubhubbub.a...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/youtube_service/client.rb
Ruby
apache-2.0
187
the-future
949
class YoutubeService class Client API_PREFIX = 'https://www.googleapis.com'.freeze CHANNEL_URL = Addressable::Template.new( "#{API_PREFIX}/youtube/v3/channels{?query*}" ).freeze VERIFY_URL = Addressable::Template.new( "#{API_PREFIX}/oauth2/v3/tokeninfo{?query*}" ).freeze attr_read...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/youtube_service/notification.rb
Ruby
apache-2.0
187
the-future
357
class YoutubeService class Notification attr_reader :atom def initialize(atom) @atom = atom.is_a?(String) ? Nokogiri::XML.parse(atom) : atom end def post!(user) entries.map { |entry| entry.post!(user) } end def entries atom.xpath('//xmlns:entry').map { |entry| Notification...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/the_tvdb_service/row.rb
Ruby
apache-2.0
187
the-future
1,699
# frozen_string_literal: true class TheTvdbService class Row < TheTvdbService attr_reader :media, :data, :tvdb_episode_id, :tvdb_series_id def initialize(media, data, tvdb_series_id, first_number) @media = media @data = data @tvdb_episode_id = data['id'] @tvdb_series_id = tvdb_series...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/services/apple_receipt_service/error.rb
Ruby
apache-2.0
187
the-future
964
class AppleReceiptService class Error < StandardError class InvalidJSON < Error; end class MalformedReceipt < Error; end class UnauthenticatedReceipt < Error; end class InvalidSecret < Error; end class ServerUnavailable < Error; end class TestReceiptOnProduction < Error; end class Producti...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
config/puma.rb
Ruby
apache-2.0
187
the-future
2,862
# frozen_string_literal: true # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for mini...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
config/application.rb
Ruby
apache-2.0
187
the-future
3,927
# frozen_string_literal: true require_relative 'boot' require 'rails' # Pick the frameworks you want: require 'active_model/railtie' require 'active_job/railtie' require 'active_record/railtie' # require 'active_storage/engine' require 'action_controller/railtie' require 'action_mailer/railtie' # require 'action_mail...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
config/sitemap.rb
Ruby
apache-2.0
187
the-future
1,011
unless Rails.env.development? adapter = SitemapGenerator::AwsSdkAdapter.new('kitsu-media') SitemapGenerator::Sitemap.adapter = adapter end SitemapGenerator::Sitemap.default_host = 'https://kitsu.app' SitemapGenerator::Sitemap.create do [Anime, Manga, Drama].each do |model| resource = model.table_name grou...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
config/routes.rb
Ruby
apache-2.0
187
the-future
7,904
# frozen_string_literal: true require 'sidekiq/web' Rails.application.routes.draw do scope '/api' do mount HealthBit.rack => '/_health' post '/graphql', to: 'graphql#execute' get '/playground', to: 'graphql_playground#show' get '/graphiql', to: redirect('/api/playground') scope '/edge' do ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
config/initializers/health_bit.rb
Ruby
apache-2.0
187
the-future
322
HealthBit.configure do |config| config.add('Database Connection') do ApplicationRecord.connection.select_value('SELECT 1') == 1 end config.add('Database Migrations') do ActiveRecord::Migration.check_pending! == nil end config.add('Redis Connection') do $redis.with { |r| r.ping == 'PONG' } end en...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
config/initializers/trusted-proxies.rb
Ruby
apache-2.0
187
the-future
1,256
# frozen_string_literal: true Sentry.with_scope do |scope| scope.set_transaction_name('initializers/trusted-proxies') if Rails.env.production? || Rails.env.staging? cloudflare_ips = begin # Grab Cloudflare IPs %w[ https://www.cloudflare.com/ips-v4 https://www.cloudflare.com/ips-v6 ...