|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "{License}" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "{LicenseUrl}". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Siddhartha Chandra, Sasken Communication Technologies Ltd |
|
14 * Description: |
|
15 * class to handle calls to rest Server API's |
|
16 */ |
|
17 #ifndef FBREQUEST_H |
|
18 #define FBREQUEST_H |
|
19 |
|
20 #include <QObject> |
|
21 #include <QString> |
|
22 #include <QDateTime> |
|
23 #include <QHttp> |
|
24 #include <QHash> |
|
25 #include <QNetworkAccessManager> |
|
26 #include <QNetworkReply> |
|
27 #include "progressbar.h" |
|
28 #include "authAppConstants.h" |
|
29 #include "xmlParser.h" |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class FBSession; |
|
33 class FBError; |
|
34 |
|
35 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 class FBRequest : public QObject |
|
37 { |
|
38 Q_OBJECT |
|
39 |
|
40 private: |
|
41 |
|
42 /* pointer to the session that owns this request */ |
|
43 FBSession* iSession; |
|
44 |
|
45 /** |
|
46 * The URL which will be contacted to execute the request. |
|
47 */ |
|
48 QString iUrl; |
|
49 |
|
50 /** |
|
51 * The API method which will be called. |
|
52 */ |
|
53 QString iMethod; |
|
54 |
|
55 /** |
|
56 * An object used by the user of the request to help identify the meaning of the request. |
|
57 */ |
|
58 void* iUserInfo; |
|
59 |
|
60 /** |
|
61 * The dictionary of parameters to pass to the method. |
|
62 * |
|
63 * These values in the dictionary will be converted to strings using the |
|
64 * standard Objective-C object-to-string conversion facilities. |
|
65 */ |
|
66 Dictionary iParams; |
|
67 |
|
68 /** |
|
69 * A data parameter. |
|
70 * |
|
71 * Used for methods such as photos.upload, video.upload, events.create, and |
|
72 * events.edit. |
|
73 */ |
|
74 QByteArray iDataParam; |
|
75 |
|
76 /** |
|
77 * true if iDataParam holds picture data |
|
78 */ |
|
79 bool iDataParamPicture; |
|
80 |
|
81 /** |
|
82 * The timestamp of when the request was sent to the server. |
|
83 */ |
|
84 QDateTime iTimestamp; |
|
85 QHttp iConnection; |
|
86 QByteArray iResponseText; |
|
87 |
|
88 QNetworkAccessManager iNetworkAccessManager; |
|
89 progressbar* pbar; |
|
90 |
|
91 signals: /* the signals ommitted by FBRequest */ |
|
92 |
|
93 /** |
|
94 * Called just before the request is sent to the server. |
|
95 */ |
|
96 void requestLoading(); |
|
97 |
|
98 /** |
|
99 * Called when the server responds and begins to send back data. |
|
100 */ |
|
101 //todo: void requestDidReceiveResponse (FBRequest* aRequest, NSURLResponse* aResponse); |
|
102 |
|
103 /** |
|
104 * Called when an error prevents the request from completing successfully. |
|
105 */ |
|
106 void requestFailedWithNetworkError( QNetworkReply::NetworkError code ); |
|
107 void requestFailedWithFacebookError ( const FBError& aError ); |
|
108 |
|
109 /** |
|
110 * Called when a request returns and its response has been parsed into an object. |
|
111 * |
|
112 * The resulting object may be a dictionary, an array, a string, or a number, depending |
|
113 * on thee format of the API response. |
|
114 */ |
|
115 void requestDidLoad ( const QVariant& aResult); |
|
116 void LoadLoginPage(); |
|
117 |
|
118 /** |
|
119 * Called when the request was cancelled. |
|
120 */ |
|
121 void requestWasCancelled (); |
|
122 |
|
123 |
|
124 private slots: |
|
125 void networkReplyError ( QNetworkReply::NetworkError code ); |
|
126 void networkReplyFinished (); |
|
127 void networkReplyFinishedNew (); |
|
128 public: /* class functions */ |
|
129 /** |
|
130 * Creates a new API request for the global session. |
|
131 */ |
|
132 static FBRequest* request(); |
|
133 |
|
134 /** |
|
135 * Creates a new API request for a particular session. |
|
136 */ |
|
137 static FBRequest* requestWithSession (FBSession* aSession); |
|
138 |
|
139 public: /* instance functions */ |
|
140 |
|
141 /** |
|
142 * Creates a new request paired to a session. |
|
143 */ |
|
144 FBRequest (FBSession* aSession); |
|
145 |
|
146 /** |
|
147 * Calls a method on the server asynchronously. |
|
148 * |
|
149 * The delegate will be called for each stage of the loading process. |
|
150 */ |
|
151 void call (const QString& aMethod, const Dictionary& aParams); |
|
152 |
|
153 /** |
|
154 * Calls a method on the server asynchronously, with a file upload component. |
|
155 * |
|
156 * The delegate will be called for each stage of the loading process. |
|
157 */ |
|
158 void callWithDataParams (const QString& aMethod, const Dictionary& aParams, const QByteArray& aDataParam, bool aDataParamPicture); |
|
159 |
|
160 /** |
|
161 * Calls a URL on the server asynchronously. |
|
162 * |
|
163 * The delegate will be called for each stage of the loading process. |
|
164 */ |
|
165 void post( const QString& aUrl, const Dictionary& aParams); |
|
166 |
|
167 /** |
|
168 * Stops an active request before the response has returned. |
|
169 */ |
|
170 void cancel(); |
|
171 |
|
172 /** |
|
173 * returns the time stamp of when the request was sent to the server |
|
174 */ |
|
175 const QDateTime& timeStamp() const; |
|
176 |
|
177 void connect(); |
|
178 |
|
179 QString generateSig(Dictionary); |
|
180 |
|
181 private: |
|
182 /** |
|
183 * Given a string returns its hex coded md5 hash |
|
184 */ |
|
185 QString sha1(); |
|
186 |
|
187 /** |
|
188 * @return true if the current request method is a special method |
|
189 */ |
|
190 bool isSpecialMethod() const; |
|
191 |
|
192 /** |
|
193 * @return QString a url to use for the given method |
|
194 */ |
|
195 QString urlForMethod (const QString& aMethod) const; |
|
196 |
|
197 /** |
|
198 * @return the Get Url for the request |
|
199 */ |
|
200 QString generateGetURL() const; |
|
201 |
|
202 QString generateCallId() const; |
|
203 |
|
204 void generatePostBody(QByteArray& body); |
|
205 |
|
206 /** |
|
207 * handles the data received from the server |
|
208 * @param aResponseData is the data received from the server |
|
209 */ |
|
210 void handleResponseData( const QByteArray& aResponseData ); |
|
211 |
|
212 /** |
|
213 * @param aResponseData is the data received from the server |
|
214 * @param aError will get error codes if any error occurs ( this will change in the future ) |
|
215 * @return a void* pointer, this will change |
|
216 */ |
|
217 QVariant parseXMLResponse ( const QByteArray& aResponseData, FBError& aError); |
|
218 public: |
|
219 TBuf8<1024> tbuf; |
|
220 void proxysettings(); |
|
221 public: |
|
222 void connect_req(QString uri); |
|
223 }; |
|
224 |
|
225 #endif // FBREQUEST_H |