<commit_before># frozen_string_literal: true
# Copyright (C) 2015 Twitter, Inc.

module TwitterAds
  module Tweet

    # cannot instaniate Tweet, only including class methods for stats
    extend TwitterAds::Analytics::ClassMethods

    RESOURCE_COLLECTION = '/0/accounts/%{account_id}/tweet/preview'.freeze # @api private
    RESOURCE_STATS      = '/0/stats/accounts/%{account_id}/organic_tweets'.freeze # @api private
    RESOURCE            = '/0/accounts/%{account_id}/tweet/preview/%{id}'.freeze # @api private
    RESOURCE_CREATE     = '/0/accounts/%{account_id}/tweet'.freeze # @api private

    class << self

      # Returns an HTML preview of a tweet, either new or existing
      #
      # @example
      #   Tweet.preview(account, status: 'potatoes can be deadly...')
      #   Tweet.preview(account, id: 634798319504617472)
      #
      # @param client [Client] The Client object instance.
      # @param account [Account] The Account object instance.
      # @param opts [Hash] A hash of options.
      #
      # @option opts [Integer] :id The ID of an existing Tweet you want to preview.
      # @option opts [String] :status The text of your status update, up to 140 characters.
      # @option opts [Array] :media_ids A list of up to four media IDs to associate with the Tweet.
      # @option opts [String] :card_id The base-36 ID of a revenue card to be embedded in the Tweet.
      # @option opts [String] :preview_target The target to render the Tweet preview
      #   for (eg. TWITTER_TIMELINES).
      #
      # @return [Array] An array containing platforms & their respective tweet previews
      #
      # @since 0.2.0
      # @see https://dev.twitter.com/ads/reference/get/accounts/%3Aaccount_id/tweet/preview
      def preview(account, opts = {})
        resource = opts.key?(:id) ? RESOURCE : RESOURCE_COLLECTION
        resource = resource % { account_id: account.id, id: opts.delete(:id) }

        # url encodes statuss message if present
        opts[:status] = URI.escape(opts[:status]) if opts.key?(:status)

        # handles array to string conversion for media IDs
        if opts.key?(:media_ids) && opts[:media_ids].respond_to?(:join)
          opts[:media_ids] = opts[:media_ids].join(',')
        end

        response = TwitterAds::Request.new(account.client, :get, resource, params: opts).perform
        response.body[:data]<commit_msg>[fix] minor typo in tweet preview code comment<commit_after># frozen_string_literal: true
# Copyright (C) 2015 Twitter, Inc.

module TwitterAds
  module Tweet

    # cannot instaniate Tweet, only including class methods for stats
    extend TwitterAds::Analytics::ClassMethods

    RESOURCE_COLLECTION = '/0/accounts/%{account_id}/tweet/preview'.freeze # @api private
    RESOURCE_STATS      = '/0/stats/accounts/%{account_id}/organic_tweets'.freeze # @api private
    RESOURCE            = '/0/accounts/%{account_id}/tweet/preview/%{id}'.freeze # @api private
    RESOURCE_CREATE     = '/0/accounts/%{account_id}/tweet'.freeze # @api private

    class << self

      # Returns an HTML preview of a tweet, either new or existing
      #
      # @example
      #   Tweet.preview(account, status: 'potatoes can be deadly...')
      #   Tweet.preview(account, id: 634798319504617472)
      #
      # @param client [Client] The Client object instance.
      # @param account [Account] The Account object instance.
      # @param opts [Hash] A hash of options.
      #
      # @option opts [Integer] :id The ID of an existing Tweet you want to preview.
      # @option opts [String] :status The text of your status update, up to 140 characters.
      # @option opts [Array] :media_ids A list of up to four media IDs to associate with the Tweet.
      # @option opts [String] :card_id The base-36 ID of a revenue card to be embedded in the Tweet.
      # @option opts [String] :preview_target The target to render the Tweet preview
      #   for (eg. TWITTER_TIMELINES).
      #
      # @return [Array] An array containing platforms & their respective tweet previews
      #
      # @since 0.2.0
      # @see https://dev.twitter.com/ads/reference/get/accounts/%3Aaccount_id/tweet/preview
      def preview(account, opts = {})
        resource = opts.key?(:id) ? RESOURCE : RESOURCE_COLLECTION
        resource = resource % { account_id: account.id, id: opts.delete(:id) }

        # url encodes status message if present
        opts[:status] = URI.escape(opts[:status]) if opts.key?(:status)

        # handles array to string conversion for media IDs
        if opts.key?(:media_ids) && opts[:media_ids].respond_to?(:join)
          opts[:media_ids] = opts[:media_ids].join(',')
        end

        response = TwitterAds::Request.new(account.client, :get, resource, params: opts).perform
        response.body[:data]
{'fraction_non_alphanumeric': 0.11134278565471226, 'fraction_numerical': 0.014595496246872394, 'mean_word_length': 2.925531914893617, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1862823', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1407, 'n_words': 442}