/ZhiWeibo_v1/Shared/WeiboEngine/WeiboClient.m

https://github.com/tianyawy/WeiboSDK · Objective C · 664 lines · 532 code · 125 blank · 7 comment · 54 complexity · 23d43165fdf3210d33b4b4a41f99c34a MD5 · raw file

  1. //
  2. // WeiboClient.m
  3. // ZhiWeibo
  4. //
  5. // Created by junmin liu on 10-11-20.
  6. // Copyright 2010 Openlab. All rights reserved.
  7. //
  8. #import "WeiboClient.h"
  9. #import "CJSONDeserializer.h"
  10. #define API_FORMAT @"json"
  11. @implementation WeiboClient
  12. - (void)dealloc
  13. {
  14. [super dealloc];
  15. }
  16. #pragma mark -
  17. #pragma mark REST API methods
  18. #pragma mark -
  19. #pragma mark Status methods
  20. - (void)getPublicTimeline
  21. {
  22. needAuth = NO;
  23. NSString *path = [NSString stringWithFormat:@"statuses/public_timeline.%@", API_FORMAT];
  24. [super asyncGet:path params:nil];
  25. }
  26. #pragma mark -
  27. #pragma mark Followed Timeline
  28. - (void)getFollowedTimelineMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  29. {
  30. [self getFollowedTimelineSinceID:0 withMaximumID:maxID startingAtPage:page count:count];
  31. }
  32. - (void)getFollowedTimelineSinceID:(long long)sinceID startingAtPage:(int)page count:(int)count
  33. {
  34. [self getFollowedTimelineSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
  35. }
  36. - (void)getFollowedTimelineSinceID:(long long)sinceID
  37. withMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  38. {
  39. needAuth = YES;
  40. NSString *path = [NSString stringWithFormat:@"statuses/friends_timeline.%@", API_FORMAT];
  41. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  42. if (sinceID > 0) {
  43. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  44. }
  45. if (maxID > 0) {
  46. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  47. }
  48. if (page > 0) {
  49. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  50. }
  51. if (count > 0) {
  52. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  53. }
  54. [super asyncGet:path params:params];
  55. }
  56. #pragma mark -
  57. #pragma mark User Timeline
  58. - (void)getUserTimelineUserId:(long long)userId maximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  59. {
  60. [self getUserTimelineSinceID:0 withUserId:userId maximumID:maxID startingAtPage:page count:count];
  61. }
  62. - (void)getUserTimelineSinceID:(long long)sinceID userId:(long long)userId startingAtPage:(int)page count:(int)count
  63. {
  64. [self getUserTimelineSinceID:sinceID withUserId:userId maximumID:0 startingAtPage:page count:count];
  65. }
  66. - (void)getUserTimelineSinceID:(long long)sinceID
  67. withUserId:(long long)userId maximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  68. {
  69. needAuth = YES;
  70. NSString *path = [NSString stringWithFormat:@"statuses/user_timeline.%@", API_FORMAT];
  71. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  72. if (sinceID > 0) {
  73. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  74. }
  75. if (userId > 0) {
  76. [params setObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"user_id"];
  77. }
  78. if (maxID > 0) {
  79. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  80. }
  81. if (page > 0) {
  82. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  83. }
  84. if (count > 0) {
  85. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  86. }
  87. [super asyncGet:path params:params];
  88. }
  89. #pragma mark -
  90. #pragma mark Repost Timeline
  91. - (void)getRepostTimelineStatusId:(long long)statusId maximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  92. {
  93. [self getRepostTimelineSinceID:0 withStatusId:statusId maximumID:maxID startingAtPage:page count:count];
  94. }
  95. - (void)getRepostTimelineSinceID:(long long)sinceID statusId:(long long)statusId startingAtPage:(int)page count:(int)count
  96. {
  97. [self getRepostTimelineSinceID:sinceID withStatusId:statusId maximumID:0 startingAtPage:page count:count];
  98. }
  99. - (void)getRepostTimelineSinceID:(long long)sinceID
  100. withStatusId:(long long)statusId maximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  101. {
  102. needAuth = YES;
  103. NSString *path = [NSString stringWithFormat:@"statuses/repost_timeline.%@", API_FORMAT];
  104. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  105. if (sinceID > 0) {
  106. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  107. }
  108. if (statusId > 0) {
  109. [params setObject:[NSString stringWithFormat:@"%lld", statusId] forKey:@"id"];
  110. }
  111. if (maxID > 0) {
  112. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  113. }
  114. if (page > 0) {
  115. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  116. }
  117. if (count > 0) {
  118. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  119. }
  120. [super asyncGet:path params:params];
  121. }
  122. #pragma mark -
  123. #pragma mark Mentions
  124. - (void)getMentionsMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  125. {
  126. [self getMentionsSinceID:0 withMaximumID:maxID startingAtPage:page count:count];
  127. }
  128. - (void)getMentionsSinceID:(long long)sinceID startingAtPage:(int)page count:(int)count
  129. {
  130. [self getMentionsSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
  131. }
  132. - (void)getMentionsSinceID:(long long)sinceID
  133. withMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  134. {
  135. needAuth = YES;
  136. NSString *path = [NSString stringWithFormat:@"statuses/mentions.%@", API_FORMAT];
  137. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  138. if (sinceID > 0) {
  139. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  140. }
  141. if (maxID > 0) {
  142. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  143. }
  144. if (page > 0) {
  145. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  146. }
  147. if (count > 0) {
  148. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  149. }
  150. [super asyncGet:path params:params];
  151. }
  152. #pragma mark -
  153. #pragma mark Favorite
  154. - (void)favorite:(long long)statusId
  155. {
  156. needAuth = YES;
  157. NSString *path = [NSString stringWithFormat:@"favorites/create.%@", API_FORMAT];
  158. [super asyncPost:path params:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%lld", statusId] forKey:@"id"] withFiles:nil];
  159. }
  160. - (void)unfavorite:(long long)statusId
  161. {
  162. needAuth = YES;
  163. NSString *path = [NSString stringWithFormat:@"favorites/destroy/%lld.%@", statusId, API_FORMAT];
  164. [super asyncPost:path params:nil withFiles:nil];
  165. }
  166. #pragma mark -
  167. #pragma mark Comments
  168. - (void)getCommentCounts:(NSArray *)_statusIds {
  169. needAuth = YES;
  170. NSString *path = [NSString stringWithFormat:@"statuses/counts.%@", API_FORMAT];
  171. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  172. NSMutableString *ids = [[NSMutableString alloc]init];
  173. int count = _statusIds.count;
  174. int maxCount = 100;
  175. for (int i=0; i<count; i++) {
  176. NSNumber *statusId = [_statusIds objectAtIndex:i];
  177. [ids appendFormat:@"%lld", [statusId longLongValue]];
  178. maxCount--;
  179. if (i < count - 1 && maxCount > 0 ) {
  180. [ids appendString:@","];
  181. }
  182. if (maxCount <= 0) {
  183. break;
  184. }
  185. }
  186. [params setObject:ids forKey:@"ids"];
  187. [ids release];
  188. [super asyncGet:path params:params];
  189. }
  190. - (void)getComments:(long long)statusId
  191. startingAtPage:(int)page
  192. count:(int)count
  193. {
  194. needAuth = YES;
  195. NSString *path = [NSString stringWithFormat:@"statuses/comments.%@", API_FORMAT];
  196. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  197. [params setObject:[NSString stringWithFormat:@"%lld", statusId] forKey:@"id"];
  198. if (page > 0) {
  199. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  200. }
  201. if (count > 0) {
  202. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  203. }
  204. [super asyncGet:path params:params];
  205. }
  206. #pragma mark -
  207. #pragma mark Comments Timeline
  208. - (void)getCommentsTimelineMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  209. {
  210. [self getCommentsTimelineSinceID:0 withMaximumID:maxID startingAtPage:page count:count];
  211. }
  212. - (void)getCommentsTimelineSinceID:(long long)sinceID startingAtPage:(int)page count:(int)count
  213. {
  214. [self getCommentsTimelineSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
  215. }
  216. - (void)getCommentsTimelineSinceID:(long long)sinceID
  217. withMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  218. {
  219. needAuth = YES;
  220. NSString *path = [NSString stringWithFormat:@"statuses/comments_to_me.%@", API_FORMAT];
  221. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  222. if (sinceID > 0) {
  223. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  224. }
  225. if (maxID > 0) {
  226. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  227. }
  228. if (page > 0) {
  229. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  230. }
  231. if (count > 0) {
  232. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  233. }
  234. [super asyncGet:path params:params];
  235. }
  236. #pragma mark -
  237. #pragma mark Trend Timeline
  238. - (void)getTrendsTimelineName:(NSString *)trend_name
  239. {
  240. needAuth = YES;
  241. NSString *path = [NSString stringWithFormat:@"trends/statuses.%@", API_FORMAT];
  242. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  243. if (trend_name) {
  244. [params setObject:[NSString stringWithFormat:@"%@", trend_name] forKey:@"trend_name"];
  245. }
  246. [super asyncGet:path params:params];
  247. }
  248. - (void)getPublicTrendsHourly {
  249. needAuth = YES;
  250. NSString *path = [NSString stringWithFormat:@"trends/hourly.%@", API_FORMAT];
  251. [super asyncGet:path params:nil];
  252. }
  253. - (void)getPublicTrendsDaily {
  254. needAuth = YES;
  255. NSString *path = [NSString stringWithFormat:@"trends/daily.%@", API_FORMAT];
  256. [super asyncGet:path params:nil];
  257. }
  258. - (void)getPublicTrendsWeekly {
  259. needAuth = YES;
  260. NSString *path = [NSString stringWithFormat:@"trends/weekly.%@", API_FORMAT];
  261. [super asyncGet:path params:nil];
  262. }
  263. - (void)getHotUserByCategory:(NSString*)category {
  264. needAuth = YES;
  265. NSString *path = [NSString stringWithFormat:@"users/hot.%@", API_FORMAT];
  266. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  267. if (category) {
  268. [params setObject:[NSString stringWithFormat:@"%@", category] forKey:@"category"];
  269. }
  270. [super asyncGet:path params:params];
  271. }
  272. - (void)getHotStatusesDaily:(int)count {
  273. needAuth = YES;
  274. NSString *path = [NSString stringWithFormat:@"statuses/hot/repost_daily.%@", API_FORMAT];
  275. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  276. if (count > 0) {
  277. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  278. }
  279. [super asyncGet:path params:params];
  280. }
  281. #pragma mark -
  282. #pragma mark Favorites Timeline
  283. - (void)getFavoritesTimelinePage:(int)page
  284. {
  285. needAuth = YES;
  286. NSString *path = [NSString stringWithFormat:@"favorites.%@", API_FORMAT];
  287. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  288. if (page >= 0) {
  289. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  290. }
  291. [super asyncGet:path params:params];
  292. }
  293. #pragma mark -
  294. #pragma mark DirectMessage
  295. - (void)getDirectMessagesMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  296. {
  297. [self getDirectMessagesSinceID:0 withMaximumID:maxID startingAtPage:page count:count];
  298. }
  299. - (void)getDirectMessagesSinceID:(long long)sinceID startingAtPage:(int)page count:(int)count
  300. {
  301. [self getDirectMessagesSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
  302. }
  303. - (void)getDirectMessagesSinceID:(long long)sinceID
  304. withMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  305. {
  306. needAuth = YES;
  307. NSString *path = [NSString stringWithFormat:@"direct_messages.%@", API_FORMAT];
  308. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  309. if (sinceID > 0) {
  310. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  311. }
  312. if (maxID > 0) {
  313. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  314. }
  315. if (page > 0) {
  316. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  317. }
  318. if (count > 0) {
  319. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  320. }
  321. [super asyncGet:path params:params];
  322. }
  323. #pragma mark -
  324. #pragma mark DirectMessageSent
  325. - (void)getDirectMessagesSentMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  326. {
  327. [self getDirectMessagesSentSinceID:0 withMaximumID:maxID startingAtPage:page count:count];
  328. }
  329. - (void)getDirectMessagesSentSinceID:(long long)sinceID startingAtPage:(int)page count:(int)count
  330. {
  331. [self getDirectMessagesSentSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
  332. }
  333. - (void)getDirectMessagesSentSinceID:(long long)sinceID
  334. withMaximumID:(long long)maxID startingAtPage:(int)page count:(int)count
  335. {
  336. needAuth = YES;
  337. NSString *path = [NSString stringWithFormat:@"direct_messages/sent.%@", API_FORMAT];
  338. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  339. if (sinceID > 0) {
  340. [params setObject:[NSString stringWithFormat:@"%lld", sinceID] forKey:@"since_id"];
  341. }
  342. if (maxID > 0) {
  343. [params setObject:[NSString stringWithFormat:@"%lld", maxID] forKey:@"max_id"];
  344. }
  345. if (page > 0) {
  346. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  347. }
  348. if (count > 0) {
  349. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  350. }
  351. [super asyncGet:path params:params];
  352. }
  353. #pragma mark -
  354. #pragma mark UserSearch
  355. - (void)getUserTimelineByName:(NSString*)name page:(int)page count:(int)count
  356. {
  357. needAuth = NO;
  358. NSString *path = [NSString stringWithFormat:@"users/search.%@", API_FORMAT];
  359. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  360. if (name && ![name isEqualToString:@""]) {
  361. [params setObject:[NSString stringWithFormat:@"%@", name] forKey:@"q"];
  362. }
  363. if (page > 0) {
  364. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  365. }
  366. if (count > 0) {
  367. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  368. }
  369. [super asyncGet:path params:params];
  370. }
  371. - (void)getStatusTimelineByName:(NSString*)name startTime:(time_t)startTime
  372. endTime:(time_t)endTime page:(int)page count:(int)count
  373. {
  374. needAuth = NO;
  375. NSString *path = [NSString stringWithFormat:@"statuses/search.%@", API_FORMAT];
  376. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  377. if (name && ![name isEqualToString:@""]) {
  378. [params setObject:[NSString stringWithFormat:@"%@", name] forKey:@"q"];
  379. }
  380. if (startTime > 0) {
  381. [params setObject:[NSString stringWithFormat:@"%llu", startTime] forKey:@"starttime"];
  382. }
  383. if (endTime > 0) {
  384. [params setObject:[NSString stringWithFormat:@"%lld", endTime] forKey:@"endtime"];
  385. }
  386. if (page > 0) {
  387. [params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
  388. }
  389. if (count > 0) {
  390. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  391. }
  392. [super asyncGet:path params:params];
  393. }
  394. #pragma mark -
  395. #pragma mark Account
  396. - (void)verify {
  397. needAuth = YES;
  398. NSString *path = [NSString stringWithFormat:@"account/verify_credentials.%@", API_FORMAT];
  399. [super asyncGet:path params:nil];
  400. }
  401. - (void)getFriends:(long long)userId
  402. cursor:(int)cursor
  403. count:(int)count
  404. {
  405. needAuth = YES;
  406. NSString *path = [NSString stringWithFormat:@"statuses/friends.%@", API_FORMAT];
  407. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  408. [params setObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"user_id"];
  409. [params setObject:[NSString stringWithFormat:@"%d", cursor] forKey:@"cursor"];
  410. if (count > 0) {
  411. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  412. }
  413. [super asyncGet:path params:params];
  414. }
  415. - (void)getFollowers:(long long)userId
  416. cursor:(int)cursor
  417. count:(int)count
  418. {
  419. needAuth = YES;
  420. NSString *path = [NSString stringWithFormat:@"statuses/followers.%@", API_FORMAT];
  421. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  422. [params setObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"user_id"];
  423. [params setObject:[NSString stringWithFormat:@"%d", cursor] forKey:@"cursor"];
  424. if (count > 0) {
  425. [params setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
  426. }
  427. [super asyncGet:path params:params];
  428. }
  429. - (void)getUser:(long long)userId
  430. {
  431. needAuth = YES;
  432. NSString *path = [NSString stringWithFormat:@"users/show.%@", API_FORMAT];
  433. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  434. [params setObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"user_id"];
  435. [super asyncGet:path params:params];
  436. }
  437. - (void)getUserByScreenName:(NSString *)screenName {
  438. needAuth = YES;
  439. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  440. [params setObject:[NSString stringWithFormat:@"%@", screenName] forKey:@"screen_name"];
  441. NSString *path = [NSString stringWithFormat:@"users/show.%@", API_FORMAT];
  442. [super asyncGet:path params:params];
  443. }
  444. - (void)getFriendship:(long long)userId {
  445. needAuth = YES;//friendships/show.xml?target_id=10503
  446. NSString *path = [NSString stringWithFormat:@"friendships/show.%@", API_FORMAT];
  447. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
  448. [params setObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"target_id"];
  449. [super asyncGet:path params:params];
  450. }
  451. - (void)getUnread {
  452. needAuth = YES;
  453. NSString *path = [NSString stringWithFormat:@"statuses/unread.%@", API_FORMAT];
  454. [super asyncGet:path params:nil];
  455. }
  456. - (void)resetUnreadFollowers {
  457. needAuth = YES;
  458. NSString *path = [NSString stringWithFormat:@"statuses/reset_count.%@", API_FORMAT];
  459. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:[NSString stringWithFormat:@"%d", 4] forKey:@"type"];
  460. [super asyncPost:path params:params withFiles:nil];
  461. }
  462. - (void)follow:(long long)userId {
  463. needAuth = YES;///friendships/create.xml?user_id=1401881
  464. NSString *path = [NSString stringWithFormat:@"friendships/create.%@", API_FORMAT];
  465. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"user_id"];
  466. [super asyncPost:path params:params withFiles:nil];
  467. }
  468. - (void)unfollow:(long long)userId {
  469. needAuth = YES;///friendships/destroy.xml?user_id=1401881
  470. NSString *path = [NSString stringWithFormat:@"friendships/destroy.%@", API_FORMAT];
  471. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:[NSString stringWithFormat:@"%lld", userId] forKey:@"user_id"];
  472. [super asyncPost:path params:params withFiles:nil];
  473. }
  474. - (void)post:(NSString*)tweet latitude:(float)latitude
  475. longitude:(float)longitude
  476. {
  477. needAuth = YES;
  478. NSString *path = [NSString stringWithFormat:@"statuses/update.%@", API_FORMAT];
  479. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  480. tweet, @"status",
  481. [NSString stringWithFormat:@"%f", latitude], @"lat",
  482. [NSString stringWithFormat:@"%f", longitude], @"long",
  483. nil];
  484. [super asyncPost:path params:params withFiles:nil];
  485. }
  486. - (void)upload:(NSData*)jpeg status:(NSString *)status
  487. latitude:(float)latitude longitude:(float)longitude
  488. {
  489. needAuth = YES;
  490. NSString *path = [NSString stringWithFormat:@"statuses/upload.%@", API_FORMAT];
  491. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  492. status, @"status",
  493. [NSString stringWithFormat:@"%f", latitude], @"lat",
  494. [NSString stringWithFormat:@"%f", longitude], @"long",
  495. nil];
  496. RequestFile *file = [[[RequestFile alloc]initWithJpegData:jpeg forKey:@"pic"] autorelease];
  497. [super asyncPost:path params:params withFiles:[NSArray arrayWithObject:file]];
  498. }
  499. - (void)repost:(long long)statusId
  500. tweet:(NSString*)tweet
  501. isComment:(BOOL)isComment {
  502. needAuth = YES;
  503. NSString *path = [NSString stringWithFormat:@"statuses/repost.%@", API_FORMAT];
  504. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  505. [params setObject:tweet forKey:@"status"];
  506. [params setObject:[NSString stringWithFormat:@"%lld", statusId] forKey:@"id"];
  507. if (isComment) {
  508. [params setObject:@"1" forKey:@"is_comment"];
  509. }
  510. [super asyncPost:path params:params withFiles:nil];
  511. }
  512. - (void)comment:(long long)statusId
  513. commentId:(long long)commentId
  514. comment:(NSString*)comment {
  515. needAuth = YES;
  516. NSString *path = [NSString stringWithFormat:@"statuses/comment.%@", API_FORMAT];
  517. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  518. [params setObject:comment forKey:@"comment"];
  519. [params setObject:[NSString stringWithFormat:@"%lld", statusId] forKey:@"id"];
  520. if (commentId > 0) {
  521. [params setObject:[NSString stringWithFormat:@"%lld", commentId] forKey:@"cid"];
  522. }
  523. [super asyncPost:path params:params withFiles:nil];
  524. }
  525. - (void)sendDirectMessage:(NSString*)text
  526. to:(int)recipientedId
  527. {
  528. needAuth = YES;
  529. NSString *path = [NSString stringWithFormat:@"direct_messages/new.%@", API_FORMAT];
  530. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  531. [params setObject:text forKey:@"text"];
  532. [params setObject:[NSString stringWithFormat:@"%d", recipientedId] forKey:@"user_id"];
  533. [super asyncPost:path params:params withFiles:nil];
  534. }
  535. - (void)alert
  536. {
  537. [[ZhiWeiboAppDelegate getAppDelegate] alert:errorMessage message:errorDetail];
  538. }
  539. @end