SuperTweet interface driver classes.

Dependents:   SuperTweet_TestProgram StarBoardOrangeExpansion1 GSL_04-Network_Twitter

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Tue Oct 12 22:20:38 2010 +0000
Child:
1:2d211e591fc8
Commit message:
First version.

Changed in this revision

SuperTweet.cpp Show annotated file Show diff for this revision Revisions of this file
SuperTweet.h Show annotated file Show diff for this revision Revisions of this file
SuperTweetV1XML.cpp Show annotated file Show diff for this revision Revisions of this file
SuperTweetV1XML.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperTweet.cpp	Tue Oct 12 22:20:38 2010 +0000
@@ -0,0 +1,23 @@
+/**
+ * SuperTweet API interface driver. (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include "SuperTweet.h"
+
+const std::string SuperTweet::URLBASE_V1 = "http://api.supertweet.net/1/";
+
+SuperTweet::SuperTweet(const std::string account, const std::string password)
+        : account(account), password(password), client() {
+    client.basicAuth(account.c_str(), password.c_str());
+    client.setTimeout(10000);
+}
+
+SuperTweet::~SuperTweet() {
+}
+
+void SuperTweet::setTimeout(int ms) {
+    client.setTimeout(ms);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperTweet.h	Tue Oct 12 22:20:38 2010 +0000
@@ -0,0 +1,24 @@
+/**
+ * SuperTweet API interface driver. (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include <string>
+#include "HTTPClient.h"
+
+class SuperTweet {
+public:
+    SuperTweet(const std::string account, const std::string password);
+    virtual ~SuperTweet();
+    void setTimeout(int ms);
+    virtual HTTPResult getStatusesUserTimeline(void (*func)(char *buf, size_t siz)) = 0;
+    virtual HTTPResult getStatusesHomeTimeline(void (*func)(char *buf, size_t siz)) = 0;
+    virtual HTTPResult postStatusesUpdate(const std::string datatext, void (*func)(char *buf, size_t siz)) = 0;
+protected:
+    static const std::string URLBASE_V1;
+    const std::string account;
+    const std::string password;
+    HTTPClient client;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperTweetV1XML.cpp	Tue Oct 12 22:20:38 2010 +0000
@@ -0,0 +1,86 @@
+/**
+ * SuperTweet API interface driver. (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include "SuperTweetV1XML.h"
+
+SuperTweetV1XML::SuperTweetV1XML(const std::string account, const std::string password)
+        : SuperTweet(account, password) {
+}
+
+SuperTweetV1XML::~SuperTweetV1XML() {
+}
+
+HTTPResult SuperTweetV1XML::getStatusesUserTimeline(void (*func)(char *buf, size_t siz)) {
+    HTTPMap map;
+    HTTPStream stream;
+    const std::string url = URLBASE_V1 + "statuses/user_timeline.xml";
+    char buf[BUFSIZ + 1] = {0};
+
+    result = HTTP_OK;
+    completed = false;
+    stream.readNext((byte*)buf, sizeof(buf) - 1);
+    HTTPResult r = client.get(url.c_str(), &stream, this, &SuperTweetV1XML::callback);
+    while (!completed) {
+        Net::poll();
+        if (stream.readable()) {
+            buf[stream.readLen()] = 0;
+            func(buf, stream.readLen());
+            stream.readNext((byte*)buf, sizeof(buf) - 1);
+        }
+    }
+    return result;
+}
+
+HTTPResult SuperTweetV1XML::getStatusesHomeTimeline(void (*func)(char *buf, size_t siz)) {
+    HTTPMap map;
+    HTTPStream stream;
+    const std::string url = URLBASE_V1 + "statuses/home_timeline.xml";
+    char buf[BUFSIZ + 1] = {0};
+
+    result = HTTP_OK;
+    completed = false;
+    stream.readNext((byte*)buf, sizeof(buf) - 1);
+    HTTPResult r = client.get(url.c_str(), &stream, this, &SuperTweetV1XML::callback);
+    if (r != HTTP_OK) {
+    while (!completed) {
+        Net::poll();
+        if (stream.readable()) {
+            buf[stream.readLen()] = 0;
+            func(buf, stream.readLen());
+            stream.readNext((byte*)buf, sizeof(buf) - 1);
+        }
+    }
+    }
+    return result;
+}
+
+HTTPResult SuperTweetV1XML::postStatusesUpdate(const std::string datatext, void (*func)(char *buf, size_t siz)) {
+    HTTPMap map;
+    HTTPStream stream;
+    map["status"] = datatext;
+    const std::string url = URLBASE_V1 + "statuses/update.xml";
+    char buf[BUFSIZ + 1] = {0};
+
+    result = HTTP_OK;
+    completed = false;
+    stream.readNext((byte*)buf, sizeof(buf) - 1);
+    HTTPResult r = client.post(url.c_str(), map, &stream, this, &SuperTweetV1XML::callback);
+    while (!completed) {
+        Net::poll();
+        if (stream.readable()) {
+            buf[stream.readLen()] = 0;
+            func(buf, stream.readLen());
+            stream.readNext((byte*)buf, sizeof(buf) - 1);
+        }
+    }
+    return result;
+}
+
+void SuperTweetV1XML::callback(HTTPResult r) {
+    result = r;
+    completed = true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperTweetV1XML.h	Tue Oct 12 22:20:38 2010 +0000
@@ -0,0 +1,21 @@
+/**
+ * SuperTweet API interface driver. (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include "SuperTweet.h"
+
+class SuperTweetV1XML : public SuperTweet {
+public:
+    SuperTweetV1XML(const std::string account, const std::string password);
+    virtual ~SuperTweetV1XML();
+    virtual HTTPResult getStatusesUserTimeline(void (*func)(char *buf, size_t siz));
+    virtual HTTPResult getStatusesHomeTimeline(void (*func)(char *buf, size_t siz));
+    virtual HTTPResult postStatusesUpdate(const std::string datatext, void (*func)(char *buf, size_t siz));
+private:
+    HTTPResult result;
+    bool completed;
+    void callback(HTTPResult r);
+};