<commit_before>module Tableau
  class Site

    def initialize(client)
      @client = client
    end

    def all(params={includeProjects: true})
      resp = @client.conn.get "/api/2.0/sites" do |req|
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      data = {sites: []}
      Nokogiri::XML(resp.body).css("tsResponse sites site").each do |s|
        s.css("project").each do |p|
          (@projects ||= []) << {id: p["id"], name: p["name"]}
        end
        data[:sites] << {
          name: "#{s['name']}",
          id: "#{s['id']}",
          content_url: "#{s['contentUrl']}",
          admin_mode: "#{s['adminMode']}",
          user_quota: "#{s['userQuota']}",
          storage_quota: "#{s['storageQuota']}",
          state: "#{s['state']}",
          status_reason: "#{s['statusReason']}",
          projects: @projects
        }
      end
      data.to_json
    end

    def find_by_id(site_id, params={})
      return { error: "site_id is missing." }.to_json unless site_id.nil? || site_id.blank?

      resp = @client.conn.get "/api/2.0/sites/#{site_id}" do |req|
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      normalize_json(resp.body)
    end

    def find_by_site_name(site_name, params={})
      resp = @client.conn.get "/api/2.0/sites/#{site_name}" do |req|
        req.params["key"] = "name"
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      normalize_json(resp.body)
    end

    def find_by_site_url_namespace(site_url_namespace, params={})
      resp = @client.conn.get "/api/2.0/sites/#{site_url_namespace}" do |req|
        req.params["key"] = "contentUrl"
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      normalize_json(resp.body)
    end

    def create(site_object)<commit_msg>return site_id missing error if nil is passed in for site_id ... srsly?<commit_after>module Tableau
  class Site

    def initialize(client)
      @client = client
    end

    def all(params={includeProjects: true})
      resp = @client.conn.get "/api/2.0/sites" do |req|
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      data = {sites: []}
      Nokogiri::XML(resp.body).css("tsResponse sites site").each do |s|
        s.css("project").each do |p|
          (@projects ||= []) << {id: p["id"], name: p["name"]}
        end
        data[:sites] << {
          name: "#{s['name']}",
          id: "#{s['id']}",
          content_url: "#{s['contentUrl']}",
          admin_mode: "#{s['adminMode']}",
          user_quota: "#{s['userQuota']}",
          storage_quota: "#{s['storageQuota']}",
          state: "#{s['state']}",
          status_reason: "#{s['statusReason']}",
          projects: @projects
        }
      end
      data.to_json
    end

    def find_by_id(site_id, params={})
      return { error: "site_id is missing." }.to_json if site_id.nil? || site_id.empty?

      resp = @client.conn.get "/api/2.0/sites/#{site_id}" do |req|
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      normalize_json(resp.body)
    end

    def find_by_site_name(site_name, params={})
      resp = @client.conn.get "/api/2.0/sites/#{site_name}" do |req|
        req.params["key"] = "name"
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      normalize_json(resp.body)
    end

    def find_by_site_url_namespace(site_url_namespace, params={})
      resp = @client.conn.get "/api/2.0/sites/#{site_url_namespace}" do |req|
        req.params["key"] = "contentUrl"
        params.each {|k,v| req.params[k] = v}
        req.headers['X-Tableau-Auth'] = @client.token if @client.token
      end
      normalize_json(resp.body)
    end

    def create(site_object)
{'fraction_non_alphanumeric': 0.1780888030888031, 'fraction_numerical': 0.003861003861003861, 'mean_word_length': 2.425619834710744, 'pattern_counts': {'":': 0, '<': 11, '<?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': '7187002', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1440, 'n_words': 282}