<commit_before>module ScormCloud
  class Base
    attr_reader :appid, :api_url

    def initialize(appid, secret, api_url="https://cloud.scorm.com/api")
      @appid = appid
      @secret = secret
      @api_url = api_url
    end

    def call(method, params = {})
      url = prepare_url(method, params)
      execute_call_xml(url)
    end

    def call_raw(method, params = {})
      url = prepare_url(method, params)
      execute_call_plain(url)
    end     

    def call_url(url)
      execute_call_plain(url)
    end

    def post(method, path, params = {})
      url = URI.parse(prepare_url(method, params))
      body = nil
      File.open(path) do |f|
          req = Net::HTTP::Post::Multipart.new "#{url.path}?#{url.query}",
            "file" => UploadIO.new(f, "application/zip", "scorm.zip")
          res = Net::HTTP.start(url.host, url.port) do |http|
            http.request(req)
          end
          body = res.body
      end
      REXML::Document.new(body)
    end

    def launch_url(method, params = {})
      prepare_url(method, params)
    end

  private

    # Get the URL for the call
    def prepare_url(method, params = {})
      timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
      params[:method] = method
      params[:appid] = @appid
      params[:ts] = timestamp
      html_params = URI.encode_www_form(params)
<commit_msg>Actually use SSL when dealing with HTTPS URLs<commit_after>module ScormCloud
  class Base
    attr_reader :appid, :api_url

    def initialize(appid, secret, api_url="https://cloud.scorm.com/api")
      @appid = appid
      @secret = secret
      @api_url = api_url
    end

    def call(method, params = {})
      url = prepare_url(method, params)
      execute_call_xml(url)
    end

    def call_raw(method, params = {})
      url = prepare_url(method, params)
      execute_call_plain(url)
    end     

    def call_url(url)
      execute_call_plain(url)
    end

    def post(method, path, params = {})
      url = URI.parse(prepare_url(method, params))
      body = nil
      File.open(path) do |f|
          req = Net::HTTP::Post::Multipart.new "#{url.path}?#{url.query}",
            "file" => UploadIO.new(f, "application/zip", "scorm.zip")
          res = Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == "https") do |http|
            http.request(req)
          end
          body = res.body
      end
      REXML::Document.new(body)
    end

    def launch_url(method, params = {})
      prepare_url(method, params)
    end

  private

    # Get the URL for the call
    def prepare_url(method, params = {})
      timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
      params[:method] = method
      params[:appid] = @appid
      params[:ts] = timestamp
      html_params = URI.encode_www_form(params)

{'fraction_non_alphanumeric': 0.12867383512544803, 'fraction_numerical': 0.0, 'mean_word_length': 2.4329643296432963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '2096376', 'n_tokens_mistral': 940, 'n_tokens_neox': 927, 'n_words': 200}