File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ class SO (object ):
2
+
3
+ def __init__ (self ,** kwargs ):
4
+ self .base_url = kwargs .pop ('base_url' ,[]) or 'http://api.stackoverflow.com/1.1'
5
+ self .uriparts = kwargs .pop ('uriparts' ,[])
6
+ for k ,v in kwargs .items ():
7
+ setattr (self ,k ,v )
8
+
9
+ def __getattr__ (self ,key ):
10
+ self .uriparts .append (key )
11
+ return self .__class__ (** self .__dict__ )
12
+
13
+ def __getitem__ (self ,key ):
14
+ return self .__getattr__ (key )
15
+
16
+ def __call__ (self ,** kwargs ):
17
+ call_url = "%s/%s" % (self .base_url ,"/" .join (self .uriparts ))
18
+ self .uriparts = []
19
+ return call_url
20
+
21
+ if __name__ == '__main__' :
22
+ print SO ().abc .mno .ghi .jkl ()
23
+ print SO ().abc .mno ['ghi' ].jkl ()
24
+ user1 = SO ().users ['55562' ]
25
+ print user1 .questions .unanswered ()
26
+ print user1 .questions .answered ()
You can’t perform that action at this time.
0 commit comments