FacebookAgent.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. Copyright (c) 2014 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __FACEBOOK_AGENT_H__
  21. #define __FACEBOOK_AGENT_H__
  22. #include <string>
  23. #include <map>
  24. #include <vector>
  25. #include <functional>
  26. namespace cocos2d{namespace plugin{
  27. class AgentManager;
  28. class FacebookAgent{
  29. public:
  30. ~FacebookAgent();
  31. /** Get singleton of FacebookAgent */
  32. static FacebookAgent* getInstance();
  33. static FacebookAgent* getInstanceLua();
  34. static FacebookAgent* getInstanceJs();
  35. /** Destroy singleton of FacebookAgent */
  36. static void destroyInstance();
  37. enum HttpMethod{
  38. Get = 0,
  39. Post,
  40. Delete
  41. };
  42. typedef std::map<std::string, std::string> FBInfo;
  43. typedef std::function<void(int, std::string&)> FBCallback;
  44. /**
  45. @brief log in
  46. @param cb callback of login
  47. */
  48. void login(FBCallback cb);
  49. /**
  50. @brief log in with specific permissions
  51. @param permissoins different permissions splited by ','
  52. @param cb callback of login
  53. */
  54. void login(std::string& permissions, FBCallback cb);
  55. /**
  56. @brief log out
  57. */
  58. void logout();
  59. /**
  60. @brief Check whether the user logined or not
  61. */
  62. bool isLoggedIn();
  63. /**
  64. @brief get UserID
  65. **/
  66. std::string getUserID();
  67. /**
  68. @brief get AccessToken
  69. */
  70. std::string getAccessToken();
  71. /**
  72. @brief get permissoin list
  73. */
  74. std::string getPermissionList();
  75. /**
  76. @brief share
  77. @param info share information
  78. @param cb callback of share
  79. */
  80. void share(FBInfo &info, FBCallback cb);
  81. /**
  82. @brief open a dialog of Facebook app
  83. @param info share information
  84. @param cb callback of dialog
  85. */
  86. void dialog(FBInfo &info, FBCallback cb);
  87. bool canPresentDialogWithParams(FBInfo &info);
  88. void webDialog(FBInfo &info,FBCallback cb);
  89. /**
  90. @brief open the app request dialog of Facebook app
  91. @param info share information
  92. @param cb callback of dialog
  93. */
  94. void appRequest(FBInfo &info, FBCallback cb);
  95. /**
  96. @brief use Facebook Open Graph api
  97. @param path path of Open Graph api
  98. @param method HttpMethod
  99. @param params request parameters
  100. @param cb callback of request
  101. */
  102. void api(std::string &path, int method, FBInfo &params, FBCallback cb);
  103. /**
  104. @brief Notifies the events system that the app has launched & logs an activatedApp event.
  105. */
  106. void activateApp();
  107. /**
  108. @brief Log an app event with the specified name, supplied value, and set of parameters.
  109. */
  110. void logEvent(std::string& eventName);
  111. void logEvent(std::string& eventName, float valueToSum);
  112. void logEvent(std::string& eventName, FBInfo& parameters);
  113. void logEvent(std::string& eventName, float valueToSum, FBInfo& parameters);
  114. /*
  115. @breif Log an app event for purchase.
  116. */
  117. void logPurchase(float mount,std::string currency);
  118. void logPurchase(float mount,std::string currency,FBInfo &parmeters);
  119. /*
  120. @breif return the version of Facebook SDK for Cocos
  121. */
  122. std::string getSDKVersion();
  123. /*
  124. @breif set the version of Facebook SDK for Cocos
  125. */
  126. void setSDKVersion(std::string version);
  127. FBCallback getRequestCallback(int index);
  128. private:
  129. FacebookAgent();
  130. AgentManager* agentManager;
  131. std::vector<FBCallback> requestCallbacks;
  132. };
  133. }}
  134. #endif