<commit_before>require_relative '../hashtags'
require_relative '../touts'
require_relative '../users'

module Trubl
  module API
    module Search
      # implements http://developer.tout.com/api-overview/search-api

      def search_hashtags(query, per_page=nil, page=nil)
        response = search('hashtags', query, per_page, page)
        Trubl::Hashtags.new.from_response(response)
      end

      def search_users(query, per_page=nil, page=nil)
        response = search('users', query, per_page, page)
        Trubl::Users.new.from_response(response)
      end

      # implements http://developer.tout.com/api/search-api/apimethod/search-touts
      # Additional Options:
      #   :organization_uid => optional, [Array<String>] || <String> of organization_uids
      #   :organization_uids => optional, alias of :organization_uid
      def search_touts(query, per_page=nil, page=nil, filter_options={})
        response = search('touts', query, per_page, page, filter_options)
        Trubl::Touts.new.from_response(response)
      end

      def search_touts_json(query, per_page=nil, page=nil, filter_options={})
        response = search('touts.json', query, per_page, page, filter_options)
        Trubl::Touts.new.from_response(response)
      end

      private

      def search(type, query, per_page=nil, page=nil, filter_options={})
        query_params = {
          q: query,
          per_page: per_page,
          page: page
        }.merge(filter_options.stringify_keys.slice(*filter_options_whitelist)).symbolize_keys
        get("search/#{type}", query: query_params)
      end

      def filter_options_whitelist
        %w{organization_uids organization_uid state public tout_uid tout_uids user_uid user_uids user_id user_ids feed_uids filtered_stream_uids}
      end

    end
  end
end<commit_msg>add with_nested_organizations in the whitelist<commit_after>require_relative '../hashtags'
require_relative '../touts'
require_relative '../users'

module Trubl
  module API
    module Search
      # implements http://developer.tout.com/api-overview/search-api

      def search_hashtags(query, per_page=nil, page=nil)
        response = search('hashtags', query, per_page, page)
        Trubl::Hashtags.new.from_response(response)
      end

      def search_users(query, per_page=nil, page=nil)
        response = search('users', query, per_page, page)
        Trubl::Users.new.from_response(response)
      end

      # implements http://developer.tout.com/api/search-api/apimethod/search-touts
      # Additional Options:
      #   :organization_uid => optional, [Array<String>] || <String> of organization_uids
      #   :organization_uids => optional, alias of :organization_uid
      def search_touts(query, per_page=nil, page=nil, filter_options={})
        response = search('touts', query, per_page, page, filter_options)
        Trubl::Touts.new.from_response(response)
      end

      def search_touts_json(query, per_page=nil, page=nil, filter_options={})
        response = search('touts.json', query, per_page, page, filter_options)
        Trubl::Touts.new.from_response(response)
      end

      private

      def search(type, query, per_page=nil, page=nil, filter_options={})
        query_params = {
          q: query,
          per_page: per_page,
          page: page
        }.merge(filter_options.stringify_keys.slice(*filter_options_whitelist)).symbolize_keys
        get("search/#{type}", query: query_params)
      end

      def filter_options_whitelist
        %w{organization_uids organization_uid state public tout_uid tout_uids user_uid user_uids user_id user_ids feed_uids filtered_stream_uids with_nested_organizations}
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.10401509027216384, 'fraction_numerical': 0.0, 'mean_word_length': 3.316279069767442, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4703666', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1120, 'n_words': 232}