xref: /haiku/src/apps/haikudepot/server/WebAppInterface.h (revision 6889394848e2dc9f41ff53b12141d572822ca0c6)
1 /*
2  * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2016-2017, Andrew Lindesay <apl@lindesay.co.nz>.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 #ifndef WEB_APP_INTERFACE_H
7 #define WEB_APP_INTERFACE_H
8 
9 
10 #include <Application.h>
11 #include <String.h>
12 #include <package/PackageVersion.h>
13 
14 #include "List.h"
15 
16 
17 class BDataIO;
18 class BMessage;
19 using BPackageKit::BPackageVersion;
20 
21 typedef List<BString, false>	StringList;
22 
23 
24 class WebAppInterface {
25 public:
26 								WebAppInterface();
27 								WebAppInterface(const WebAppInterface& other);
28 	virtual						~WebAppInterface();
29 
30 			WebAppInterface&	operator=(const WebAppInterface& other);
31 
32 			void				SetAuthorization(const BString& username,
33 									const BString& password);
34 			const BString&		Username() const
35 									{ return fUsername; }
36 
37 			void				SetPreferredLanguage(const BString& language);
38 			void				SetArchitecture(const BString& architecture);
39 
40 			status_t			RetrieveRepositoriesForSourceBaseURLs(
41 									const StringList& repositorySourceBaseURL,
42 									BMessage& message);
43 
44 			status_t			RetrievePackageInfo(
45 									const BString& packageName,
46 									const BString& architecture,
47 									const BString& repositoryCode,
48 									BMessage& message);
49 
50 			status_t			RetrieveBulkPackageInfo(
51 									const StringList& packageNames,
52 									const StringList& packageArchitectures,
53 									const StringList& repositoryCodes,
54 									BMessage& message);
55 
56 			status_t			RetrieveUserRatings(
57 									const BString& packageName,
58 									const BString& architecture,
59 									int resultOffset, int maxResults,
60 									BMessage& message);
61 
62 			status_t			RetrieveUserRating(
63 									const BString& packageName,
64 									const BPackageVersion& version,
65 									const BString& architecture,
66 									const BString& repositoryCode,
67 									const BString& username,
68 									BMessage& message);
69 
70 			status_t			CreateUserRating(
71 									const BString& packageName,
72 									const BString& architecture,
73 									const BString& repositoryCode,
74 									const BString& languageCode,
75 									const BString& comment,
76 									const BString& stability,
77 									int rating,
78 									BMessage& message);
79 
80 			status_t			UpdateUserRating(
81 									const BString& ratingID,
82 									const BString& languageCode,
83 									const BString& comment,
84 									const BString& stability,
85 									int rating, bool active,
86 									BMessage& message);
87 
88 			status_t			RetrieveScreenshot(
89 									const BString& code,
90 									int32 width, int32 height,
91 									BDataIO* stream);
92 
93 			status_t			RequestCaptcha(BMessage& message);
94 
95 			status_t			CreateUser(const BString& nickName,
96 									const BString& passwordClear,
97 									const BString& email,
98 									const BString& captchaToken,
99 									const BString& captchaResponse,
100 									const BString& languageCode,
101 									BMessage& message);
102 
103 			status_t			AuthenticateUser(const BString& nickName,
104 									const BString& passwordClear,
105 									BMessage& message);
106 
107 private:
108 			status_t			_SendJsonRequest(const char* domain,
109 									BString jsonString, uint32 flags,
110 									BMessage& reply) const;
111 
112 private:
113 			BString				fUsername;
114 			BString				fPassword;
115 			BString				fLanguage;
116 	static	int					fRequestIndex;
117 };
118 
119 
120 #endif // WEB_APP_INTERFACE_H
121