Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.03 KB | None | 0 0
  1. syntax = "proto3";
  2. package one.api.v1;
  3.  
  4. //// General Message Information
  5.  
  6. enum RequestStatus {
  7. UNKNOWN_ERROR = 0;
  8. SUCCESS = 1;
  9.  
  10. // An invalid session means that your session_token is no longer valid, and
  11. // you must log in again.
  12. INVALID_SESSION = 2;
  13.  
  14. // An invalid request means that your request had something wrong with it.
  15. // Repeating the same request will almost certainly not fix the error, the
  16. // problem is on the client side. This may be the response, for example, if
  17. // you request a profile for a user who does not exist, or try to delete
  18. // another user's image.
  19. INVALID_REQUEST = 3;
  20.  
  21. // This means that the server is too busy, or that the client has been making
  22. // requests too frequently. In either case, the client should pause at least
  23. // two seconds before making additional requests.
  24. TOO_BUSY = 4;
  25. }
  26.  
  27. message Location {
  28. float latitude = 1;
  29. float longitude = 2;
  30. string name = 3; // Rarely used, mostly for glances
  31. }
  32.  
  33. message UserLocation {
  34. // As always, don't count on any of these to exist when reading.
  35. // In particular, ttl_ms will default to 0 if not present, so be careful.
  36. bytes user_id = 1;
  37. Location location = 2;
  38. string tagline = 3;
  39. uint32 ttl_ms = 4;
  40. }
  41.  
  42. //// Authentication
  43.  
  44. message AuthenticationDetails {
  45. enum EnumAuthenticationType {
  46. AUTH_SOURCE_LOCAL = 0; // Authenticating with an email address and password
  47. AUTH_SOURCE_FACEBOOK = 1; // Authenticating by Facebook token
  48. }
  49. EnumAuthenticationType auth_type = 1;
  50.  
  51. // Note: auth_type == LOCAL should use the "username" and "password" fields
  52. // auth_type == FACEBOOK should use only the "token" field
  53. string username = 2;
  54. string password = 3;
  55. string token = 4;
  56. }
  57.  
  58. enum EnumAuthenticationResponse {
  59. // Note: Anything other than AUTH_SUCCESS is an error. You should catch any
  60. // unknown values and just say there was an unknown error, in case this list
  61. // gets expanded in the future.
  62. AUTH_UNKNOWN_ERROR = 0;
  63. AUTH_SUCCESS = 1;
  64. INVALID_CREDENTIALS = 2;
  65. EXPIRED_CREDENTIALS = 3;
  66. ACCOUNT_EXISTS = 4;
  67. }
  68.  
  69. message LoginRequest {
  70. AuthenticationDetails auth = 1;
  71. }
  72.  
  73. message LoginResponse {
  74. EnumAuthenticationResponse response_code = 1;
  75.  
  76. // session_token will only be set if response_code == SUCCESS
  77. // Note that session_token is an opaque string of bytes:
  78. // * Do not assume it is a valid UTF-8 string.
  79. // * Do not assume it has a fixed length.
  80. // * Its length should not exceed 1024 bytes, but avoid using a fixed buffer
  81. // to store it. If you do, double-check the length before storing it.
  82. // * It will last for a reasonably long period of time. You can save it to
  83. // a keychain to avoid needing to have the user log in repeatedly.
  84. bytes session_token = 2;
  85.  
  86. // This is the profile ID of the logged-in user. 16 bytes.
  87. // Note that you should almost always request your own profile after logging
  88. // in. This will allow you to sync the user information across multiple
  89. // devices, check to see if the user has paid, and so on.
  90. bytes profile_id = 3;
  91. }
  92.  
  93. message LogoutRequest {
  94. // This just destroys a session.
  95. bytes session_token = 1; // The session_token from logging in
  96. }
  97.  
  98. message LogoutResponse {
  99. RequestStatus status = 1;
  100. }
  101.  
  102. message CreateProfileRequest {
  103. AuthenticationDetails auth = 1;
  104. }
  105.  
  106. message CreateProfileResponse {
  107. EnumAuthenticationResponse response_code = 1;
  108.  
  109. // profile_id will only be set if response_code == SUCCESS
  110. bytes profile_id = 2;
  111. }
  112.  
  113. //// Profiles
  114.  
  115. message Profile {
  116. // NOTE: A profile is not guaranteed to contain ANY of these fields. You MUST
  117. // verify that a field has content before attempting to display it in a user
  118. // interface.
  119.  
  120. // Obvious examples of this may include: you can't see the birthdate for
  121. // other users, but you can see your own, etc.
  122.  
  123. // However, there may be conditions under which you can see, for example,
  124. // the username and images of someone, but not their bio.
  125.  
  126. message Image {
  127. bytes id = 1; // An opaque identifier. 16 bytes.
  128. string uri = 2;
  129. // The ordering priority of this image. Note that lower numbers are given
  130. // higher priority, so it would be reasonable to start at 0 and go up as
  131. // images are added with less priority.
  132. int32 priority = 3;
  133. int32 size = 4; // The size of the file referred to by uri in bytes.
  134.  
  135. // Note again that you can't count on the thumbnail to exist, but it might.
  136. string thumb_uri = 5; // A thumbnail that can be loaded more quickly.
  137. int32 thumb_size = 6; // The filesize for the thumbnail.
  138.  
  139. // This is to be used when uploading an image, and almost never otherwise.
  140. // Note that images uploaded MUST be in JPEG format.
  141. bytes image_content = 16;
  142. }
  143.  
  144. bytes id = 1; // An opaque identifier. 16 bytes.
  145. string name = 2;
  146. repeated Image images = 3;
  147. bool is_male = 4;
  148. string biography = 5;
  149. int64 profile_views = 6;
  150.  
  151. // Less commonly exposed fields get tags > 15 to save space.
  152. // 20-39: What the user is looking for.
  153. bool looking_for_men = 20;
  154. bool looking_for_women = 21;
  155. int32 looking_for_min_age = 22;
  156. int32 looking_for_max_age = 23;
  157.  
  158. // 40-59: Properties of the user.
  159. int32 birthday_year = 40;
  160. int32 birthday_month = 41;
  161. int32 birthday_day = 42;
  162.  
  163. // 60-79: Internal recordkeeping
  164. bool configuration_completed = 60;
  165. bool is_paying_user = 61;
  166. }
  167.  
  168. message GetProfileRequest {
  169. bytes session_token = 1; // The session_token from logging in
  170. bytes profile_id = 2; // The profile_id you're requesting
  171. }
  172.  
  173. message GetProfileResponse {
  174. RequestStatus status = 1;
  175.  
  176. // Only some fields will actually be set:
  177. // * name
  178. // * images
  179. // * is_male
  180. // * biography
  181. // * profile_views
  182. Profile profile = 2;
  183. }
  184.  
  185. message UpdateProfileRequest {
  186. bytes session_token = 1; // The session_token from logging in
  187.  
  188. // This is the profile update.
  189. // Notes:
  190. // * Images should not be updated this way.
  191. // * All user-editable fields MUST be set on the profile, or they will be
  192. // reset to defaults, including potentially changing the user's gender.
  193. // * To clear the name or biography, set them to be blank.
  194. // * You cannot modify profile_views, nor can you clear most fields once
  195. // set (you can override, but not clear, birthdays, etc.).
  196. Profile profile = 2;
  197. }
  198.  
  199. message UpdateProfileResponse {
  200. RequestStatus status = 1;
  201. }
  202.  
  203. //// Images
  204.  
  205. message UploadImageRequest {
  206. bytes session_token = 1; // The session_token from logging in
  207. Profile.Image image = 2; // The image to upload
  208. }
  209.  
  210. message UploadImageResponse {
  211. RequestStatus status = 1;
  212.  
  213. // The ID of the image that got uploaded if successful, 16 bytes.
  214. bytes image_id = 2;
  215. }
  216.  
  217. message DeleteImageRequest {
  218. bytes session_token = 1; // The session_token from logging in
  219. bytes image_id = 2; // One image_id to delete
  220. }
  221.  
  222. message DeleteImageResponse {
  223. RequestStatus status = 1;
  224. }
  225.  
  226. message ReorderImagesRequest {
  227. bytes session_token = 1; // The session_token from logging in
  228.  
  229. // This may be confusing at first: you're sending an array of Profile.Image
  230. // objects, where the id must be set to the image ID, and the priority must
  231. // be the new priority of the image. All other fields will be ignored, but
  232. // this allows for batching of updates to photo ordering.
  233. repeated Profile.Image images = 2;
  234. }
  235.  
  236. message ReorderImagesResponse {
  237. RequestStatus status = 1;
  238. }
  239.  
  240. //// Messages
  241.  
  242. // Note: This is a somewhat simplified message synchronizing system, and may be
  243. // swapped out at a later date. The general theme:
  244. // * Messages have one of several types, including TEXT, GLANCE, and DELETE.
  245. // * Messages have an ID and a "order". The "order" is assigned by the
  246. // server, not the client.
  247. // * Messages MUST be processed in "order" order.
  248. // * A DELETE message instructs the client (and server) to delete the message
  249. // with the ID given by the DELETE message.
  250. // * When a client processes a DELETE message, it should check to see if any
  251. // message has an ID matching that of the DELETE message.
  252. // * If there is one, delete it and don't store the DELETE message.
  253. // * If there isn't one, ignore the DELETE message.
  254. // * When synchronizing messages, store the last "order", and only request
  255. // messages that were sent after that "order" in the future.
  256. // * Marking a message as read is done by sending a READ message to the server
  257. // with an ID of the message that was read. Semantics for processing READ
  258. // messages on the client are similar to those of DELETE: if the message
  259. // exists, mark it read, otherwise, ignore the READ message.
  260.  
  261. // Additionally, a number of things will be enforced by the server:
  262. // * You can mark only messages sent *to* you as read.
  263. // * You can delete only messages sent *to* you.
  264. // * Deleting a message deletes it for both users.
  265.  
  266. enum EnumSentMessageType {
  267. TEXT = 0; // Contains only text
  268. GLANCE = 1; // Contains only a location
  269. DELETE = 2; // Deletes a previous message
  270. READ = 3; // Marks a previous message as read
  271. }
  272.  
  273. message SentMessage {
  274. bytes id = 1; // Opaque identifier, 16 bytes.
  275. EnumSentMessageType type = 2;
  276. bytes from_id = 3; // The sender of this message
  277. bytes to_id = 4; // The recipient of this message
  278. uint64 order = 5; // The order for this message, opaque, but sortable
  279.  
  280. // A timestamp for this message in seconds from the Unix epoch (UTC)
  281. uint64 timestamp = 6;
  282.  
  283. // Text for this message, if the type allows it.
  284. string content = 7;
  285.  
  286. // A location for this message, if the type allows it.
  287. Location location = 8;
  288. }
  289.  
  290. message SendMessageRequest {
  291. bytes session_token = 1; // The session_token from logging in
  292. SentMessage message = 2; // The message to send
  293. }
  294.  
  295. message SendMessageResponse {
  296. RequestStatus status = 1;
  297. bytes message_id = 2; // The message ID sent, if successful
  298. }
  299.  
  300. message UpdateMessagesRequest {
  301. bytes session_token = 1; // The session_token from logging in
  302.  
  303. // The "order" number from which to start retrieving messages. Note that
  304. // if no "order" is known, this field can be omitted or set to 0.
  305. uint64 order = 2;
  306. }
  307.  
  308. message UpdateMessagesResponse {
  309. // Note: this response is likely to be sent multiple times, when there are
  310. // multiple items to retrieve.
  311. RequestStatus status = 1;
  312. SentMessage message = 2;
  313. }
  314.  
  315. message VoteMessageRequest {
  316. RequestStatus status = 1;
  317. bytes message_id = 2; // The message ID to vote on
  318.  
  319. // The number of points to give/take from the message. Note that the server
  320. // MAY require that this number be one of {-1, 0, 1} or otherwise bounded.
  321. int32 vote = 3;
  322. }
  323.  
  324. //// Map
  325.  
  326. message UpdateMapRequest {
  327. bytes session_token = 1; // The session_token from logging in
  328. Location location = 2; // Your current location
  329. string tagline = 3; // Text you want to have display with your location
  330. uint32 ttl_ms = 4; // Time to leave this on the map in milliseconds
  331. bool need_other_users = 5; // Set to true if you want other users' locations
  332. }
  333.  
  334. message UpdateMapResponse {
  335. RequestStatus status = 1;
  336.  
  337. // Zero or more users in the nearby area.
  338. repeated UserLocation locations = 2;
  339. }
  340.  
  341. //// Service definition
  342.  
  343. service Apiv1 {
  344. // Authentication
  345. rpc Login(LoginRequest) returns (LoginResponse);
  346. rpc Logout(LogoutRequest) returns (LogoutResponse);
  347. rpc CreateProfile(CreateProfileRequest) returns (CreateProfileResponse);
  348.  
  349. // Profiles
  350. rpc GetProfile(GetProfileRequest) returns (GetProfileResponse);
  351. rpc UpdateProfile(UpdateProfileRequest) returns (UpdateProfileResponse);
  352.  
  353. // Images
  354. rpc UploadImage(UploadImageRequest) returns (UploadImageResponse);
  355. rpc DeleteImage(DeleteImageRequest) returns (DeleteImageResponse);
  356. rpc ReorderImages(ReorderImagesRequest) returns (ReorderImagesResponse);
  357.  
  358. // Messages
  359. rpc SendMessage(SendMessageRequest) returns (SendMessageResponse);
  360. rpc UpdateMessages(UpdateMessagesRequest) returns (stream UpdateMessagesResponse);
  361.  
  362. // Map
  363. rpc UpdateMap(UpdateMapRequest) returns (UpdateMapResponse);
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement