<commit_before>//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2012 Freshplanet (http://freshplanet.com | <EMAIL>)
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//    http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//  
//////////////////////////////////////////////////////////////////////////////////////

package com.freshplanet.nativeExtensions
{
	import flash.desktop.NativeApplication;
	import flash.events.EventDispatcher;
	import flash.events.InvokeEvent;
	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;
	import flash.system.Capabilities;

	public class Facebook extends EventDispatcher
	{
		// --------------------------------------------------------------------------------------//
		//																						 //
		// 									   CONSTANTS										 //
		// 																						 //
		// --------------------------------------------------------------------------------------//
		
		private static const MAX_BATCH_ITEM:int = 20;
		
		
		// --------------------------------------------------------------------------------------//
		//																						 //
		// 									   PUBLIC API										 //
		// 																						 //
		// --------------------------------------------------------------------------------------//
		
		public static var URL_SUFFIX:String = "";
		
		public function Facebook()
		{
			if (!_instance)
			{
				if (isFacebookSupported)
				{
					_extCtx = ExtensionContext.createExtensionContext("com.freshplanet.AirFacebook", null);
					NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
					if (_extCtx != null)
					{
						_extCtx.addEventListener(StatusEvent.STATUS, onStatus);
					}
					else
					{
						trace('[Facebook] Error - Extension Context is null.');
					}
				}
				_instance = this;
			}
			else
			{
				throw Error('This is a singleton, use getInstance(), do not call the constructor directly.');
			}
		}
		
		public static function getInstance() : Facebook
		{
			return _instance ? _instance : new Facebook();
		}
		
		/** Get Facebook SSO access token (can be used for 2 months). */
		public function getAccessToken() : String
		{
			return _extCtx.call('getAccessToken') as String;
		}
		
		/**
		 * Get expiration timestamp (in seconds since Unix epoch) associated with the current Facebook access token,
		 * or 0 if the session doesn't expire or doesn't exist.
		 */
		public function getExpirationTimestamp() : Number
		{
			return _extCtx.call('getExpirationTimestamp') as Number;
		}
		
		public function isLogIn() : Boolean
		{
			return _extCtx.call('isSessionValid');
		}
		
		public function isLogOut() : Boolean
		{
			return !isLogIn();
		}
		
		public function deleteInvites() : void
		{
			requestWithGraphPath("me/apprequests", onAppRequestReceived);
		}
		
		public function get isFacebookSupported() : Boolean
		{
			return Capabilities.manufacturer.indexOf('iOS') > -1 || Capabilities.manufacturer.indexOf('Android') > -1;
		}
		
		public function initFacebook( appID : String ) : void
		{
			if (isFacebookSupported)
			{
				_extCtx.call('initFacebook', appID, URL_SUFFIX);
			}
		}
		
		public function extendAccessTokenIfNeeded() : void
		{<commit_msg>Fixed a bug caused by the ANE on non-mobile devices<commit_after>//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2012 Freshplanet (http://freshplanet.com | <EMAIL>)
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//    http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//  
//////////////////////////////////////////////////////////////////////////////////////

package com.freshplanet.nativeExtensions
{
	import flash.desktop.NativeApplication;
	import flash.events.EventDispatcher;
	import flash.events.InvokeEvent;
	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;
	import flash.system.Capabilities;

	public class Facebook extends EventDispatcher
	{
		// --------------------------------------------------------------------------------------//
		//																						 //
		// 									   CONSTANTS										 //
		// 																						 //
		// --------------------------------------------------------------------------------------//
		
		private static const MAX_BATCH_ITEM:int = 20;
		
		
		// --------------------------------------------------------------------------------------//
		//																						 //
		// 									   PUBLIC API										 //
		// 																						 //
		// --------------------------------------------------------------------------------------//
		
		public static var URL_SUFFIX:String = "";
		
		public function Facebook()
		{
			if (!_instance)
			{
				if (isFacebookSupported)
				{
					_extCtx = ExtensionContext.createExtensionContext("com.freshplanet.AirFacebook", null);
					NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
					if (_extCtx != null)
					{
						_extCtx.addEventListener(StatusEvent.STATUS, onStatus);
					}
					else
					{
						trace('[Facebook] Error - Extension Context is null.');
					}
				}
				_instance = this;
			}
			else
			{
				throw Error('This is a singleton, use getInstance(), do not call the constructor directly.');
			}
		}
		
		public static function getInstance() : Facebook
		{
			return _instance ? _instance : new Facebook();
		}
		
		/** Get Facebook SSO access token (can be used for 2 months). */
		public function getAccessToken() : String
		{
			if (!isFacebookSupported) return null;
			
			return _extCtx.call('getAccessToken') as String;
		}
		
		/**
		 * Get expiration timestamp (in seconds since Unix epoch) associated with the current Facebook access token,
		 * or 0 if the session doesn't expire or doesn't exist.
		 */
		public function getExpirationTimestamp() : Number
		{
			if (!isFacebookSupported) return 0;
			
			return _extCtx.call('getExpirationTimestamp') as Number;
		}
		
		public function isLogIn() : Boolean
		{
			if (!isFacebookSupported) return false;
			
			return _extCtx.call('isSessionValid');
		}
		
		public function isLogOut() : Boolean
		{
			return !isLogIn();
		}
		
		public function deleteInvites() : void
		{
			requestWithGraphPath("me/apprequests", onAppRequestReceived);
		}
		
		public function get isFacebookSupported() : Boolean
		{
			return Capabilities.manufacturer.indexOf('iOS') > -1 || Capabilities.manufacturer.indexOf('Android') > -1;
		}
		
		public function initFacebook( appID : String ) : void
		{
			if (isFacebookSupported)
			{
				_extCtx.call('initFacebook', appID, URL_SUFFIX);
			}
		}
		
		public function extendAccessTokenIfNeeded() : void
		{
{'fraction_non_alphanumeric': 0.22462627852084974, 'fraction_numerical': 0.003802779963283504, 'mean_word_length': 1.6336325966850829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1461342', 'n_tokens_mistral': 2342, 'n_tokens_neox': 1850, 'n_words': 541}