Permission.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  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, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. import Foundation
  19. /**
  20. Represents a Graph API permission.
  21. Each permission has its own set of requirements and suggested use cases.
  22. See a full list at https://developers.facebook.com/docs/facebook-login/permissions
  23. */
  24. public enum Permission: Hashable, ExpressibleByStringLiteral {
  25. /// Provides access to a subset of items that are part of a person's public profile.
  26. case publicProfile
  27. /// Provides access the list of friends that also use your app.
  28. case userFriends
  29. /// Provides access to the person's primary email address.
  30. case email
  31. /// Provides access to a person's personal description (the 'About Me' section on their Profile)
  32. case userAboutMe
  33. /// Provides access to all common books actions published by any app the person has used.
  34. /// This includes books they've read, want to read, rated or quoted.
  35. case userActionsBooks
  36. /// Provides access to all common Open Graph fitness actions published by any app the person has used.
  37. /// This includes runs, walks and bikes actions.
  38. case userActionsFitness
  39. /// Provides access to all common Open Graph music actions published by any app the person has used.
  40. /// This includes songs they've listened to, and playlists they've created.
  41. case userActionsMusic
  42. /// Provides access to all common Open Graph news actions published by any app the person
  43. /// has used which publishes these actions.
  44. /// This includes news articles they've read or news articles they've published.
  45. case userActionsNews
  46. /// Provides access to all common Open Graph video actions published by any app the person
  47. /// has used which publishes these actions.
  48. case userActionsVideo
  49. /// Access the date and month of a person's birthday. This may or may not include the person's year of birth,
  50. /// dependent upon their privacy settings and the access token being used to query this field.
  51. case userBirthday
  52. /// Provides access to a person's education history through the education field on the User object.
  53. case userEducationHistory
  54. /// Provides read-only access to the Events a person is hosting or has RSVP'd to.
  55. case userEvents
  56. /// Provides access to read a person's game activity (scores, achievements) in any game the person has played.
  57. case userGamesActivity
  58. /// Provides access to a person's gender.
  59. case userGender
  60. /// Provides access to a person's hometown location through the hometown field on the User object.
  61. case userHometown
  62. /// Provides access to the list of all Facebook Pages and Open Graph objects that a person has liked.
  63. case userLikes
  64. /// Provides access to a person's current city through the location field on the User object.
  65. case userLocation
  66. /// Lets your app read the content of groups a person is an admin of through the Groups edge on the User object.
  67. case userManagedGroups
  68. /// Provides access to the photos a person has uploaded or been tagged in.
  69. case userPhotos
  70. /// Provides access to the posts on a person's Timeline. Includes their own posts, posts they are tagged in,
  71. /// and posts other people make on their Timeline.
  72. case userPosts
  73. /// Provides access to a person's relationship status,
  74. /// significant other and family members as fields on the User object.
  75. case userRelationships
  76. /// Provides access to a person's relationship interests as the interested_in field on the User object.
  77. case userRelationshipDetails
  78. /// Provides access to a person's religious and political affiliations.
  79. case userReligionPolitics
  80. /// Provides access to the Places a person has been tagged at in photos, videos, statuses and links.
  81. case userTaggedPlaces
  82. /// Provides access to the videos a person has uploaded or been tagged in.
  83. case userVideos
  84. /// Provides access to the person's personal website URL via the website field on the User object.
  85. case userWebsite
  86. /// Provides access to a person's work history and list of employers via the work field on the User object.
  87. case userWorkHistory
  88. /// Provides access to the names of custom lists a person has created to organize their friends.
  89. case readCustomFriendlists
  90. /// Provides read-only access to the Insights data for Pages, Apps and web domains the person owns.
  91. case readInsights
  92. /// Provides read-only access to the Audience Network Insights data for Apps the person owns.
  93. case readAudienceNetworkInsights
  94. /// Provides the ability to read from the Page Inboxes of the Pages managed by a person.
  95. case readPageMailboxes
  96. /// Provides the access to show the list of the Pages that you manage.
  97. case pagesShowList
  98. /// Provides the access to manage call to actions of the Pages that you manage.
  99. case pagesManageCta
  100. /// Lets your app manage Instant Articles on behalf of Facebook Pages administered by people using your app.
  101. case pagesManageInstantArticles
  102. /// Provides the access to Ads Insights API to pull ads report information for ad accounts you have access to.
  103. case adsRead
  104. /**
  105. Permission with a custom string value.
  106. See https://developers.facebook.com/docs/facebook-login/permissions for full list of available permissions.
  107. */
  108. case custom(String)
  109. public init(stringLiteral value: String) {
  110. guard let permission = StringPermission(rawValue: value)?.permission else {
  111. self = .custom(value)
  112. return
  113. }
  114. self = permission
  115. }
  116. public var name: String {
  117. if let permission = stringPermission {
  118. return permission.rawValue
  119. }
  120. if case let .custom(permission) = self {
  121. return permission
  122. }
  123. return ""
  124. }
  125. private var stringPermission: StringPermission? {
  126. switch self {
  127. case .publicProfile: return .publicProfile
  128. case .userFriends: return .userFriends
  129. case .email: return .email
  130. case .userAboutMe: return .userAboutMe
  131. case .userActionsBooks: return .userActionsBooks
  132. case .userActionsFitness: return .userActionsFitness
  133. case .userActionsMusic: return .userActionsMusic
  134. case .userActionsNews: return .userActionsNews
  135. case .userActionsVideo: return .userActionsVideo
  136. case .userBirthday: return .userBirthday
  137. case .userEducationHistory: return .userEducationHistory
  138. case .userEvents: return .userEvents
  139. case .userGamesActivity: return .userGamesActivity
  140. case .userGender: return .userGender
  141. case .userHometown: return .userHometown
  142. case .userLikes: return .userLikes
  143. case .userLocation: return .userLocation
  144. case .userManagedGroups: return .userManagedGroups
  145. case .userPhotos: return .userPhotos
  146. case .userPosts: return .userPosts
  147. case .userRelationships: return .userRelationships
  148. case .userRelationshipDetails: return .userRelationshipDetails
  149. case .userReligionPolitics: return .userReligionPolitics
  150. case .userTaggedPlaces: return .userTaggedPlaces
  151. case .userVideos: return .userVideos
  152. case .userWebsite: return .userWebsite
  153. case .userWorkHistory: return .userWorkHistory
  154. case .readCustomFriendlists: return .readCustomFriendlists
  155. case .readInsights: return .readInsights
  156. case .readAudienceNetworkInsights: return .readAudienceNetworkInsights
  157. case .readPageMailboxes: return .readPageMailboxes
  158. case .pagesShowList: return .pagesShowList
  159. case .pagesManageCta: return .pagesManageCta
  160. case .pagesManageInstantArticles: return .pagesManageInstantArticles
  161. case .adsRead: return .adsRead
  162. case .custom: return nil
  163. }
  164. }
  165. }
  166. private enum StringPermission: String {
  167. case publicProfile = "public_profile"
  168. case userFriends = "user_friends"
  169. case email = "email"
  170. case userAboutMe = "user_about_me"
  171. case userActionsBooks = "user_actions.books"
  172. case userActionsFitness = "user_action.fitness"
  173. case userActionsMusic = "user_actions.music"
  174. case userActionsNews = "user_actions.news"
  175. case userActionsVideo = "user_actions.video"
  176. case userBirthday = "user_birthday"
  177. case userEducationHistory = "user_education_history"
  178. case userEvents = "user_events"
  179. case userGamesActivity = "user_games_activity"
  180. case userGender = "user_gender"
  181. case userHometown = "user_hometown"
  182. case userLikes = "user_likes"
  183. case userLocation = "user_location"
  184. case userManagedGroups = "user_managed_groups"
  185. case userPhotos = "user_photos"
  186. case userPosts = "user_posts"
  187. case userRelationships = "user_relationships"
  188. case userRelationshipDetails = "user_relationship_details"
  189. case userReligionPolitics = "user_religion_politics"
  190. case userTaggedPlaces = "user_tagged_places"
  191. case userVideos = "user_videos"
  192. case userWebsite = "user_website"
  193. case userWorkHistory = "user_work_history"
  194. case readCustomFriendlists = "read_custom_friendlists"
  195. case readInsights = "read_insights"
  196. case readAudienceNetworkInsights = "read_audience_network_insights"
  197. case readPageMailboxes = "read_page_mailboxes"
  198. case pagesShowList = "pages_show_list"
  199. case pagesManageCta = "pages_manage_cta"
  200. case pagesManageInstantArticles = "pages_manage_instant_articles"
  201. case adsRead = "ads_read"
  202. var permission: Permission {
  203. switch self {
  204. case .publicProfile: return .publicProfile
  205. case .userFriends: return .userFriends
  206. case .email: return .email
  207. case .userAboutMe: return .userAboutMe
  208. case .userActionsBooks: return .userActionsBooks
  209. case .userActionsFitness: return .userActionsFitness
  210. case .userActionsMusic: return .userActionsMusic
  211. case .userActionsNews: return .userActionsNews
  212. case .userActionsVideo: return .userActionsVideo
  213. case .userBirthday: return .userBirthday
  214. case .userEducationHistory: return .userEducationHistory
  215. case .userEvents: return .userEvents
  216. case .userGamesActivity: return .userGamesActivity
  217. case .userGender: return .userGender
  218. case .userHometown: return .userHometown
  219. case .userLikes: return .userLikes
  220. case .userLocation: return .userLocation
  221. case .userManagedGroups: return .userManagedGroups
  222. case .userPhotos: return .userPhotos
  223. case .userPosts: return .userPosts
  224. case .userRelationships: return .userRelationships
  225. case .userRelationshipDetails: return .userRelationshipDetails
  226. case .userReligionPolitics: return .userReligionPolitics
  227. case .userTaggedPlaces: return .userTaggedPlaces
  228. case .userVideos: return .userVideos
  229. case .userWebsite: return .userWebsite
  230. case .userWorkHistory: return .userWorkHistory
  231. case .readCustomFriendlists: return .readCustomFriendlists
  232. case .readInsights: return .readInsights
  233. case .readAudienceNetworkInsights: return .readAudienceNetworkInsights
  234. case .readPageMailboxes: return .readPageMailboxes
  235. case .pagesShowList: return .pagesShowList
  236. case .pagesManageCta: return .pagesManageCta
  237. case .pagesManageInstantArticles: return .pagesManageInstantArticles
  238. case .adsRead: return .adsRead
  239. }
  240. }
  241. }