PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/FBConnect/FBSession.h

https://github.com/leecraven/facebook-iphone-sdk
C Header | 203 lines | 51 code | 34 blank | 118 comment | 0 complexity | d30fdee33eb0e032473eb7d007307e3c MD5 | raw file
  1. /*
  2. * Copyright 2009 Facebook
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #import "FBConnect/FBConnectGlobal.h"
  16. @protocol FBSessionDelegate;
  17. @class FBRequest;
  18. /**
  19. * An FBSession represents a single user's authenticated session for a Facebook application.
  20. *
  21. * To create a session, you must use the session key of your application (which can
  22. * be found on the Facebook developer website). You may then use the login dialog to ask
  23. * the user to enter their email address and password. If successful, you will get back a
  24. * session key which can be used to make requests to the Facebook API.
  25. *
  26. * Session keys are cached and stored on the disk of the device so that you do not need to ask
  27. * the user to login every time they launch the app. To restore the last active session, call the
  28. * resume method after instantiating your session.
  29. */
  30. @interface FBSession : NSObject {
  31. NSMutableArray* _delegates;
  32. NSString* _apiKey;
  33. NSString* _apiSecret;
  34. NSString* _getSessionProxy;
  35. FBUID _uid;
  36. NSString* _sessionKey;
  37. NSString* _sessionSecret;
  38. NSDate* _expirationDate;
  39. NSMutableArray* _requestQueue;
  40. NSDate* _lastRequestTime;
  41. int _requestBurstCount;
  42. NSTimer* _requestTimer;
  43. }
  44. /**
  45. * Delegates which implement FBSessionDelegate.
  46. */
  47. @property(nonatomic,readonly) NSMutableArray* delegates;
  48. /**
  49. * The URL used for API HTTP requests.
  50. */
  51. @property(nonatomic,readonly) NSString* apiURL;
  52. /**
  53. * The URL used for secure API HTTP requests.
  54. */
  55. @property(nonatomic,readonly) NSString* apiSecureURL;
  56. /**
  57. * Your application's API key, as passed to the constructor.
  58. */
  59. @property(nonatomic,readonly) NSString* apiKey;
  60. /**
  61. * Your application's API secret, as passed to the constructor.
  62. */
  63. @property(nonatomic,readonly) NSString* apiSecret;
  64. /**
  65. * The URL to call to create a session key after login.
  66. *
  67. * This is an alternative to calling auth.getSession directly using the secret key.
  68. */
  69. @property(nonatomic,readonly) NSString* getSessionProxy;
  70. /**
  71. * The current user's Facebook id.
  72. */
  73. @property(nonatomic,readonly) FBUID uid;
  74. /**
  75. * The current user's session key.
  76. */
  77. @property(nonatomic,readonly) NSString* sessionKey;
  78. /**
  79. * The current user's session secret.
  80. */
  81. @property(nonatomic,readonly) NSString* sessionSecret;
  82. /**
  83. * The expiration date of the session key.
  84. */
  85. @property(nonatomic,readonly) NSDate* expirationDate;
  86. /**
  87. * Determines if the session is active and connected to a user.
  88. */
  89. @property(nonatomic,readonly) BOOL isConnected;
  90. /**
  91. * The globally shared session instance.
  92. */
  93. + (FBSession*)session;
  94. /**
  95. * Sets the globally shared session instance.
  96. *
  97. * This session is not retained, so you are still responsible for retaining it yourself. The
  98. * first session that is created is automatically stored here.
  99. */
  100. + (void)setSession:(FBSession*)session;
  101. /**
  102. * Constructs a session and stores it as the globally shared session instance.
  103. *
  104. * @param secret the application secret (optional)
  105. */
  106. + (FBSession*)sessionForApplication:(NSString*)key secret:(NSString*)secret
  107. delegate:(id<FBSessionDelegate>)delegate;
  108. /**
  109. * Constructs a session and stores it as the global singleton.
  110. *
  111. * @param getSessionProxy a url to that proxies auth.getSession (optional)
  112. */
  113. + (FBSession*)sessionForApplication:(NSString*)key getSessionProxy:(NSString*)getSessionProxy
  114. delegate:(id<FBSessionDelegate>)delegate;
  115. /**
  116. * Constructs a session for an application.
  117. *
  118. * @param secret the application secret (optional)
  119. * @param getSessionProxy a url to that proxies auth.getSession (optional)
  120. */
  121. - (FBSession*)initWithKey:(NSString*)key secret:(NSString*)secret
  122. getSessionProxy:(NSString*)getSessionProxy;
  123. /**
  124. * Begins a session for a user with a given key and secret.
  125. */
  126. - (void)begin:(FBUID)uid sessionKey:(NSString*)sessionKey sessionSecret:(NSString*)sessionSecret
  127. expires:(NSDate*)expires;
  128. /**
  129. * Resumes a previous session whose uid, session key, and secret are cached on disk.
  130. */
  131. - (BOOL)resume;
  132. /**
  133. * Cancels a login (no-op if the login is already complete).
  134. */
  135. - (void)cancelLogin;
  136. /**
  137. * Ends the current session and deletes the uid, session key, and secret from disk.
  138. */
  139. - (void)logout;
  140. /**
  141. * Sends a fully configured request to the server for execution.
  142. */
  143. - (void)send:(FBRequest*)request;
  144. /**
  145. * Deletes all cookies belonging to facebook
  146. */
  147. - (void)deleteFacebookCookies;
  148. @end
  149. ///////////////////////////////////////////////////////////////////////////////////////////////////
  150. @protocol FBSessionDelegate <NSObject>
  151. /**
  152. * Called when a user has successfully logged in and begun a session.
  153. */
  154. - (void)session:(FBSession*)session didLogin:(FBUID)uid;
  155. @optional
  156. /**
  157. * Called when a user closes the login dialog without logging in.
  158. */
  159. - (void)sessionDidNotLogin:(FBSession*)session;
  160. /**
  161. * Called when a session is about to log out.
  162. */
  163. - (void)session:(FBSession*)session willLogout:(FBUID)uid;
  164. /**
  165. * Called when a session has logged out.
  166. */
  167. - (void)sessionDidLogout:(FBSession*)session;
  168. @end