<commit_before>require_relative 'service_core'

module BingAdsReporting
  class AdInsightReal < ServiceCore
    WDSL = 'https://adinsight.api.bingads.microsoft.com/Api/Advertiser/AdInsight/v13/AdInsightService.svc?singleWsdl'.freeze
    FAILED_STATUS = 'Error'.freeze
    SUCCESS_STATUS = 'Success'.freeze

    def generate_report(report_settings, report_params)
      options = default_options(report_settings).merge(report_params)
      call_operation(options)
    end

    private

    def wdsl
      WDSL
    end

    def failed_status
      FAILED_STATUS
    end

    def success_status
      SUCCESS_STATUS
    end

    def report_operation(options)
      BingHelper.camel_case_to_sym(options[:report_type])
    end

    def generate_report_message(options)
      period = options[:period]
      report_type = options[:report_type]

      report_request(period, options, report_type)
    end

    def report_request(period, _options, _report_type)
      {
        'EntityType' => 'Account',
        'SearchParameters' => {
          'SearchParameter' =>  date_range(period)
        },
        '@xsi:type' => 'tns:DateRangeSearchParameter'
      }
    end


    def date_range(period)
      {
        'EndDate' => scope_data_range(period.to),
        'StartDate' => scope_data_range(period.from),
        '@i:type' => 'tns:DateRangeSearchParameter'
      }
    end

    def scope_data_range(period_range)
      {
        ns('Day') => "#{period_range.day}",
        ns('Month') => "#{period_range.month}",
        ns('Year') => "#{period_range.year}"
      }
    end
  end
end
<commit_msg>Add AdInsight Real API<commit_after>require_relative 'service_core'

module BingAdsReporting
  class AdInsightReal < ServiceCore
    WDSL = 'https://adinsight.api.bingads.microsoft.com/Api/Advertiser/AdInsight/v13/AdInsightService.svc?singleWsdl'.freeze
    FAILED_STATUS = 'Error'.freeze
    SUCCESS_STATUS = 'Success'.freeze

    def generate_report(report_settings, report_params)
      options = default_options(report_settings).merge(report_params)
      response = call_operation(options)

      response_result(response, options)
    end

    private

    def wdsl
      WDSL
    end

    def failed_status
      FAILED_STATUS
    end

    def success_status
      SUCCESS_STATUS
    end

    def response_result(response, options)
      tag = response_tag(options)
      response.body[tag]
    end

    def response_tag(options)
      "#{report_operation(options)}_response".to_sym
    end

    def report_operation(options)
      BingHelper.camel_case_to_sym(options[:report_type])
    end

    def generate_report_message(options)
      period = options[:period]
      report_type = options[:report_type]

      report_request(period, options, report_type)
    end

    def report_request(period, _options, _report_type)
      {
        'EntityType' => 'Account',
        'SearchParameters' => {
          'SearchParameter' =>  date_range(period)
        },
        '@xsi:type' => 'tns:DateRangeSearchParameter'
      }
    end


    def date_range(period)
      {
        'EndDate' => scope_data_range(period.to),
        'StartDate' => scope_data_range(period.from),
        '@i:type' => 'tns:DateRangeSearchParameter'
      }
    end

    def scope_data_range(period_range)
      {
        ns('Day') => "#{period_range.day}",
        ns('Month') => "#{period_range.month}",
        ns('Year') => "#{period_range.year}"
      }
    end
  end
end

{'fraction_non_alphanumeric': 0.10576644450883801, 'fraction_numerical': 0.0011590843233845263, 'mean_word_length': 2.8830146231721034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '2545570', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1077, 'n_words': 175}