<commit_before>require "pingo/version"
require "pingo/cli"
require "json"
require "typhoeus"

module Pingo
  class Pingo
    INIT_CLIENT = 'initClient'
    PLAY_SOUND  = 'playSound'

    class << self
      def run(model_name)
        new(model_name).instance_eval do
          @partition = get_partition
          @device_id = get_device_id
          play_sound
        end
      end
    end

    def initialize(model_name)
      @model_name = model_name
      @username = ENV['APPLE_ID']
      @password = ENV['<PASSWORD>']
    end

    private
      def get_partition
        post(INIT_CLIENT).headers['X-Apple-MMe-Host']
      end

      def get_device_id
        parse_device_id(post(INIT_CLIENT))
      end

      def parse_device_id(data)
        target_content(data) ? target_content(data)["id"] : nil
      end

      def target_content(data)
        @target_content ||= contents(data).find { |content| match_device?(content) }
      end

      def contents(data)
        JSON.parse(data.body)['content']
      end

      def match_device?(params)
        params['location'] && params['deviceDisplayName'] =~ /#{@model_name}$/
      end

      def play_sound
        post(PLAY_SOUND, generate_body)
      end

      def generate_body
        JSON.generate(play_sound_body)
      end

      def play_sound_body
        {
          clientContext: {
            appName: 'FindMyiPhone',
            appVersion:  '2.0.2',
            shouldLocate: false,
          },
          device: @device_id,
          subject: "Pingo"
        }
      end

      def post(mode, body=nil)
        Typhoeus::Request.post(uri(mode), userpwd: "#{@username}:#{@password}", headers: post_headers, followlocation: true, verbose: true, maxredirs: 1, body: body)
      end

      def post_headers
          {<commit_msg>Allow Uppercase in input of model name<commit_after>require "pingo/version"
require "pingo/cli"
require "json"
require "typhoeus"

module Pingo
  class Pingo
    INIT_CLIENT = 'initClient'
    PLAY_SOUND  = 'playSound'

    class << self
      def run(model_name)
        new(model_name).instance_eval do
          @partition = get_partition
          @device_id = get_device_id
          play_sound
        end
      end
    end

    def initialize(model_name)
      @model_name = model_name
      @username = ENV['APPLE_ID']
      @password = ENV['<PASSWORD>']
    end

    private
      def get_partition
        post(INIT_CLIENT).headers['X-Apple-MMe-Host']
      end

      def get_device_id
        parse_device_id(post(INIT_CLIENT))
      end

      def parse_device_id(data)
        target_content(data) ? target_content(data)["id"] : nil
      end

      def target_content(data)
        @target_content ||= contents(data).find { |content| match_device?(content) }
      end

      def contents(data)
        JSON.parse(data.body)['content']
      end

      def match_device?(params)
        params['location'] && params['deviceDisplayName'] =~ /#{@model_name}$/i
      end

      def play_sound
        post(PLAY_SOUND, generate_body)
      end

      def generate_body
        JSON.generate(play_sound_body)
      end

      def play_sound_body
        {
          clientContext: {
            appName: 'FindMyiPhone',
            appVersion:  '2.0.2',
            shouldLocate: false,
          },
          device: @device_id,
          subject: "Pingo"
        }
      end

      def post(mode, body=nil)
        Typhoeus::Request.post(uri(mode), userpwd: "#{@username}:#{@password}", headers: post_headers, followlocation: true, verbose: true, maxredirs: 1, body: body)
      end

      def post_headers
          {
{'fraction_non_alphanumeric': 0.10286028602860287, 'fraction_numerical': 0.0022002200220022, 'mean_word_length': 2.1708805579773323, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '2166171', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1129, 'n_words': 232}