about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/stream.cpp84
-rw-r--r--src/tweet.cpp11
-rw-r--r--src/tweet.h4
3 files changed, 56 insertions, 43 deletions
diff --git a/src/stream.cpp b/src/stream.cpp index 17dcce7..d2b3afe 100644 --- a/src/stream.cpp +++ b/src/stream.cpp
@@ -101,55 +101,55 @@ namespace twitter {
101 101
102 void stream::run(std::string url) 102 void stream::run(std::string url)
103 { 103 {
104 curl::curl_ios<stream> ios(this, [] (void* contents, size_t size, size_t nmemb, void* userp) { 104 _backoff_type = backoff::none;
105 return static_cast<stream*>(userp)->write(static_cast<char*>(contents), size, nmemb); 105 _backoff_amount = std::chrono::milliseconds(0);
106 }); 106 for (;;)
107 {
108 curl::curl_ios<stream> ios(this, [] (void* contents, size_t size, size_t nmemb, void* userp) {
109 return static_cast<stream*>(userp)->write(static_cast<char*>(contents), size, nmemb);
110 });
107 111
108 curl::curl_easy conn(ios); 112 curl::curl_easy conn(ios);
109 curl::curl_header headers; 113 curl::curl_header headers;
110 std::string oauth_header; 114 std::string oauth_header;
111 115
112 try 116 try
113 { 117 {
114 oauth_header = _client._oauth_client->getFormattedHttpHeader(OAuth::Http::Get, url, ""); 118 oauth_header = _client._oauth_client->getFormattedHttpHeader(OAuth::Http::Get, url, "");
115 119
116 if (!oauth_header.empty()) 120 if (!oauth_header.empty())
121 {
122 headers.add(oauth_header);
123 }
124 } catch (const OAuth::ParseError& error)
117 { 125 {
118 headers.add(oauth_header); 126 std::cout << "Error generating OAuth header:" << std::endl;
119 } 127 std::cout << error.what() << std::endl;
120 } catch (const OAuth::ParseError& error) 128 std::cout << "This is likely due to a malformed URL." << std::endl;
121 {
122 std::cout << "Error generating OAuth header:" << std::endl;
123 std::cout << error.what() << std::endl;
124 std::cout << "This is likely due to a malformed URL." << std::endl;
125 129
126 assert(false); 130 assert(false);
127 } 131 }
128 132
129 try 133 try
130 { 134 {
131 conn.add<CURLOPT_HEADERFUNCTION>(nullptr); 135 conn.add<CURLOPT_HEADERFUNCTION>(nullptr);
132 conn.add<CURLOPT_HEADERDATA>(nullptr); 136 conn.add<CURLOPT_HEADERDATA>(nullptr);
133 conn.add<CURLOPT_XFERINFOFUNCTION>([] (void* cdata, curl_off_t, curl_off_t, curl_off_t, curl_off_t) { 137 conn.add<CURLOPT_XFERINFOFUNCTION>([] (void* cdata, curl_off_t, curl_off_t, curl_off_t, curl_off_t) {
134 return static_cast<stream*>(cdata)->progress(); 138 return static_cast<stream*>(cdata)->progress();
135 }); 139 });
136 conn.add<CURLOPT_XFERINFODATA>(this); 140 conn.add<CURLOPT_XFERINFODATA>(this);
137 conn.add<CURLOPT_NOPROGRESS>(0); 141 conn.add<CURLOPT_NOPROGRESS>(0);
138 //conn.add<CURLOPT_VERBOSE>(1); 142 //conn.add<CURLOPT_VERBOSE>(1);
139 //conn.add<CURLOPT_DEBUGFUNCTION>(my_trace); 143 //conn.add<CURLOPT_DEBUGFUNCTION>(my_trace);
140 conn.add<CURLOPT_URL>(url.c_str()); 144 conn.add<CURLOPT_URL>(url.c_str());
141 conn.add<CURLOPT_HTTPHEADER>(headers.get()); 145 conn.add<CURLOPT_HTTPHEADER>(headers.get());
142 } catch (const curl::curl_exception& error) 146 } catch (const curl::curl_exception& error)
143 { 147 {
144 error.print_traceback(); 148 error.print_traceback();
149
150 assert(false);
151 }
145 152
146 assert(false);
147 }
148
149 _backoff_type = backoff::none;
150 _backoff_amount = std::chrono::milliseconds(0);
151 for (;;)
152 {
153 bool failure = false; 153 bool failure = false;
154 try 154 try
155 { 155 {
diff --git a/src/tweet.cpp b/src/tweet.cpp index 4849fb7..4abe2f8 100644 --- a/src/tweet.cpp +++ b/src/tweet.cpp
@@ -66,4 +66,15 @@ namespace twitter {
66 return *_author == _client.getUser(); 66 return *_author == _client.getUser();
67 } 67 }
68 68
69 std::string tweet::getURL() const
70 {
71 std::ostringstream urlstr;
72 urlstr << "https://twitter.com";
73 urlstr << _author->getScreenName();
74 urlstr << "/statuses/";
75 urlstr << _id;
76
77 return urlstr.str();
78 }
79
69}; 80};
diff --git a/src/tweet.h b/src/tweet.h index 3035d51..a29e45c 100644 --- a/src/tweet.h +++ b/src/tweet.h
@@ -39,7 +39,7 @@ namespace twitter {
39 { 39 {
40 return *_author; 40 return *_author;
41 } 41 }
42 42
43 bool isRetweet() const 43 bool isRetweet() const
44 { 44 {
45 return _is_retweet; 45 return _is_retweet;
@@ -63,6 +63,8 @@ namespace twitter {
63 63
64 bool isMyTweet() const; 64 bool isMyTweet() const;
65 65
66 std::string getURL() const;
67
66 private: 68 private:
67 69
68 const client& _client; 70 const client& _client;