SuperTweet interface driver classes.
Dependents: SuperTweet_TestProgram StarBoardOrangeExpansion1 GSL_04-Network_Twitter
SuperTweetV1XML.cpp@0:d48d92e6c145, 2010-10-12 (annotated)
- Committer:
- shintamainjp
- Date:
- Tue Oct 12 22:20:38 2010 +0000
- Revision:
- 0:d48d92e6c145
- Child:
- 1:2d211e591fc8
First version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:d48d92e6c145 | 1 | /** |
shintamainjp | 0:d48d92e6c145 | 2 | * SuperTweet API interface driver. (Version 0.0.1) |
shintamainjp | 0:d48d92e6c145 | 3 | * |
shintamainjp | 0:d48d92e6c145 | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 0:d48d92e6c145 | 5 | * http://shinta.main.jp/ |
shintamainjp | 0:d48d92e6c145 | 6 | */ |
shintamainjp | 0:d48d92e6c145 | 7 | |
shintamainjp | 0:d48d92e6c145 | 8 | #include "SuperTweetV1XML.h" |
shintamainjp | 0:d48d92e6c145 | 9 | |
shintamainjp | 0:d48d92e6c145 | 10 | SuperTweetV1XML::SuperTweetV1XML(const std::string account, const std::string password) |
shintamainjp | 0:d48d92e6c145 | 11 | : SuperTweet(account, password) { |
shintamainjp | 0:d48d92e6c145 | 12 | } |
shintamainjp | 0:d48d92e6c145 | 13 | |
shintamainjp | 0:d48d92e6c145 | 14 | SuperTweetV1XML::~SuperTweetV1XML() { |
shintamainjp | 0:d48d92e6c145 | 15 | } |
shintamainjp | 0:d48d92e6c145 | 16 | |
shintamainjp | 0:d48d92e6c145 | 17 | HTTPResult SuperTweetV1XML::getStatusesUserTimeline(void (*func)(char *buf, size_t siz)) { |
shintamainjp | 0:d48d92e6c145 | 18 | HTTPMap map; |
shintamainjp | 0:d48d92e6c145 | 19 | HTTPStream stream; |
shintamainjp | 0:d48d92e6c145 | 20 | const std::string url = URLBASE_V1 + "statuses/user_timeline.xml"; |
shintamainjp | 0:d48d92e6c145 | 21 | char buf[BUFSIZ + 1] = {0}; |
shintamainjp | 0:d48d92e6c145 | 22 | |
shintamainjp | 0:d48d92e6c145 | 23 | result = HTTP_OK; |
shintamainjp | 0:d48d92e6c145 | 24 | completed = false; |
shintamainjp | 0:d48d92e6c145 | 25 | stream.readNext((byte*)buf, sizeof(buf) - 1); |
shintamainjp | 0:d48d92e6c145 | 26 | HTTPResult r = client.get(url.c_str(), &stream, this, &SuperTweetV1XML::callback); |
shintamainjp | 0:d48d92e6c145 | 27 | while (!completed) { |
shintamainjp | 0:d48d92e6c145 | 28 | Net::poll(); |
shintamainjp | 0:d48d92e6c145 | 29 | if (stream.readable()) { |
shintamainjp | 0:d48d92e6c145 | 30 | buf[stream.readLen()] = 0; |
shintamainjp | 0:d48d92e6c145 | 31 | func(buf, stream.readLen()); |
shintamainjp | 0:d48d92e6c145 | 32 | stream.readNext((byte*)buf, sizeof(buf) - 1); |
shintamainjp | 0:d48d92e6c145 | 33 | } |
shintamainjp | 0:d48d92e6c145 | 34 | } |
shintamainjp | 0:d48d92e6c145 | 35 | return result; |
shintamainjp | 0:d48d92e6c145 | 36 | } |
shintamainjp | 0:d48d92e6c145 | 37 | |
shintamainjp | 0:d48d92e6c145 | 38 | HTTPResult SuperTweetV1XML::getStatusesHomeTimeline(void (*func)(char *buf, size_t siz)) { |
shintamainjp | 0:d48d92e6c145 | 39 | HTTPMap map; |
shintamainjp | 0:d48d92e6c145 | 40 | HTTPStream stream; |
shintamainjp | 0:d48d92e6c145 | 41 | const std::string url = URLBASE_V1 + "statuses/home_timeline.xml"; |
shintamainjp | 0:d48d92e6c145 | 42 | char buf[BUFSIZ + 1] = {0}; |
shintamainjp | 0:d48d92e6c145 | 43 | |
shintamainjp | 0:d48d92e6c145 | 44 | result = HTTP_OK; |
shintamainjp | 0:d48d92e6c145 | 45 | completed = false; |
shintamainjp | 0:d48d92e6c145 | 46 | stream.readNext((byte*)buf, sizeof(buf) - 1); |
shintamainjp | 0:d48d92e6c145 | 47 | HTTPResult r = client.get(url.c_str(), &stream, this, &SuperTweetV1XML::callback); |
shintamainjp | 0:d48d92e6c145 | 48 | if (r != HTTP_OK) { |
shintamainjp | 0:d48d92e6c145 | 49 | while (!completed) { |
shintamainjp | 0:d48d92e6c145 | 50 | Net::poll(); |
shintamainjp | 0:d48d92e6c145 | 51 | if (stream.readable()) { |
shintamainjp | 0:d48d92e6c145 | 52 | buf[stream.readLen()] = 0; |
shintamainjp | 0:d48d92e6c145 | 53 | func(buf, stream.readLen()); |
shintamainjp | 0:d48d92e6c145 | 54 | stream.readNext((byte*)buf, sizeof(buf) - 1); |
shintamainjp | 0:d48d92e6c145 | 55 | } |
shintamainjp | 0:d48d92e6c145 | 56 | } |
shintamainjp | 0:d48d92e6c145 | 57 | } |
shintamainjp | 0:d48d92e6c145 | 58 | return result; |
shintamainjp | 0:d48d92e6c145 | 59 | } |
shintamainjp | 0:d48d92e6c145 | 60 | |
shintamainjp | 0:d48d92e6c145 | 61 | HTTPResult SuperTweetV1XML::postStatusesUpdate(const std::string datatext, void (*func)(char *buf, size_t siz)) { |
shintamainjp | 0:d48d92e6c145 | 62 | HTTPMap map; |
shintamainjp | 0:d48d92e6c145 | 63 | HTTPStream stream; |
shintamainjp | 0:d48d92e6c145 | 64 | map["status"] = datatext; |
shintamainjp | 0:d48d92e6c145 | 65 | const std::string url = URLBASE_V1 + "statuses/update.xml"; |
shintamainjp | 0:d48d92e6c145 | 66 | char buf[BUFSIZ + 1] = {0}; |
shintamainjp | 0:d48d92e6c145 | 67 | |
shintamainjp | 0:d48d92e6c145 | 68 | result = HTTP_OK; |
shintamainjp | 0:d48d92e6c145 | 69 | completed = false; |
shintamainjp | 0:d48d92e6c145 | 70 | stream.readNext((byte*)buf, sizeof(buf) - 1); |
shintamainjp | 0:d48d92e6c145 | 71 | HTTPResult r = client.post(url.c_str(), map, &stream, this, &SuperTweetV1XML::callback); |
shintamainjp | 0:d48d92e6c145 | 72 | while (!completed) { |
shintamainjp | 0:d48d92e6c145 | 73 | Net::poll(); |
shintamainjp | 0:d48d92e6c145 | 74 | if (stream.readable()) { |
shintamainjp | 0:d48d92e6c145 | 75 | buf[stream.readLen()] = 0; |
shintamainjp | 0:d48d92e6c145 | 76 | func(buf, stream.readLen()); |
shintamainjp | 0:d48d92e6c145 | 77 | stream.readNext((byte*)buf, sizeof(buf) - 1); |
shintamainjp | 0:d48d92e6c145 | 78 | } |
shintamainjp | 0:d48d92e6c145 | 79 | } |
shintamainjp | 0:d48d92e6c145 | 80 | return result; |
shintamainjp | 0:d48d92e6c145 | 81 | } |
shintamainjp | 0:d48d92e6c145 | 82 | |
shintamainjp | 0:d48d92e6c145 | 83 | void SuperTweetV1XML::callback(HTTPResult r) { |
shintamainjp | 0:d48d92e6c145 | 84 | result = r; |
shintamainjp | 0:d48d92e6c145 | 85 | completed = true; |
shintamainjp | 0:d48d92e6c145 | 86 | } |