<commit_before>module GoogleContentApi

  class Product
    class << self

      def create_products(sub_account_id, products, dry_run = false)
        token            = Authorization.fetch_token
        products_url     = GoogleContentApi.urls("products", sub_account_id, dry_run)
        xml              = create_product_items_batch_xml(products)
        Faraday.headers  = {
          "Content-Type"   => "application/atom+xml",
          "Authorization"  => "AuthSub token=#{token}"
        }

        response = Faraday.post products_url, xml

        if response.status == 200
          response
        else
          raise "Unable to batch insert products - received status #{response.status}. body: #{response.body}"
        end
      end
      alias_method :create_items, :create_products


      private
        def create_product_items_batch_xml(items)
          mandatory_values = [:id, :title, :description, :link, :image, :content_language, :target_country, :channel]
          # 120.days.from_now.strftime("%Y-%m-%d")

          Nokogiri::XML::Builder.new do |xml|
            xml.feed('xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:batch' => 'http://schemas.google.com/gdata/batch') do
              items.each do |attributes|
                xml.entry('xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:sc' => 'http://schemas.google.com/structuredcontent/2009', 'xmlns:scp' => 'http://schemas.google.com/structuredcontent/2009/products', 'xmlns:app' => 'http://www.w3.org/2007/app') do
                  xml['batch'].operation_(:type => 'INSERT')
                  xml['sc'].id_ attributes[:id]
                  xml.title_ attributes[:title]
                  xml.content_ attributes[:description], :type => 'text'
                  xml.link_(:rel => 'alternate', :type => 'text/html', :href => attributes[:link])
                  xml['sc'].image_link_ attributes[:image]
                  xml['sc'].content_language_ attributes[:content_language]
                  xml['sc'].target_country_   attributes[:target_country]
                  xml['sc'].expiration_date_  attributes[:expiration_date] if attributes[:expiration_date]
                  xml['sc'].adult_ attributes[:adult] if attributes[:adult]
                  xml['scp'].availability_ attributes[:availability]
                  xml['scp'].condition_(attributes[:condition] != 9 ? "new" : "used")
                  xml['scp'].price_ attributes[:price], :unit => attributes[:currency]

                  # optional values
                  add_optional_values(xml, attributes)
                end
              end
            end
          end.to_xml
        end

        def add_optional_values(xml, attributes)
          if attributes[:additional_images]
            attributes[:additional_images].each { |image_link| xml['sc'].additional_image_link_ }
          end
          if attributes[:product_type]
            xml['scp'].product_type_ attributes[:product_type]
          end
          if attributes[:google_product_category]
            xml['scp'].google_product_category_ attributes[:google_product_category]
          end
          if attributes[:brand]
            xml['scp'].brand_ attributes[:brand]
          end
          if attributes[:mpn]
            xml['scp'].mpn_ attributes[:mpn]
          end
          if attributes[:adwords_grouping]
            xml['scp'].adwords_grouping_ attributes[:adwords_grouping]
          end
          if attributes[:adwords_labels]
            xml['scp'].adwords_labels_ attributes[:adwords_labels]
          end
          if attributes[:adwords_redirect]
            xml['scp'].adwords_redirect_ attributes[:adwords_redirect]
          end
          if attributes[:shipping]
            xml['scp'].shipping_ do
              xml['scp'].shipping_country_ attributes[:shipping_country]
              xml['scp'].shipping_price_ attributes[:shipping_price]
              xml['scp'].shipping_service_ attributes[:shipping_service]
            end
          end
          if attributes[:size]
            xml['scp'].size_ attributes[:size]
          end
          if attributes[:gender]
            xml['scp'].gender_ attributes[:gender]
          end
          if attributes[:age_group]
            xml['scp'].age_group_ attributes[:age_group]
          end
        end
    end
  end

end<commit_msg>removing additional items method<commit_after>module GoogleContentApi

  class Product
    class << self

      def create_products(sub_account_id, products, dry_run = false)
        token            = Authorization.fetch_token
        products_url     = GoogleContentApi.urls("products", sub_account_id, dry_run)
        xml              = create_product_items_batch_xml(products)
        Faraday.headers  = {
          "Content-Type"   => "application/atom+xml",
          "Authorization"  => "AuthSub token=#{token}"
        }

        response = Faraday.post products_url, xml

        if response.status == 200
          response
        else
          raise "Unable to batch insert products - received status #{response.status}. body: #{response.body}"
        end
      end
      alias_method :create_items, :create_products


      private
        def create_product_items_batch_xml(items)
          mandatory_values = [:id, :title, :description, :link, :image, :content_language, :target_country, :channel]
          # 120.days.from_now.strftime("%Y-%m-%d")

          Nokogiri::XML::Builder.new do |xml|
            xml.feed('xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:batch' => 'http://schemas.google.com/gdata/batch') do
              items.each do |attributes|
                xml.entry('xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:sc' => 'http://schemas.google.com/structuredcontent/2009', 'xmlns:scp' => 'http://schemas.google.com/structuredcontent/2009/products', 'xmlns:app' => 'http://www.w3.org/2007/app') do
                  xml['batch'].operation_(:type => 'INSERT')
                  xml['sc'].id_ attributes[:id]
                  xml.title_ attributes[:title]
                  xml.content_ attributes[:description], :type => 'text'
                  xml.link_(:rel => 'alternate', :type => 'text/html', :href => attributes[:link])
                  xml['sc'].image_link_ attributes[:image]
                  xml['sc'].content_language_ attributes[:content_language]
                  xml['sc'].target_country_   attributes[:target_country]
                  xml['sc'].expiration_date_  attributes[:expiration_date] if attributes[:expiration_date]
                  xml['sc'].adult_ attributes[:adult] if attributes[:adult]
                  xml['scp'].availability_ attributes[:availability]
                  xml['scp'].condition_(attributes[:condition] != 9 ? "new" : "used")
                  xml['scp'].price_ attributes[:price], :unit => attributes[:currency]

                  # optional values
                 if attributes[:additional_images]
                   attributes[:additional_images].each { |image_link| xml['sc'].additional_image_link_ }
                 end
                 if attributes[:product_type]
                   xml['scp'].product_type_ attributes[:product_type]
                 end
                 if attributes[:google_product_category]
                   xml['scp'].google_product_category_ attributes[:google_product_category]
                 end
                 if attributes[:brand]
                   xml['scp'].brand_ attributes[:brand]
                 end
                 if attributes[:mpn]
                   xml['scp'].mpn_ attributes[:mpn]
                 end
                 if attributes[:adwords_grouping]
                   xml['scp'].adwords_grouping_ attributes[:adwords_grouping]
                 end
                 if attributes[:adwords_labels]
                   xml['scp'].adwords_labels_ attributes[:adwords_labels]
                 end
                 if attributes[:adwords_redirect]
                   xml['scp'].adwords_redirect_ attributes[:adwords_redirect]
                 end
                 if attributes[:shipping]
                   xml['scp'].shipping_ do
                     xml['scp'].shipping_country_ attributes[:shipping_country]
                     xml['scp'].shipping_price_ attributes[:shipping_price]
                     xml['scp'].shipping_service_ attributes[:shipping_service]
                   end
                 end
                 if attributes[:size]
                   xml['scp'].size_ attributes[:size]
                 end
                 if attributes[:gender]
                   xml['scp'].gender_ attributes[:gender]
                 end
                 if attributes[:age_group]
                   xml['scp'].age_group_ attributes[:age_group]
                 end
                end
              end
            end
          end.to_xml
        end
    end
  end

end
{'fraction_non_alphanumeric': 0.1154280551163316, 'fraction_numerical': 0.00677659814772984, 'mean_word_length': 1.9408834274327467, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 88}, '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': '4506553', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2264, 'n_words': 410}