<commit_before>- content_for :title, "How to use the API"
%h1= yield :title

%p The API allows you to programatically retrieve data from any public scraper using an SQL query. It's all pretty easy.

%pre
  %code
    GET #{api_url_in_html(content_tag(:em, "[scraper]"), content_tag(:em, "[format]"), content_tag(:em, "[sql]"), "")}

%p With a simple header for authentication

%pre
  %code
    = api_header(content_tag(:em, "[api_key]"))

%h2 Parameters

= semantic_form_for @scraper, html: {class: "form-horizontal"} do |f|
  = f.inputs do
    .string.input.optional.stringish.form-group#scraper_full_name_input
      %label.control-label.col-sm-1(for="scraper_full_name") [scraper]
      .col-sm-5
        %input.form-control#scraper_full_name(maxlength="255" name="scraper[full_name]" type="text" value="#{@scraper.full_name}")
        %span.help-block The full name of the scraper as seen in the url
    .string.input.optional.stringish.form-group#query_input
      %label.control-label.col-sm-1(for="query") [sql]
      .col-sm-5
        %input.form-control#query(maxlength="255" name="query" type="text" value="#{@query}")
        %span.help-block
          The SQL query to perform on the scraper data.
          Ensure it is #{link_to "url encoded", "https://en.wikipedia.org/wiki/Percent-encoding"}.
    .string.input.optional.stringish.form-group#format_input
      %label.control-label.col-sm-1(for="format") [format]
      .col-sm-3
        %select.form-control#format(name="format")
          = options_for_select(["json", "csv"])
        %span.help-block
          Format of outputted data
    - if current_user
      .row
        .col-sm-6
          .string.input.optional.stringish.form-group#api_key_input
            %label.control-label.col-sm-2(for="api_key") [api_key]
            .col-sm-10
              %p.form-control-static#api_key= current_user.api_key
              %span.help-block
                Don't tell anyone else what the api key is
        .col-sm-3
          .select.input.optional.form-group#owner_input
            %select.form-control#owner(name="owner")
              = options_for_select(current_user.all_owners.map{|o| [o.nickname, o.api_key]})
            %span.help-block
              Choose which api key you want to use
    - else
      .row
        .col-sm-6
          .string.input.optional.stringish.form-group#api_key_input
            %label.control-label.col-sm-2(for="api_key") [api_key]
            .col-sm-10
              %p#api_key
                = button_link_to "sign in with GitHub", user_omniauth_authorize_path(:github)
    .string.input.optional.stringish.form-group#callback_input
      %label.control-label.col-sm-1(for="callback") [callback]
      .col-sm-5
        %input.form-control#callback(maxlength="255" name="query" type="text")
        %span.help-block
          (Optional) To return JSONP set "callback" to the name of your javascript callback function.

%h2 Example
%p
  To do the API query with the values above

%pre
  %code
    - if current_user
      = curl_command(content_tag(:span, current_user.api_key, class: "api_key"), content_tag(:span, @scraper.full_name, class: "full_name"), content_tag(:span, "json", class: "format"), content_tag(:span, CGI::escape(@query), class: "query"), content_tag(:span, "", class: "callback"))
    - else
      = curl_command(content_tag(:em, "[api_key]"), content_tag(:span, @scraper.full_name, class: "full_name"), content_tag(:span, "json", class: "format"), content_tag(:span, CGI::escape(@query), class: "query"), content_tag(:span, "", class: "callback"))

:javascript
  $(function() {
    function update_full_name() {
      $("code span.full_name").html($("#scraper_full_name").val());
    }

    function update_query() {
      $("code span.query").html(encodeURIComponent($("#query").val()));
    }

    function update_api_key() {
      api_key = $("#owner").val();
      $("#api_key").html(api_key);
      $("code span.api_key").html(api_key);
    }

    function update_format() {
      $("code span.format").html($("#format").val());
    }

    function update_callback() {
      var v = $("#callback").val();
      if (v == "") {
        $("code span.callback").html("");
      }
      else {
        $("code span.callback").html("&callback=" + v);
      }
    }

    update_full_name();
    update_query();
    update_api_key();
    update_format();
    update_callback();

    $("#scraper_full_name").change(update_full_name);
    $("#scraper_full_name").keyup(update_full_name);
    $("#query").change(update_query);
    $("#query").keyup(update_query);
    $("#owner").change(update_api_key);
    $("#format").change(update_format);
    $("#callback").change(update_callback);
    $("#callback").keyup(update_callback);
  });<commit_msg>Only show the callback option when json is selected as the format<commit_after>- content_for :title, "How to use the API"
%h1= yield :title

%p The API allows you to programatically retrieve data from any public scraper using an SQL query. It's all pretty easy.

%pre
  %code
    GET #{api_url_in_html(content_tag(:em, "[scraper]"), content_tag(:em, "[format]"), content_tag(:em, "[sql]"), "")}

%p With a simple header for authentication

%pre
  %code
    = api_header(content_tag(:em, "[api_key]"))

%h2 Parameters

= semantic_form_for @scraper, html: {class: "form-horizontal"} do |f|
  = f.inputs do
    .string.input.optional.stringish.form-group#scraper_full_name_input
      %label.control-label.col-sm-1(for="scraper_full_name") [scraper]
      .col-sm-5
        %input.form-control#scraper_full_name(maxlength="255" name="scraper[full_name]" type="text" value="#{@scraper.full_name}")
        %span.help-block The full name of the scraper as seen in the url
    .string.input.optional.stringish.form-group#query_input
      %label.control-label.col-sm-1(for="query") [sql]
      .col-sm-5
        %input.form-control#query(maxlength="255" name="query" type="text" value="#{@query}")
        %span.help-block
          The SQL query to perform on the scraper data.
          Ensure it is #{link_to "url encoded", "https://en.wikipedia.org/wiki/Percent-encoding"}.
    .string.input.optional.stringish.form-group#format_input
      %label.control-label.col-sm-1(for="format") [format]
      .col-sm-3
        %select.form-control#format(name="format")
          = options_for_select(["json", "csv"])
        %span.help-block
          Format of outputted data
    - if current_user
      .row
        .col-sm-6
          .string.input.optional.stringish.form-group#api_key_input
            %label.control-label.col-sm-2(for="api_key") [api_key]
            .col-sm-10
              %p.form-control-static#api_key= current_user.api_key
              %span.help-block
                Don't tell anyone else what the api key is
        .col-sm-3
          .select.input.optional.form-group#owner_input
            %select.form-control#owner(name="owner")
              = options_for_select(current_user.all_owners.map{|o| [o.nickname, o.api_key]})
            %span.help-block
              Choose which api key you want to use
    - else
      .row
        .col-sm-6
          .string.input.optional.stringish.form-group#api_key_input
            %label.control-label.col-sm-2(for="api_key") [api_key]
            .col-sm-10
              %p#api_key
                = button_link_to "sign in with GitHub", user_omniauth_authorize_path(:github)
    .string.input.optional.stringish.form-group#callback_input
      %label.control-label.col-sm-1(for="callback") [callback]
      .col-sm-5
        %input.form-control#callback(maxlength="255" name="query" type="text")
        %span.help-block
          (Optional) To return JSONP set "callback" to the name of your javascript callback function.

%h2 Example
%p
  To do the API query with the values above

%pre
  %code
    - if current_user
      = curl_command(content_tag(:span, current_user.api_key, class: "api_key"), content_tag(:span, @scraper.full_name, class: "full_name"), content_tag(:span, "json", class: "format"), content_tag(:span, CGI::escape(@query), class: "query"), content_tag(:span, "", class: "callback"))
    - else
      = curl_command(content_tag(:em, "[api_key]"), content_tag(:span, @scraper.full_name, class: "full_name"), content_tag(:span, "json", class: "format"), content_tag(:span, CGI::escape(@query), class: "query"), content_tag(:span, "", class: "callback"))

:javascript
  $(function() {
    function update_full_name() {
      $("code span.full_name").html($("#scraper_full_name").val());
    }

    function update_query() {
      $("code span.query").html(encodeURIComponent($("#query").val()));
    }

    function update_api_key() {
      api_key = $("#owner").val();
      $("#api_key").html(api_key);
      $("code span.api_key").html(api_key);
    }

    function update_format() {
      var format = $("#format").val();
      $("code span.format").html(format);
      if (format == "json") {
        $("#callback_input").show("fast");
      }
      else {
        $("#callback_input").hide("fast");
        $("#callback").val("");
        update_callback();
      }
    }

    function update_callback() {
      var v = $("#callback").val();
      if (v == "") {
        $("code span.callback").html("");
      }
      else {
        $("code span.callback").html("&callback=" + v);
      }
    }

    update_full_name();
    update_query();
    update_api_key();
    update_format();
    update_callback();

    $("#scraper_full_name").change(update_full_name);
    $("#scraper_full_name").keyup(update_full_name);
    $("#query").change(update_query);
    $("#query").keyup(update_query);
    $("#owner").change(update_api_key);
    $("#format").change(update_format);
    $("#callback").change(update_callback);
    $("#callback").keyup(update_callback);
  });
{'fraction_non_alphanumeric': 0.16454924280922859, 'fraction_numerical': 0.005894908019107633, 'mean_word_length': 3.069478908188586, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4922448', 'n_tokens_mistral': 3222, 'n_tokens_neox': 3203, 'n_words': 604}