<commit_before>class User < ActiveRecord::Base
  require 'geocoder'

  attr_accessible :provider, :uid, :name, :email, :access_token, :refresh_token, :lat, :long, :last_passes_call
  reverse_geocoded_by :lat, :long

  validates_presence_of :name
  after_create :compare_location!
  after_create :subscribe_to_iss

  has_many :passes
  has_many :subscriptions
  has_many :spacecrafts, through: :subscriptions

  def self.create_with_omniauth(auth)
   where(auth.slice(:provider, :uid)).first_or_create do |user|
      user.provider = auth['provider']
      user.uid = auth['uid']
      user.access_token = auth['credentials']['token']
      user.refresh_token = auth['credentials']['refresh_token']
      if auth['info']
        user.name = auth['info']['name'] || ""
        user.email = auth['info']['email'] || ""
      end
    end
  end

  def refresh_access_token(uri,client_id,client_secret)
    if self.refresh_token
      begin
        response = HTTParty.post(uri, :body => {refresh_token: self.refresh_token, client_id: client_id, client_secret: client_secret, grant_type:'refresh_token'})
        if self.access_token = response['access_token']
          self.save
          return true
        end
        return false
      rescue
      end
    end
    return false
  end

  def send_glass_card(card = Hash.new,ding = true)
    # card[:html] ||= "<article class=\'photo\'>\n  <img src=\'https://mirror-api-playground.appspot.com/links/filoli-spring-fling.jpg\' width=\'100%\' height=\'100%\'>\n  <div class=\'photo-overlay\'/>\n  <section>\n <p class=\'text-auto-size\'>Spring Fling Fundraiser at Filoli</p>\n  </section>\n</article>\n"
    card[:bundleId] = "iss_flyby"
    card[:notification] = {level:"DEFAULT"} if ding
    #TODO #30 set up share subscription to handle sharing by users: {action:"SHARE"}
    card[:menuItems] = [{action:"TOGGLE_PINNED"}]

    begin
      return HTTParty.post('https://www.googleapis.com/mirror/v1/timeline', body: card.to_json, headers: { 'Content-Type' => 'application/json', 'Authorization' => 'Bearer '+self.access_token })<commit_msg>disables pinning<commit_after>class User < ActiveRecord::Base
  require 'geocoder'

  attr_accessible :provider, :uid, :name, :email, :access_token, :refresh_token, :lat, :long, :last_passes_call
  reverse_geocoded_by :lat, :long

  validates_presence_of :name
  after_create :compare_location!
  after_create :subscribe_to_iss

  has_many :passes
  has_many :subscriptions
  has_many :spacecrafts, through: :subscriptions

  def self.create_with_omniauth(auth)
   where(auth.slice(:provider, :uid)).first_or_create do |user|
      user.provider = auth['provider']
      user.uid = auth['uid']
      user.access_token = auth['credentials']['token']
      user.refresh_token = auth['credentials']['refresh_token']
      if auth['info']
        user.name = auth['info']['name'] || ""
        user.email = auth['info']['email'] || ""
      end
    end
  end

  def refresh_access_token(uri,client_id,client_secret)
    if self.refresh_token
      begin
        response = HTTParty.post(uri, :body => {refresh_token: self.refresh_token, client_id: client_id, client_secret: client_secret, grant_type:'refresh_token'})
        if self.access_token = response['access_token']
          self.save
          return true
        end
        return false
      rescue
      end
    end
    return false
  end

  def send_glass_card(card = Hash.new,ding = true)
    # card[:html] ||= "<article class=\'photo\'>\n  <img src=\'https://mirror-api-playground.appspot.com/links/filoli-spring-fling.jpg\' width=\'100%\' height=\'100%\'>\n  <div class=\'photo-overlay\'/>\n  <section>\n <p class=\'text-auto-size\'>Spring Fling Fundraiser at Filoli</p>\n  </section>\n</article>\n"
    card[:bundleId] = "iss_flyby"
    card[:notification] = {level:"DEFAULT"} if ding
    #TODO #30 set up share subscription to handle sharing by users: {action:"SHARE"}
    #card[:menuItems] = [{action:"TOGGLE_PINNED"}]

    begin
      return HTTParty.post('https://www.googleapis.com/mirror/v1/timeline', body: card.to_json, headers: { 'Content-Type' => 'application/json', 'Authorization' => 'Bearer '+self.access_token })
{'fraction_non_alphanumeric': 0.14767831498324557, 'fraction_numerical': 0.00430828147438966, 'mean_word_length': 3.7924311926605503, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '1632139', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1352, 'n_words': 275}