Created
October 23, 2012 23:15
-
-
Save prabirshrestha/3942407 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace FacebookApi | |
| { | |
| using System; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| public class FacebookApi | |
| { | |
| private Func<object, string> serializeJson; | |
| private static Func<object, string> defaultJsonSerializer; | |
| private Func<string, Type, object> deserializeJson; | |
| private static Func<string, Type, object> defaultJsonDeserializer; | |
| private Func<Uri, HttpWebRequestWrapper> httpWebRequestFactory; | |
| private static Func<Uri, HttpWebRequestWrapper> defaultHttpWebRequestFactory; | |
| private string accessToken; | |
| public virtual string AccessToken | |
| { | |
| get { return accessToken; } | |
| set { accessToken = value; } | |
| } | |
| public virtual string AppId { get; set; } | |
| public virtual string AppSecret { get; set; } | |
| public virtual bool IsSecureConnection { get; set; } | |
| public virtual bool UseFacebookBeta { get; set; } | |
| public FacebookApi() | |
| { | |
| } | |
| public FacebookApi(string accessToken) | |
| { | |
| this.accessToken = accessToken; | |
| } | |
| public static void SetDefaultHttpWebRequestFactory(Func<Uri, HttpWebRequestWrapper> httpWebRequestFactory) | |
| { | |
| defaultHttpWebRequestFactory = httpWebRequestFactory; | |
| } | |
| public static void SetDefaultJsonSerializers(Func<object, string> jsonSerializer, Func<string, Type, object> jsonDeserializer) | |
| { | |
| defaultJsonSerializer = jsonSerializer ?? SimpleJson.SerializeObject; | |
| defaultJsonDeserializer = jsonDeserializer ?? SimpleJson.DeserializeObject; | |
| } | |
| public void SetHttpWebRequestFactory(Func<Uri, HttpWebRequestWrapper> httpWebRequestFactory) | |
| { | |
| this.httpWebRequestFactory = httpWebRequestFactory; | |
| } | |
| public void SetJsonSerializers(Func<object, string> jsonSerializer, Func<string, Type, object> jsonDeserializer) | |
| { | |
| this.serializeJson = jsonSerializer; | |
| this.deserializeJson = jsonDeserializer; | |
| } | |
| public virtual Task<object> ApiAsync(string httpMethod, string path, object parameters, Type resultType) | |
| { | |
| return ApiAsync(httpMethod, path, parameters, resultType); | |
| } | |
| public virtual Task<object> ApiAsync(string httpMethod, string path, object parameters, Type resultType, CancellationToken cancellationToken) | |
| { | |
| return ApiAsync(httpMethod, path, parameters, resultType, cancellationToken, null, null); | |
| } | |
| public virtual async Task<object> ApiAsync(string httpMethod, string path, object parameters, Type resultType, CancellationToken cancellationToken, | |
| IProgress<FacebookProgress> uploadProgress, IProgress<FacebookProgress> downloadProgress) | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| public virtual Task<TResult> ApiAsync<TResult>(string httpMethod, string path, object parameters) | |
| { | |
| return ApiAsync<TResult>(httpMethod, path, parameters); | |
| } | |
| public virtual Task<TResult> ApiAsync<TResult>(string httpMethod, string path, object parameters, CancellationToken cancellationToken) | |
| { | |
| return ApiAsync<TResult>(httpMethod, path, parameters, cancellationToken, null, null); | |
| } | |
| public virtual async Task<TResult> ApiAsync<TResult>(string httpMethod, string path, object parameters, CancellationToken cancellationToken, | |
| IProgress<FacebookProgress> uploadProgress, IProgress<FacebookProgress> downloadProgress) | |
| { | |
| return (TResult)await ApiAsync(httpMethod, path, parameters, typeof(TResult), cancellationToken, uploadProgress, downloadProgress); | |
| } | |
| public virtual IAsyncResult BeginApiAsync(string httpMethod, string path, object parameters, Type resultType, object state, AsyncCallback callback) | |
| { | |
| return ApiAsync(httpMethod, path, parameters, resultType, CancellationToken.None); | |
| } | |
| public virtual object EndApiAsync(IAsyncResult asyncResult) | |
| { | |
| var task = (Task<object>)asyncResult; | |
| return task.Result; | |
| } | |
| public virtual IAsyncResult BeginApiAsync<TResult>(string httpMethod, string path, object parameters, object state, AsyncCallback callback) | |
| { | |
| return ApiAsync<TResult>(httpMethod, path, parameters, CancellationToken.None); | |
| } | |
| public virtual TResult EndApiAsync<TResult>(IAsyncResult asyncResult) | |
| { | |
| var task = (Task<TResult>)asyncResult; | |
| return task.Result; | |
| } | |
| } | |
| public class FacebookProgress | |
| { | |
| } | |
| public class FacebookMediaStream | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment