<commit_before>module Ocawari
  module Strategy
    class Logirl < Parser

      private

      def parse
        if json_response["galleries"].nil?
          images = json_response["bodyContainsImageURLs"].map do |url|
            append_https(update_domain(url))
          end
          
          images << append_https(
            update_domain(json_response["thumbnailURL"]).sub("_large", "")
          )

          images
        else
          json_response["galleries"].map do |mediaobj|
            append_https(mediaobj.dig("media", "full", "url"))
          end
        end
      end

      def article_id
        uri.to_s[/\d+/]
      end

      def api_endpoint 
        URI("https://ucon.favclip.com/api/article/#{article_id}?corePortalID=logirl&visibility=site")
      end

      def json_response
        @json_response ||= JSON.parse(Net::HTTP.get(api_endpoint))
      end

      def append_https(url_fragment)
        "https:#{url_fragment}"
      end

      def update_domain(url)
        url.sub("ex-chaos.appspot", "ucon.favclip")
      end
    end
  end
end
<commit_msg>Move convenience methods to #json_response<commit_after>module Ocawari
  module Strategy
    class Logirl < Parser

      private

      def parse
        if json_response["galleries"].nil?
          images = json_response["bodyContainsImageURLs"].map do |url|
            append_https(update_domain(url))
          end
          
          images << append_https(
            update_domain(json_response["thumbnailURL"]).sub("_large", "")
          )

          images
        else
          json_response["galleries"].map do |mediaobj|
            append_https(mediaobj.dig("media", "full", "url"))
          end
        end
      end

      def json_response
        @json_response ||= begin
          article_id = uri.to_s[/\d+/]
          api_endpoint = URI("https://ucon.favclip.com/api/article/#{article_id}?corePortalID=logirl&visibility=site")
          JSON.parse(Net::HTTP.get(api_endpoint))
        end
      end

      def append_https(url_fragment)
        "https:#{url_fragment}"
      end

      def update_domain(url)
        url.sub("ex-chaos.appspot", "ucon.favclip")
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10914855072463768, 'fraction_numerical': 0.0, 'mean_word_length': 2.026027397260274, 'pattern_counts': {'":': 0, '<': 9, '<?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': '642579', 'n_tokens_mistral': 681, 'n_tokens_neox': 649, 'n_words': 116}