<commit_before>require 'bra/driver_common/requests/poster'

module Bra
  module DriverCommon
    module Requests
      # Abstract object for handling POSTs in Player objects
      #
      # This deals with the various protocols POSTing objects handles, so that
      # drivers can override the protocol methods they implement
      class PlayerPoster < Poster
        # Supported URL protocols in this version of the bra API.
        URL_TYPES = {
          playlist: :item_from_playlist_url
        }

        # Supported hash types in this version of the bra API.
        HASH_TYPES = {
          playlist: :item_from_playlist_hash
        }

        # These are the overridable functions a concrete PlayerPoster can fill
        # in.  They are defined in this class as raising a NotSupportedByDriver
        # exception.
        TO_OVERRIDE = [
          :item_from_local_playlist,  # index
          :item_from_other_playlist   # playlist_id, index
        ]

        # Set up the main Poster methods to reference the jump tables above
        %w{url hash}.each do |style|
          jump_table = const_get("#{style.upcase}_TYPES")
          jump_table.default = :unsupported_protocol

          # Assume nothing other than :item reaches here.
          define_method(style) do |type, rest|
            send(jump_table[type], rest)
          end
        end
<commit_msg>Convert player_handler to handler subclass.<commit_after>require 'bra/driver_common/requests/poster'

module Bra
  module DriverCommon
    module Requests
      # Extension of request handler to deal with the common Player APIs
      #
      # This deals with the various protocols for POSTing player items, so that
      # drivers can override the protocol methods they implement
      class PlayerHandler < Handler
        use_post_payload_processor

        # Supported URL protocols in this version of the bra API.
        URL_TYPES = {
          playlist: :item_from_playlist_url
        }

        # Supported hash types in this version of the bra API.
        HASH_TYPES = {
          playlist: :item_from_playlist_hash
        }

        # These are the overridable functions a concrete PlayerPoster can fill
        # in.  They are defined in this class as raising a NotSupportedByDriver
        # exception.
        TO_OVERRIDE = [
          :item_from_local_playlist,  # index
          :item_from_other_playlist   # playlist_id, index
        ]

        # Set up the main Poster methods to reference the jump tables above
        %w{url hash}.each do |style|
          jump_table = const_get("#{style.upcase}_TYPES")
          jump_table.default = :unsupported_protocol

          # Assume nothing other than :item reaches here.
          define_method(style) do |type, rest|
            send(jump_table[type], rest)
          end
        end

{'fraction_non_alphanumeric': 0.05266878755744079, 'fraction_numerical': 0.0, 'mean_word_length': 2.275462962962963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5318199', 'n_tokens_mistral': 760, 'n_tokens_neox': 742, 'n_words': 263}