@@ -26,6 +26,18 @@ class InoreaderClient(object):
2626
2727 # paths
2828 TOKEN_PATH = '/oauth2/token'
29+ USER_INFO_PATH = 'user-info'
30+ TAG_LIST_PATH = 'tag/list'
31+ SUBSCRIPTION_LIST_PATH = 'subscription/list'
32+ STREAM_CONTENTS_PATH = 'stream/contents/'
33+ EDIT_TAG_PATH = 'edit-tag'
34+
35+ # tags
36+ GENERAL_TAG_TEMPLATE = 'user/-/label/{}'
37+ READ_TAG = 'user/-/state/com.google/read'
38+ STARRED_TAG = 'user/-/state/com.google/starred'
39+ LIKED_TAG = 'user/-/state/com.google/like'
40+ BROADCAST_TAG = 'user/-/state/com.google/broadcast'
2941
3042 def __init__ (self , app_id , app_key , access_token , refresh_token ,
3143 expires_at , userid = None , config_manager = None ):
@@ -83,13 +95,13 @@ def refresh_access_token(self):
8395 def userinfo (self ):
8496 self .check_token ()
8597
86- url = urljoin (BASE_URL , 'user-info' )
98+ url = urljoin (BASE_URL , self . USER_INFO_PATH )
8799 return self .parse_response (self .session .post (url ))
88100
89101 def get_folders (self ):
90102 self .check_token ()
91103
92- url = urljoin (BASE_URL , 'tag/list' )
104+ url = urljoin (BASE_URL , self . TAG_LIST_PATH )
93105 params = {'types' : 1 , 'counts' : 1 }
94106 response = self .parse_response (self .session .post (url , params = params ))
95107
@@ -107,7 +119,7 @@ def get_folders(self):
107119 def get_tags (self ):
108120 self .check_token ()
109121
110- url = urljoin (BASE_URL , 'tag/list' )
122+ url = urljoin (BASE_URL , self . TAG_LIST_PATH )
111123 params = {'types' : 1 , 'counts' : 1 }
112124 response = self .parse_response (self .session .post (url , params = params ))
113125
@@ -125,7 +137,7 @@ def get_tags(self):
125137 def get_subscription_list (self ):
126138 self .check_token ()
127139
128- url = urljoin (BASE_URL , 'subscription/list' )
140+ url = urljoin (BASE_URL , self . SUBSCRIPTION_LIST_PATH )
129141 response = self .parse_response (self .session .get (url ))
130142 for item in response ['subscriptions' ]:
131143 yield Subscription .from_json (item )
@@ -141,7 +153,7 @@ def get_stream_contents(self, stream_id, c=''):
141153 def __get_stream_contents (self , stream_id , continuation = '' ):
142154 self .check_token ()
143155
144- url = urljoin (BASE_URL , 'stream/contents/' + quote_plus (stream_id ))
156+ url = urljoin (BASE_URL , self . STREAM_CONTENTS_PATH + quote_plus (stream_id ))
145157 params = {
146158 'n' : 50 , # default 20, max 1000
147159 'r' : '' ,
@@ -157,16 +169,13 @@ def __get_stream_contents(self, stream_id, continuation=''):
157169 def fetch_unread (self , folder = None , tags = None ):
158170 self .check_token ()
159171
160- url = urljoin (BASE_URL , 'stream/contents/' )
172+ url = urljoin (BASE_URL , self . STREAM_CONTENTS_PATH )
161173 if folder :
162174 url = urljoin (
163175 url ,
164- quote_plus ('user/{}/label/{}' . format (self . userid , folder ))
176+ quote_plus (self . GENERAL_TAG_TEMPLATE . format (folder ))
165177 )
166- params = {
167- 'xt' : 'user/{}/state/com.google/read' .format (self .userid ),
168- 'c' : str (uuid4 ())
169- }
178+ params = {'xt' : self .READ_TAG , 'c' : str (uuid4 ())}
170179
171180 response = self .parse_response (self .session .post (url , params = params ))
172181 for data in response ['items' ]:
@@ -195,7 +204,7 @@ def fetch_unread(self, folder=None, tags=None):
195204 def add_general_label (self , articles , label ):
196205 self .check_token ()
197206
198- url = urljoin (BASE_URL , 'edit-tag' )
207+ url = urljoin (BASE_URL , self . EDIT_TAG_PATH )
199208 for start in range (0 , len (articles ), 10 ):
200209 end = min (start + 10 , len (articles ))
201210 params = {
@@ -205,16 +214,16 @@ def add_general_label(self, articles, label):
205214 self .parse_response (self .session .post (url , params = params ), json_data = False )
206215
207216 def add_tag (self , articles , tag ):
208- self .add_general_label (articles , 'user/-/label/{}' .format (tag ))
217+ self .add_general_label (articles , self . GENERAL_TAG_TEMPLATE .format (tag ))
209218
210219 def mark_as_read (self , articles ):
211- self .add_general_label (articles , 'user/-/state/com.google/read' )
220+ self .add_general_label (articles , self . READ_TAG )
212221
213222 def mark_as_starred (self , articles ):
214- self .add_general_label (articles , 'user/-/state/com.google/starred' )
223+ self .add_general_label (articles , self . STARRED_TAG )
215224
216225 def mark_as_liked (self , articles ):
217- self .add_general_label (articles , 'user/-/state/com.google/like' )
226+ self .add_general_label (articles , self . LIKED_TAG )
218227
219228 def broadcast (self , articles ):
220- self .add_general_label (articles , 'user/-/state/com.google/broadcast' )
229+ self .add_general_label (articles , self . BROADCAST_TAG )
0 commit comments