constructor facility added
[statusbox:statusbox.git] / src / api / status.js
1 net.status.js.Status=function(){
2         this.id=null;
3         
4         this.init=function(_id){
5                 this.construct();
6                 this.id=_id;
7                 this.method="/statuses/show.json";
8                 this.params={id:this.id};
9                 this.type="net.status.js.Status";
10                 return this;
11         };
12         
13         this.retweet=function(){
14                 return this.retweet(this.id);
15         };
16         
17         this.favorite=function(){
18                 return this.favorite(this.id);
19         };
20         
21         this.unfavorite=function(){
22                 return this.unfavorite(this.id);
23         };
24         
25         this.reply=function(message){
26                 return this.reply(message,this.id);
27         };
28         
29         this.destroy=function(){
30                 this.proxy="POST";
31                 this.validateOnline();
32                 this.method="/statuses/destroy.json";
33                 this.params={id:this.id};
34                 this.type="net.status.js.Status";
35                 
36                 return this;
37         };
38         
39         this.retweets=function(){
40                 this.validateOnline();
41                 this.method="/statuses/retweets.json";
42                 this.params={id:this.id};
43                 this.type="net.status.js.Status";
44                 
45                 return this;
46         };
47         
48         this.retweeters=function(){
49                 this.validateOnline();
50                 this.method="/statuses/"+ this.id +"/retweeted_by.json";
51                 this.params=null;
52                 this.type="net.status.js.User";
53                 
54                 return this;
55         };
56         
57         this.inReplyTo=function(){
58                 return net.status.js.User.find(this.in_reply_to_user_id);
59         };
60 };
61
62 //inheritance
63 net.status.js.Status.prototype=new net.status.js.APIBase();
64
65 net.status.js.Status.find=function(id){
66         var status=new net.status.js.Status();
67         status.api(this.parent);
68         status.init(id);
69         return status;
70 };
71
72 /**
73  * 
74  * @param status 
75  * @param options optional parameter object
76  */
77 net.status.js.Status.update=function(_status,options){
78         var api=new net.status.js.APIBase();
79         api.api(this.parent);
80         //api.validateOnline();
81         api.proxy="POST";
82         api.method="/statuses/update.json";
83         var params={status:_status};
84         jQuery.extend(params,options);
85         api.params=params;
86         api.type="net.status.js.Status";
87         
88         return api;
89 };
90
91 net.status.js.Status.publicTimeline=function(){
92         var api=new net.status.js.APIBase();
93         api.api(this.parent);
94         api.method="/statuses/public_timeline.json";
95         api.params=null;
96         api.type="net.status.js.Status";
97         
98         return api;
99 };
100
101 net.status.js.Status.retweet=function(_id){
102         var api=new net.status.js.APIBase();
103         api.api(this.parent);
104         api.validateOnline();
105         api.proxy="POST";
106         api.method="/statuses/retweet.json";
107         api.params={id:_id};
108         api.type="net.status.js.Status";
109         
110         return api;
111 };
112
113 net.status.js.Status.favorite=function(_id){
114         var api=new net.status.js.APIBase();
115         api.api(this.parent);
116         api.validateOnline();
117         api.proxy="POST";
118         api.method="/favorites/create/"+_id+".json";
119         api.type="net.status.js.Status";
120         
121         return api;
122 };
123
124 net.status.js.Status.unfavorite=function(_id){
125         var api=new net.status.js.APIBase();
126         api.api(this.parent);
127         api.validateOnline();
128         api.proxy="POST";
129         api.method="/favorites/destroy/"+_id+".json";
130         api.type="net.status.js.Status";
131         
132         return api;
133 };
134
135 net.status.js.Status.reply=function(message,_id){
136         return net.status.js.Status.update(message, {in_reply_to_status_id:_id});
137 };
138