<commit_before>require 'httparty'
require 'cgi'

class C2DM
  include HTTParty
  default_timeout 30

  attr_accessor :timeout

  AUTH_URL = 'https://www.google.com/accounts/ClientLogin'
  PUSH_URL = 'https://android.apis.google.com/c2dm/send'
  DEFAULT_SOURCE = 'MyCompany-MyAppName-1.0'

  def initialize(username, password, source = DEFAULT_SOURCE)
    post_body = "accountType=HOSTED_OR_GOOGLE&Email=#{username}&Passwd=#{password}&service=ac2dm&source=#{source}"
    params = {
      :body => post_body, 
      :headers => {
        'Content-type' => 'application/x-www-form-urlencoded', 
        'Content-length' => "#{post_body.length}"
      }
    }

    response = self.class.post(AUTH_URL, params)

    raise response if response["Error="] #Raise error in case of auth failure

    response_split = response.body.split("\n")
    @auth_token = response_split[2].gsub("Auth=", "")
  end

  # {
  #   :registration_id => "...",
  #   :data => {
  #     :some_message => "Hi!", 
  #     :another_message => 7
  #   }
  #   :collapse_key => "optional collapse_key string"<commit_msg>Move auth into its own method<commit_after>require 'httparty'
require 'cgi'

class C2DM
  include HTTParty
  default_timeout 30

  attr_accessor :timeout

  AUTH_URL = 'https://www.google.com/accounts/ClientLogin'
  PUSH_URL = 'https://android.apis.google.com/c2dm/send'
  DEFAULT_SOURCE = 'MyCompany-MyAppName-1.0'

  def initialize(username, password, source = DEFAULT_SOURCE)
    auth(username, password, source)
  end

  def auth(username, password, source)
    post_body = "accountType=HOSTED_OR_GOOGLE&Email=#{username}&Passwd=#{password}&service=ac2dm&source=#{source}"
    params = {
      :body => post_body, 
      :headers => {
        'Content-type' => 'application/x-www-form-urlencoded', 
        'Content-length' => "#{post_body.length}"
      }
    }

    response = self.class.post(AUTH_URL, params)

    raise response if response["Error="] #Raise error in case of auth failure

    response_split = response.body.split("\n")
    @auth_token = response_split[2].gsub("Auth=", "")
  end

  # {
  #   :registration_id => "...",
  #   :data => {
  #     :some_message => "Hi!", 
  #     :another_message => 7
  #   }
  #   :collapse_key => "optional collapse_key string"
{'fraction_non_alphanumeric': 0.14971378247468076, 'fraction_numerical': 0.007926023778071334, 'mean_word_length': 3.411650485436893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '2581431', 'n_tokens_mistral': 793, 'n_tokens_neox': 757, 'n_words': 136}