3 * Copyright (C) 2009-2010 troorl
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * troorl <troorl@gmail.com>
30 public class RestAPIRe : RestAPIAbstract {
32 public RestAPIRe(Account? _account) {
36 public RestUrls get_urls() {
41 public void send_dm(string user, string text) throws RestError {
45 string req_url = urls.direct_new();
47 var map = new HashTable<string, string>(str_hash, str_equal);
48 map.insert("screen_name", user);
49 map.insert("text", text);
51 if(account != null && account.service == "identi.ca") //client name for identi.ca
52 map.insert("source", Config.APPNAME);
54 make_request(req_url, "POST", map);
58 public Status update_status(string text,
59 string reply_id = "") throws RestError, ParseError {
64 string req_url = urls.status_update();
66 var map = new HashTable<string, string>(str_hash, str_equal);
67 map.insert("status", text);
69 if(account != null && account.service == "identi.ca") //client name for identi.ca
70 map.insert("source", Config.APPNAME);
73 map.insert("in_reply_to_status_id", reply_id);
75 string data = make_request(req_url, "POST", map);
78 var result = parse_status(data);
84 private Status parse_status(string data) throws ParseError {
85 Status status = new Status();
86 Xml.Doc* xmlDoc = Parser.parse_memory(data, (int)data.size());
88 throw new ParseError.CODE("Invalid XML data");
90 Xml.Node* rootNode = xmlDoc->get_root_element();
93 //changing locale to C
94 string currentLocale = GLib.Intl.setlocale(GLib.LocaleCategory.TIME, null);
95 GLib.Intl.setlocale(GLib.LocaleCategory.TIME, "C");
98 for(iter = rootNode->children; iter != null; iter = iter->next) {
99 if (iter->type != ElementType.ELEMENT_NODE)
104 status.id = iter->get_content();
108 status.created_at = str_to_time(iter->get_content());
109 status.created_at_s = iter->get_content();
113 status.text = iter->get_content();
116 case "in_reply_to_screen_name":
117 status.to_user = iter->get_content();
120 case "in_reply_to_status_id":
121 status.to_status_id = iter->get_content();
124 case "retweeted_status":
125 status.is_retweet = true;
131 for(iter_user = iter->children->next; iter_user != null; iter_user = iter_user->next) {
132 switch(iter_user->name) {
137 status.user_name = iter_user->get_content();
141 status.user_screen_name = iter_user->get_content();
144 case "profile_image_url":
145 status.user_avatar = iter_user->get_content();
153 //back to the normal locale
154 GLib.Intl.setlocale(GLib.LocaleCategory.TIME, currentLocale);