tjplurker 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tjplurker/core.rb +496 -66
- data/lib/tjplurker/legacy.rb +94 -94
- metadata +12 -11
data/lib/tjplurker/core.rb
CHANGED
@@ -34,6 +34,7 @@ module TJP
|
|
34
34
|
})
|
35
35
|
end
|
36
36
|
|
37
|
+
|
37
38
|
# return:: authorize URL
|
38
39
|
def get_authorize_url
|
39
40
|
@request_token = @consumer.get_request_token
|
@@ -72,62 +73,22 @@ module TJP
|
|
72
73
|
return json
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
-
#:section: Offical API wrapping
|
77
|
-
|
76
|
+
# :section: Users
|
78
77
|
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
# Should can be a JSON list of friend ids in String formatting or Ruby Array, e.g.
|
84
|
-
# \[3,4,66,34] or "\[3,4,66,34]" will only be plurked to these user ids.
|
85
|
-
# If it's [0] then the Plurk is privatley posted to the poster's friends.
|
86
|
-
# no_comments:: If set to 1 or "1", then responses are disabled for this plurk.
|
87
|
-
# If set to 2 or "2", then only friends can respond to this plurk.
|
88
|
-
# lang:: The plurk's language. Can be following:
|
89
|
-
# 'en': 'English', 'pt_BR': 'Português', 'cn': '中文 (中国)', 'ca': 'Català', 'el': 'Ελληνικά'
|
90
|
-
# 'dk': 'Dansk', 'de': 'Deutsch', 'es': 'Español', 'sv': 'Svenska', 'nb': 'Norsk bokmål'
|
91
|
-
# 'hi': 'Hindi', 'ro': 'Română', 'hr': 'Hrvatski', 'fr': 'Français', 'ru': 'Pусский'
|
92
|
-
# 'it': 'Italiano', 'ja': '日本語', 'he': 'עברית', 'hu': 'Magyar', 'ne': 'Nederlands', 'th': 'ไทย'
|
93
|
-
# 'ta_fp': 'Filipino', 'in': 'Bahasa Indonesia', 'pl': 'Polski', 'ar': 'العربية', 'fi': 'Finnish'
|
94
|
-
# 'tr_ch': '中文 (繁體中文)', 'tr': 'Türkçe', 'ga': 'Gaeilge', 'sk': 'Slovenský'
|
95
|
-
# 'uk': 'українська', 'fa': 'فارسی
|
96
|
-
def plurk_add content, qualifier=':', limited_to=nil, no_comments=nil, lang='tr_ch'
|
97
|
-
method = "/APP/Timeline/plurkAdd"
|
98
|
-
limited_to = limited_to.to_s if limited_to.is_a? Array
|
99
|
-
attr = {:content=>content, :qualifier=>qualifier, :limited_to=>limited_to, :no_comments=>no_comments, :lang=>lang}
|
100
|
-
api(method, attr)
|
101
|
-
end
|
102
|
-
|
103
|
-
# Adds a responses to +plurk_id+. Language is inherited from the plurk.
|
104
|
-
def response_add plurk_id, content, qualifier=':'
|
105
|
-
method = "/APP/Responses/responseAdd"
|
106
|
-
attr = {:plurk_id=>plurk_id, :content=>content, :qualifier=>qualifier}
|
107
|
-
api(method, attr)
|
108
|
-
end
|
109
|
-
|
110
|
-
# Accept all friendship requests as friends.
|
111
|
-
def add_all_as_friends
|
112
|
-
method = "/APP/Alerts/addAllAsFriends"
|
78
|
+
# Returns info about current user's karma, including current karma,
|
79
|
+
# karma growth, karma graph and the latest reason why the karma has dropped.
|
80
|
+
def get_karma_stats
|
81
|
+
method = "/APP/Users/getKarmaStats"
|
113
82
|
api(method)
|
114
83
|
end
|
115
84
|
|
116
|
-
#
|
117
|
-
def become_fan fan_id
|
118
|
-
method = "/APP/FriendsFans/becomeFan"
|
119
|
-
attr = {:fan_id=>fan_id}
|
120
|
-
api(method, attr)
|
121
|
-
end
|
85
|
+
# :section: Profile
|
122
86
|
|
123
|
-
# Returns
|
124
|
-
#
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
method = "/APP/FriendsFans/getFriendsByOffset"
|
129
|
-
attr = {:user_id=>user_id, :offset=>offset, :limit=>limit}
|
130
|
-
api(method, attr)
|
87
|
+
# Returns data that's private for the current user.
|
88
|
+
# This can be used to construct a profile and render a timeline of the latest plurks.
|
89
|
+
def get_own_profile
|
90
|
+
method = "/APP/Profile/getOwnProfile"
|
91
|
+
api(method)
|
131
92
|
end
|
132
93
|
|
133
94
|
# Fetches public information such as a user's public plurks and basic information.
|
@@ -138,16 +99,7 @@ module TJP
|
|
138
99
|
api(method, attr)
|
139
100
|
end
|
140
101
|
|
141
|
-
#
|
142
|
-
# Warning:: It has bugs in offecial Plurk API.
|
143
|
-
# offset:: Return plurks newer than offset, formatted as 2009-6-20T21:55:34.
|
144
|
-
# limit:: The max number of plurks to be returned (default: 20)
|
145
|
-
# filter:: Can be only_user, only_responded, only_private or only_favorite
|
146
|
-
def get_plurks offset=nil, limit=nil, filter=nil
|
147
|
-
method = "/APP/Timeline/getPlurks"
|
148
|
-
attr = {:limit=>limit, :offset=>offset}
|
149
|
-
api(method, attr)
|
150
|
-
end
|
102
|
+
# :section: Real Time Notifications
|
151
103
|
|
152
104
|
# Get instant notifications when there are new plurks and responses on a user's timeline.
|
153
105
|
# Generally you don't need call this because comet_channel will automatically do that for you.
|
@@ -198,12 +150,457 @@ module TJP
|
|
198
150
|
json
|
199
151
|
end
|
200
152
|
|
201
|
-
# :section:
|
153
|
+
# :section: Polling
|
154
|
+
|
155
|
+
# You should use this call to find out if there any new plurks posted to the user's timeline.
|
156
|
+
# It's much more efficient than doing it with timeline_get_plurks, so please use it :)
|
157
|
+
# offset:: Return plurks newer than offset, formatted as 2009-6-20T21:55:34 in String or in Time.
|
158
|
+
# limit:: The max number of plurks to be returned (default: 20)
|
159
|
+
def get_plurks offset, limit=nil
|
160
|
+
method = "/APP/Polling/getPlurks"
|
161
|
+
offset = offset.utc.strftime("%Y-%m-%dT%H:%M:%S") if offset.is_a? Time
|
162
|
+
attr = {:offset=>offset, :limit=>limit}
|
163
|
+
api(method, attr)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Use this call to find out if there are unread plurks on a user's timeline.
|
167
|
+
def get_unread_count
|
168
|
+
method = "/APP/Polling/getUnreadCount"
|
169
|
+
api(method)
|
170
|
+
end
|
171
|
+
|
172
|
+
# :section: Timeline
|
173
|
+
|
174
|
+
# Get one plurk from user's timeline
|
175
|
+
# plurk_id:: Can be Integer or String
|
176
|
+
def get_plurk plurk_id
|
177
|
+
method = "/APP/Timeline/getPlurk"
|
178
|
+
attr = {:plurk_id=>plurk_id}
|
179
|
+
api(method, attr)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Get plurks from user's timeline
|
183
|
+
# offset:: Return plurks older than offset, formatted as 2009-6-20T21:55:34 in String or in Time.
|
184
|
+
# limit:: The max number of plurks to be returned (default: 20)
|
185
|
+
# filter:: Can be only_user, only_responded, only_private or only_favorite
|
186
|
+
def timeline_get_plurks offset=nil, limit=nil, filter=nil
|
187
|
+
method = "/APP/Timeline/getPlurks"
|
188
|
+
offset = offset.utc.strftime("%Y-%m-%dT%H:%M:%S") if offset.is_a? Time
|
189
|
+
attr = {:offset=>offset, :limit=>limit, :filter=>filter}
|
190
|
+
api(method, attr)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Get unread plurks from user's timeline
|
194
|
+
# offset:: Return plurks newer than offset, formatted as 2009-6-20T21:55:34 in String or in Time.
|
195
|
+
# limit:: The max number of plurks to be returned (default: 20)
|
196
|
+
# filter:: Can be only_user, only_responded, only_private or only_favorite
|
197
|
+
def get_unread_plurks offset=nil, limit=nil, filter=nil
|
198
|
+
method = "/APP/Timeline/getUnreadPlurks"
|
199
|
+
offset = offset.utc.strftime("%Y-%m-%dT%H:%M:%S") if offset.is_a? Time
|
200
|
+
attr = {:offset=>offset, :limit=>limit, :filter=>filter}
|
201
|
+
api(method, attr)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Get public plurks from user's timeline
|
205
|
+
# user_id:: The user_id of the public plurks owner to get. Can be integer (like 34) or nick name (like amix).
|
206
|
+
# offset:: Return plurks newer than offset, formatted as 2009-6-20T21:55:34 in String or in Time.
|
207
|
+
# limit:: The max number of plurks to be returned (default: 20)
|
208
|
+
# filter:: Can be only_user, only_responded, only_private or only_favorite
|
209
|
+
def get_public_plurks user_id, offset=nil, limit=nil, filter=nil
|
210
|
+
method = "/APP/Timeline/getPublicPlurks"
|
211
|
+
offset = offset.utc.strftime("%Y-%m-%dT%H:%M:%S") if offset.is_a? Time
|
212
|
+
attr = {:user_id=>user_id, :offset=>offset, :limit=>limit, :filter=>filter}
|
213
|
+
api(method, attr)
|
214
|
+
end
|
215
|
+
|
216
|
+
# qualifier:: The Plurk's qualifier, must be in English. Can be following:
|
217
|
+
# loves, likes, shares, gives, hates, wants, has, will, asks, wishes, was,
|
218
|
+
# feels, thinks, says, is, :, freestyle, hopes, needs, wonders
|
219
|
+
# limited_to:: Limit the plurk only to some users (also known as private plurking).
|
220
|
+
# Should can be a JSON list of friend ids in String formatting or Ruby Array, e.g.
|
221
|
+
# \[3,4,66,34] or "\[3,4,66,34]" will only be plurked to these user ids.
|
222
|
+
# If it's [0] then the Plurk is privatley posted to the poster's friends.
|
223
|
+
# no_comments:: If set to 1 or "1", then responses are disabled for this plurk.
|
224
|
+
# If set to 2 or "2", then only friends can respond to this plurk.
|
225
|
+
# lang:: The plurk's language. Can be following:
|
226
|
+
# 'en': 'English', 'pt_BR': 'Português', 'cn': '中文 (中国)', 'ca': 'Català', 'el': 'Ελληνικά'
|
227
|
+
# 'dk': 'Dansk', 'de': 'Deutsch', 'es': 'Español', 'sv': 'Svenska', 'nb': 'Norsk bokmål'
|
228
|
+
# 'hi': 'Hindi', 'ro': 'Română', 'hr': 'Hrvatski', 'fr': 'Français', 'ru': 'Pусский'
|
229
|
+
# 'it': 'Italiano', 'ja': '日本語', 'he': 'עברית', 'hu': 'Magyar', 'ne': 'Nederlands', 'th': 'ไทย'
|
230
|
+
# 'ta_fp': 'Filipino', 'in': 'Bahasa Indonesia', 'pl': 'Polski', 'ar': 'العربية', 'fi': 'Finnish'
|
231
|
+
# 'tr_ch': '中文 (繁體中文)', 'tr': 'Türkçe', 'ga': 'Gaeilge', 'sk': 'Slovenský'
|
232
|
+
# 'uk': 'українська', 'fa': 'فارسی
|
233
|
+
def plurk_add content, qualifier=':', limited_to=nil, no_comments=nil, lang='tr_ch'
|
234
|
+
method = "/APP/Timeline/plurkAdd"
|
235
|
+
limited_to = limited_to.to_s if limited_to.is_a? Array
|
236
|
+
attr = {:content=>content, :qualifier=>qualifier, :limited_to=>limited_to, :no_comments=>no_comments, :lang=>lang}
|
237
|
+
api(method, attr)
|
238
|
+
end
|
239
|
+
|
240
|
+
# plurk_id:: The id of the plurk.
|
241
|
+
def plurk_delete plurk_id
|
242
|
+
method = "/APP/Timeline/plurkDelete"
|
243
|
+
attr = {:plurk_id=>plurk_id}
|
244
|
+
api(method, attr)
|
245
|
+
end
|
246
|
+
|
247
|
+
# plurk_id:: The id of the plurk.
|
248
|
+
# content:: The content of plurk.
|
249
|
+
def plurk_edit plurk_id, content
|
250
|
+
method = "/APP/Timeline/plurkEdit"
|
251
|
+
attr = {:plurk_id=>plurk_id, :content=>content}
|
252
|
+
api(method, attr)
|
253
|
+
end
|
254
|
+
|
255
|
+
# ids:: The plurk ids, formated as JSON String or Ruby Array, e.g. "[342,23242,2323]" or [342,23242,2323]
|
256
|
+
def mute_plurks ids
|
257
|
+
method = "/APP/Timeline/mutePlurks"
|
258
|
+
ids = ids.to_s if ids.is_a? Array
|
259
|
+
attr = {:ids=>ids}
|
260
|
+
api(method, attr)
|
261
|
+
end
|
262
|
+
|
263
|
+
# ids:: The plurk ids, formated as JSON String or Ruby Array, e.g. "[342,23242,2323]" or [342,23242,2323]
|
264
|
+
def unmute_plurks
|
265
|
+
method = "/APP/Timeline/unmutePlurks"
|
266
|
+
ids = ids.to_s if ids.is_a? Array
|
267
|
+
attr = {:ids=>ids}
|
268
|
+
api(method, attr)
|
269
|
+
end
|
270
|
+
|
271
|
+
# ids:: The plurk ids, formated as JSON String or Ruby Array, e.g. "[342,23242,2323]" or [342,23242,2323]
|
272
|
+
def favorite_plurks ids
|
273
|
+
method = "/APP/Timeline/favoritePlurks"
|
274
|
+
ids = ids.to_s if ids.is_a? Array
|
275
|
+
attr = {:ids=>ids}
|
276
|
+
api(method, attr)
|
277
|
+
end
|
278
|
+
|
279
|
+
# ids:: The plurk ids, formated as JSON String or Ruby Array, e.g. "[342,23242,2323]" or [342,23242,2323]
|
280
|
+
def unfavorite_plurks ids
|
281
|
+
method = "/APP/Timeline/unfavoritePlurks"
|
282
|
+
ids = ids.to_s if ids.is_a? Array
|
283
|
+
attr = {:ids=>ids}
|
284
|
+
api(method, attr)
|
285
|
+
end
|
286
|
+
|
287
|
+
# ids:: The plurk ids, formated as JSON String or Ruby Array, e.g. "[342,23242,2323]" or [342,23242,2323]
|
288
|
+
# note_position:: If true responses_seen of the plurks will be updated as well (to match response_count).
|
289
|
+
def mark_as_read ids, note_position=nil
|
290
|
+
method = "/APP/Timeline/markAsRead"
|
291
|
+
ids = ids.to_s if ids.is_a? Array
|
292
|
+
attr = {:ids=>ids, :note_position=>note_position}
|
293
|
+
api(method, attr)
|
294
|
+
end
|
295
|
+
|
296
|
+
# :section: Response
|
297
|
+
|
298
|
+
# Fetches responses for plurk with plurk_id and some basic info about the users.
|
299
|
+
# plurk_id:: The plurk that the responses belong to.
|
300
|
+
# from_response:: Only fetch responses from an offset - could be 5, 10 or 15 (default: 0)
|
301
|
+
def response_get plurk_id, from_response=nil
|
302
|
+
method = "/APP/Responses/get"
|
303
|
+
attr = {:plurk_id=>plurk_id, :from_response=>from_response}
|
304
|
+
api(method, attr)
|
305
|
+
end
|
306
|
+
|
307
|
+
# Adds a responses to plurk_id. Language is inherited from the plurk.
|
308
|
+
# plurk_id:: The plurk that the responses belong to.
|
309
|
+
# content:: The response's text.
|
310
|
+
# qualifier:: The Plurk's qualifier, must be in English. Refers to plurk_add.
|
311
|
+
def response_add plurk_id, content, qualifier=':'
|
312
|
+
method = "/APP/Responses/responseAdd"
|
313
|
+
attr = {:plurk_id=>plurk_id, :content=>content, :qualifier=>qualifier}
|
314
|
+
api(method, attr)
|
315
|
+
end
|
316
|
+
|
317
|
+
#Deletes a response. A user can delete own responses or responses that are posted to own plurks.
|
318
|
+
# response_id:: The id of the response to delete.
|
319
|
+
# plurk_id:: The plurk that the response belongs to.
|
320
|
+
def response_delete response_id, plurk_id
|
321
|
+
method = "/APP/Responses/responseDelete"
|
322
|
+
attr = {:response_id=>response_id, :plurk_id=>plurk_id}
|
323
|
+
api(method, attr)
|
324
|
+
end
|
325
|
+
|
326
|
+
# :section: Friends and Fans
|
327
|
+
|
328
|
+
# Returns user_id's friend list in chucks of 100 friends at a time.
|
329
|
+
# However, We suggest you use get_friends instead of get_friends_by_offset
|
330
|
+
# limit:: The max number of friends to be returned.
|
331
|
+
# offset:: Can be Numeric or String, e.g. 10, "20", 30, "40" etc.
|
332
|
+
# return:: An Array
|
333
|
+
def get_friends_by_offset user_id, limit=100, offset=0
|
334
|
+
method = "/APP/FriendsFans/getFriendsByOffset"
|
335
|
+
attr = {:user_id=>user_id, :offset=>offset, :limit=>limit}
|
336
|
+
api(method, attr)
|
337
|
+
end
|
338
|
+
|
339
|
+
# Returns user_id's fans list in chucks of 100 fans at a time.
|
340
|
+
# However, We suggest you use get_fans instead of get_fans_by_offset
|
341
|
+
# limit:: The max number of friends to be returned.
|
342
|
+
# offset:: Can be Numeric or String, e.g. 10, "20", 30, "40" etc.
|
343
|
+
# return:: An Array
|
344
|
+
def get_fans_by_offset user_id, limit=100, offset=0
|
345
|
+
method = "/APP/FriendsFans/getFansByOffset"
|
346
|
+
attr = {:user_id=>user_id, :offset=>offset, :limit=>limit}
|
347
|
+
api(method, attr)
|
348
|
+
end
|
349
|
+
|
350
|
+
# Returns users that the current logged in user follows as fan - in chucks of 100 fans at a time.
|
351
|
+
# However, We suggest you use get_following instead of get_following_by_offset
|
352
|
+
# limit:: The max number of friends to be returned.
|
353
|
+
# offset:: Can be Numeric or String, e.g. 10, "20", 30, "40" etc.
|
354
|
+
# return:: An Array
|
355
|
+
def get_following_by_offset limit=100, offset=0
|
356
|
+
method = "/APP/FriendsFans/getFollowingByOffset"
|
357
|
+
attr = {:offset=>offset, :limit=>limit}
|
358
|
+
api(method, attr)
|
359
|
+
end
|
360
|
+
|
361
|
+
# Create a friend request to friend_id. User with friend_id has to accept a friendship.
|
362
|
+
# friend_id:: The ID of the user you want to befriend.
|
363
|
+
def become_friend friend_id
|
364
|
+
method = "/APP/FriendsFans/becomeFriend"
|
365
|
+
attr = {:friend_id=>friend_id}
|
366
|
+
api(method, attr)
|
367
|
+
end
|
368
|
+
|
369
|
+
# Remove friend with ID friend_id. friend_id won't be notified.
|
370
|
+
# friend_id:: The ID of the user you want to remove
|
371
|
+
def remove_as_friend friend_id
|
372
|
+
method = "/APP/FriendsFans/removeAsFriend"
|
373
|
+
attr = {:friend_id=>friend_id}
|
374
|
+
api(method, attr)
|
375
|
+
end
|
376
|
+
|
377
|
+
# Become fan of fan_id. To stop being a fan of someone, use set_following
|
378
|
+
# fan_id:: The ID of the user you want to become fan of
|
379
|
+
def become_fan fan_id
|
380
|
+
method = "/APP/FriendsFans/becomeFan"
|
381
|
+
attr = {:fan_id=>fan_id}
|
382
|
+
api(method, attr)
|
383
|
+
end
|
384
|
+
|
385
|
+
# Update following of user_id. A user can befriend someone, but can unfollow them.
|
386
|
+
# This request is also used to stop following someone as a fan.
|
387
|
+
# user_id:: The ID of the user you want to follow/unfollow
|
388
|
+
# follow:: Normally, true if the user should be followed, and false if the user should be unfollowed.
|
389
|
+
# Actually, toggle the follwing state no matter you give true or false
|
390
|
+
def set_following user_id, follow=true
|
391
|
+
method = "/APP/FriendsFans/setFollowing"
|
392
|
+
attr = {:user_id=>user_id, :follow=>follow}
|
393
|
+
api(method, attr)
|
394
|
+
end
|
395
|
+
|
396
|
+
# Returns a JSON object of the logged in users friends (nick name and full name).
|
397
|
+
# This information can be used to construct auto-completion for private plurking.
|
398
|
+
# Notice that a friend list can be big, depending on how many friends a user has,
|
399
|
+
# so this list should be lazy-loaded in your application.
|
400
|
+
def get_completion
|
401
|
+
method = "/APP/FriendsFans/getCompletion"
|
402
|
+
api(method)
|
403
|
+
end
|
404
|
+
|
405
|
+
# :section: Alerts
|
406
|
+
# ===General data structures
|
407
|
+
# The data returned by getActive and getHistory can be of following nature:
|
408
|
+
# Friendship request:
|
409
|
+
# {"type": "friendship_request", "from_user": {"nick_name": ...}, "posted": ...}
|
410
|
+
#
|
411
|
+
# Friendship pending:
|
412
|
+
# {"type": "friendship_pending", "to_user": {"nick_name": ...}, "posted": ...}
|
413
|
+
#
|
414
|
+
# New fan notification: (does not require actions from the user)
|
415
|
+
# {"type": "new_fan", "new_fan": {"nick_name": ...}, "posted": ...}
|
416
|
+
#
|
417
|
+
# Friendship accepted notification: (does not require actions from the user)
|
418
|
+
# {"type": "friendship_accepted", "friend_info": {"nick_name": ...}, "posted": ...}
|
419
|
+
#
|
420
|
+
# New friend notification: (does not require actions from the user)
|
421
|
+
# {"type": "new_friend", "new_friend": {"nick_name": ...}, "posted": ...}
|
422
|
+
|
423
|
+
# Return a JSON list of current active alerts.
|
424
|
+
def get_active
|
425
|
+
method = "/APP/Alerts/getActive"
|
426
|
+
api(method)
|
427
|
+
end
|
428
|
+
|
429
|
+
# Return a JSON list of past 30 alerts.
|
430
|
+
def get_history
|
431
|
+
method = "/APP/Alerts/getHistory"
|
432
|
+
api(method)
|
433
|
+
end
|
434
|
+
|
435
|
+
# user_id:: The user_id that has asked for friendship.
|
436
|
+
def add_as_fan user_id
|
437
|
+
method = "/APP/Alerts/addAsFan"
|
438
|
+
attr = {:user_id=>user_id}
|
439
|
+
api(method, attr)
|
440
|
+
end
|
441
|
+
|
442
|
+
# Accept all friendship requests as fans.
|
443
|
+
def add_all_as_fan
|
444
|
+
method = "/APP/Alerts/addAllAsFan"
|
445
|
+
api(method)
|
446
|
+
end
|
447
|
+
|
448
|
+
# Accept all friendship requests as friends.
|
449
|
+
def add_all_as_friends
|
450
|
+
method = "/APP/Alerts/addAllAsFriends"
|
451
|
+
api(method)
|
452
|
+
end
|
453
|
+
|
454
|
+
# Accept user_id as friend.
|
455
|
+
# user_id:: The user_id that has asked for friendship.
|
456
|
+
def add_as_friend user_id
|
457
|
+
method = "/APP/Alerts/addAsFriend"
|
458
|
+
attr = {:user_id=>user_id}
|
459
|
+
api(method, attr)
|
460
|
+
end
|
461
|
+
|
462
|
+
# Deny friendship to user_id.
|
463
|
+
# user_id:: The user_id that has asked for friendship.
|
464
|
+
def deny_friendship user_id
|
465
|
+
method = "/APP/Alerts/denyFriendship"
|
466
|
+
attr = {:user_id=>user_id}
|
467
|
+
api(method, attr)
|
468
|
+
end
|
469
|
+
|
470
|
+
# Remove notification to user with id user_id.
|
471
|
+
# user_id:: The user_id that the current user has requested friendship for.
|
472
|
+
def remove_notification user_id
|
473
|
+
method = "/APP/Alerts/removeNotification"
|
474
|
+
attr = {:user_id=>user_id}
|
475
|
+
api(method, attr)
|
476
|
+
end
|
477
|
+
|
478
|
+
# :section: Search
|
479
|
+
|
480
|
+
# Returns the latest 20 plurks on a search term.
|
481
|
+
# query:: The query after Plurks.
|
482
|
+
# offset:: A plurk_id of the oldest Plurk in the last search result.
|
483
|
+
def plurk_search query, offset=nil
|
484
|
+
method = "/APP/PlurkSearch/search"
|
485
|
+
attr = {:query=>query, :offset=>offset}
|
486
|
+
api(method, attr)
|
487
|
+
end
|
488
|
+
|
489
|
+
# Returns 10 users that match query, users are sorted by karma.
|
490
|
+
# query:: The query after users.
|
491
|
+
# offset:: Page offset, like 10, 20, 30 etc.
|
492
|
+
def user_search query, offset=0
|
493
|
+
method = "/APP/UserSearch/search"
|
494
|
+
attr = {:query=>query, :offset=>offset}
|
495
|
+
api(method, attr)
|
496
|
+
end
|
497
|
+
|
498
|
+
# :section: Emoticons
|
499
|
+
|
500
|
+
# Emoticons are a big part of Plurk since they make it easy to express feelings.
|
501
|
+
# Check out current Plurk emoticons. This call returns a JSON object that looks like:
|
502
|
+
# {"karma": {"0": [[":-))", "http:\/\/statics.plurk.com\/XXX.gif"], ...], ...},
|
503
|
+
# "recuited": {"10": [["(bigeyes)", "http:\/\/statics.plurk.com\/XXX.gif"], ...], ...} }
|
504
|
+
# emoticons["karma"][25] denotes that the user has to have karma over 25 to use these emoticons.
|
505
|
+
# emoticons["recuited"][10] means that the user has to have user.recuited >= 10 to use these emoticons.
|
506
|
+
# It's important to check for these things on the client as well,
|
507
|
+
# since the emoticon levels are checked in the models.
|
508
|
+
def emoticons_get
|
509
|
+
method = "/APP/Emoticons/get"
|
510
|
+
api(method)
|
511
|
+
end
|
512
|
+
|
513
|
+
# :section: Blocks
|
514
|
+
|
515
|
+
# offset:: What page should be shown, e.g. 0, 10, 20.
|
516
|
+
def blocks_get offset=0
|
517
|
+
method = "/APP/Blocks/get"
|
518
|
+
attr = {:offset=>offset}
|
519
|
+
api(method, attr)
|
520
|
+
end
|
521
|
+
|
522
|
+
# user_id:: The id of the user that should be blocked.
|
523
|
+
def block user_id
|
524
|
+
method = "/APP/Blocks/block"
|
525
|
+
attr = {:user_id=>user_id}
|
526
|
+
api(method, attr)
|
527
|
+
end
|
528
|
+
|
529
|
+
# user_id: The id of the user that should be unblocked.
|
530
|
+
def unblock user_id
|
531
|
+
method = "/APP/Blocks/unblock"
|
532
|
+
attr = {:user_id=>user_id}
|
533
|
+
api(method, attr)
|
534
|
+
end
|
535
|
+
|
536
|
+
# :section: Cliques
|
537
|
+
|
538
|
+
def get_cliques
|
539
|
+
method = "/APP/Cliques/getCliques"
|
540
|
+
api(method)
|
541
|
+
end
|
542
|
+
|
543
|
+
# clique_name:: The name of the new clique
|
544
|
+
def get_clique clique_name
|
545
|
+
method = "/APP/Cliques/getClique"
|
546
|
+
attr = {:clique_name=>clique_name}
|
547
|
+
api(method, attr)
|
548
|
+
end
|
549
|
+
|
550
|
+
# clique_name:: The name of the new clique
|
551
|
+
def create_clique clique_name
|
552
|
+
method = "/APP/Cliques/createClique"
|
553
|
+
attr = {:clique_name=>clique_name}
|
554
|
+
api(method, attr)
|
555
|
+
end
|
556
|
+
|
557
|
+
# clique_name:: The name of the clique to rename
|
558
|
+
# new_name:: The name of the new clique
|
559
|
+
def rename_clique clique_name, new_name
|
560
|
+
method = "/APP/Cliques/renameClique"
|
561
|
+
attr = {:clique_name=>clique_name, :new_name=>new_name}
|
562
|
+
api(method, attr)
|
563
|
+
end
|
564
|
+
|
565
|
+
# clique_name:: The name of the clique
|
566
|
+
# user_id:: The user to add to the clique
|
567
|
+
def cliques_add clique_name, user_id
|
568
|
+
method = "/APP/Cliques/add"
|
569
|
+
attr = {:clique_name=>clique_name, :user_id=>user_id}
|
570
|
+
api(method, attr)
|
571
|
+
end
|
572
|
+
|
573
|
+
# clique_name:: The name of the clique
|
574
|
+
# user_id:: The user to remove from the clique
|
575
|
+
def cliques_remove clique_name, user_id
|
576
|
+
method = "/APP/Cliques/remove"
|
577
|
+
attr = {:clique_name=>clique_name, :user_id=>user_id}
|
578
|
+
api(method, attr)
|
579
|
+
end
|
580
|
+
|
581
|
+
# :section: PlurkTop
|
582
|
+
|
583
|
+
def get_collections
|
584
|
+
method = "/APP/PlurkTop/getCollections"
|
585
|
+
api(method)
|
586
|
+
end
|
587
|
+
|
588
|
+
# collection_name:: only get plurks in specified collection
|
589
|
+
# offset:: offset of Plurks in PlurkTop, should be an float, e.g. 0.99.
|
590
|
+
# limit:: number of plurks returned (default: 30)
|
591
|
+
# sorting:: the way to sort plurks in PlurkTop, can be "hot" for sorting by popularity or "new" for posted time.
|
592
|
+
def plurk_top_get_plurks collection_name, limit=nil, offset=nil, sorting=nil
|
593
|
+
method = "/APP/PlurkTop/getPlurks"
|
594
|
+
attr = {:collection_name=>collection_name, :limit=>limit, :offset=>offset, :sorting=>sorting}
|
595
|
+
api(method, attr)
|
596
|
+
end
|
597
|
+
|
598
|
+
# :section: TJPlurker Provided
|
202
599
|
# Those methos were all provided by TJPlukrer instead of Plurk
|
203
600
|
|
204
601
|
# Improved from get_friends_by_offset for getting all friends from a user
|
205
602
|
# return:: An Array
|
206
|
-
def get_friends user_id,
|
603
|
+
def get_friends user_id, at_least=nil
|
207
604
|
list = []
|
208
605
|
offset = 0;
|
209
606
|
loop{
|
@@ -211,7 +608,39 @@ module TJP
|
|
211
608
|
size = set.size
|
212
609
|
break if size == 0
|
213
610
|
list |= set
|
214
|
-
break if
|
611
|
+
break if at_least && list.size>=at_least
|
612
|
+
offset += size
|
613
|
+
}
|
614
|
+
return list
|
615
|
+
end
|
616
|
+
|
617
|
+
# Improved from get_fans_by_offset for getting all fans from a user
|
618
|
+
# return:: An Array
|
619
|
+
def get_fans user_id, at_least=nil
|
620
|
+
list = []
|
621
|
+
offset = 0;
|
622
|
+
loop{
|
623
|
+
set = get_fans_by_offset(user_id, 100, offset)
|
624
|
+
size = set.size
|
625
|
+
break if size == 0
|
626
|
+
list |= set
|
627
|
+
break if at_least && list.size>=at_least
|
628
|
+
offset += size
|
629
|
+
}
|
630
|
+
return list
|
631
|
+
end
|
632
|
+
|
633
|
+
# Improved from get_following_by_offset for getting all fans from a user
|
634
|
+
# return:: An Array
|
635
|
+
def get_following at_least=nil
|
636
|
+
list = []
|
637
|
+
offset = 0;
|
638
|
+
loop{
|
639
|
+
set = get_following_by_offset(100, offset)
|
640
|
+
size = set.size
|
641
|
+
break if size == 0
|
642
|
+
list |= set
|
643
|
+
break if at_least && list.size>=at_least
|
215
644
|
offset += size
|
216
645
|
}
|
217
646
|
return list
|
@@ -287,10 +716,11 @@ module TJP
|
|
287
716
|
end
|
288
717
|
|
289
718
|
module_function
|
290
|
-
# Convert user name into user_id, e.g. Given "tonytonyjan", return
|
719
|
+
# Convert user name into user_id, e.g. Given "tonytonyjan", return 5874158 in Integer
|
720
|
+
# return:: user id in Integer
|
291
721
|
def get_uid user_name
|
292
722
|
open("http://www.plurk.com/#{user_name}").read =~ /"user_id": (\d*)/
|
293
723
|
raise "User \"#{user_name}\" not found." unless $1
|
294
|
-
return $1
|
724
|
+
return $1.to_i
|
295
725
|
end
|
296
726
|
end
|
data/lib/tjplurker/legacy.rb
CHANGED
@@ -41,10 +41,10 @@ module Legacy
|
|
41
41
|
# Plurk user ID.
|
42
42
|
attr_reader :user
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
=begin
|
45
|
+
[auto_login] 是否在建構時自動登入
|
46
|
+
If +auto_login+ sets +true+, it will autologin while constructing.
|
47
|
+
=end
|
48
48
|
def initialize api_key, user, passwd, auto_login=true
|
49
49
|
@user, @passwd, @api_key = user, passwd, api_key
|
50
50
|
@cookie = nil
|
@@ -54,23 +54,23 @@ module Legacy
|
|
54
54
|
end
|
55
55
|
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
=begin
|
58
|
+
:section: Offical API wrapping
|
59
|
+
對Plurk官方API做包裹
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
Plurk API wrapping
|
62
|
+
=end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
64
|
+
=begin
|
65
|
+
登入
|
66
|
+
[no_data] 是否將登入成功後的訊息簡化成:
|
67
|
+
{"success_text": "ok"}
|
68
|
+
否則將回傳使用者的詳細資料
|
69
|
+
|
70
|
+
If no_data sets true, the successful login message was simplified as follow:
|
71
|
+
{"success_text": "ok"}
|
72
|
+
Otherwise, more details of user's profile were retured.
|
73
|
+
=end
|
74
74
|
def login no_data=true
|
75
75
|
method = "/API/Users/login"
|
76
76
|
attr = {:username=>@user, :password=>@passwd, :api_key=>@api_key}
|
@@ -78,91 +78,91 @@ module Legacy
|
|
78
78
|
api(method, attr)
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
=begin
|
82
|
+
發噗
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
範例:
|
85
|
+
require 'tjplurker'
|
86
|
+
tjp = TJPlurker.new("API Key", "帳號", "密碼")
|
87
|
+
tjp.plurk_add("Hello TJPlurker")
|
88
|
+
=end
|
89
89
|
def plurk_add content, qualifier=':', limited_to=nil, no_comments=nil, lang='tr_ch'
|
90
90
|
method = "/API/Timeline/plurkAdd"
|
91
91
|
attr = {:api_key=>@api_key, :content=>content, :qualifier=>qualifier,:limited_to=>limited_to, :no_comments=>no_comments, :lang=>lang}
|
92
92
|
api(method, attr)
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
95
|
+
=begin
|
96
|
+
回噗
|
97
|
+
[qualifier] 可以是如下的字串:
|
98
|
+
|
99
|
+
Can be the following string:
|
100
|
+
loves, likes, shares, gives, hates, wants, has, will,
|
101
|
+
asks, wishes, was, feels, thinks, says, is, :, freestyle, hopes, needs, wonders
|
102
|
+
範例:
|
103
|
+
require 'tjplurker'
|
104
|
+
tjp = TJPlurker.new("API Key", "帳號", "密碼")
|
105
|
+
json_obj = tjp.plurk_add("Hello TJPlurker")
|
106
|
+
tjp.response_add(json_obj["plurk_id"], "This is a reply.", "says")
|
107
|
+
=end
|
108
108
|
def response_add plurk_id, content, qualifier=':'
|
109
109
|
method = "/API/Responses/responseAdd"
|
110
110
|
attr = {:api_key=>@api_key, :plurk_id=>plurk_id, :content=>content, :qualifier=>qualifier}
|
111
111
|
api(method, attr)
|
112
112
|
end
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
=begin
|
115
|
+
成為粉絲
|
116
|
+
[fan_id] 你想追蹤的人的ID
|
117
|
+
|
118
|
+
The ID of the user you want to become fan of
|
119
|
+
=end
|
120
120
|
def become_fan fan_id
|
121
121
|
method = "/API/FriendsFans/becomeFan"
|
122
122
|
attr = {:api_key=>@api_key, :fan_id=>fan_id}
|
123
123
|
api(method, attr)
|
124
124
|
end
|
125
125
|
|
126
|
-
|
127
|
-
|
126
|
+
=begin
|
127
|
+
接受所有的好友邀請
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
Accept all friendship requests as friends.
|
130
|
+
Successful return:
|
131
|
+
{"success_text": "ok"}
|
132
|
+
=end
|
133
133
|
def add_all_as_friends
|
134
134
|
method = "/API/Alerts/addAllAsFriends"
|
135
135
|
attr = {:api_key=>@api_key}
|
136
136
|
api(method, attr)
|
137
137
|
end
|
138
138
|
|
139
|
-
|
140
|
-
|
139
|
+
=begin
|
140
|
+
取得使用者的好友名單
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
Returns user_id's friend list
|
143
|
+
[limit] The max number of friends to be returned (default 10).
|
144
|
+
[Successful return] 好友名單陣列
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
146
|
+
Returns a list of JSON objects users, e.g.
|
147
|
+
[{"id": 3, "nick_name": "alvin", ...}, ...]
|
148
|
+
[warnning] +limit+的最大值被官方設定為100,這個方法沒有很好用,建議你用tjp_get_friends取代
|
149
|
+
This maximum of +limit+ is set 100 officially, this method is not that useful.
|
150
|
+
We suggest you use get_friend_list instead of get_friends_by_offset.
|
151
|
+
=end
|
152
152
|
def get_friends_by_offset user_id, limit=100, offset='0'
|
153
153
|
method = "/API/FriendsFans/getFriendsByOffset"
|
154
154
|
attr = {:api_key=>@api_key, :user_id=>user_id, :offset=>offset, :limit=>limit}
|
155
155
|
api(method, attr)
|
156
156
|
end
|
157
157
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
158
|
+
=begin
|
159
|
+
Fetches public information such as a user's public plurks and basic information.
|
160
|
+
Fetches also if the current user is following the user, are friends with or is a fan.
|
161
|
+
[Successful return] Returns a JSON object with a lot of information
|
162
|
+
that can be used to construct a user's public profile and timeline.
|
163
|
+
[Error returns] HTTP 400 BAD REQUEST with {"error_text": "Invalid user_id"} as body
|
164
|
+
HTTP 400 BAD REQUEST with {"error_text": "User not found"} as body
|
165
|
+
=end
|
166
166
|
def get_public_profile user_id
|
167
167
|
method = "/API/Profile/getPublicProfile"
|
168
168
|
attr = {:api_key=>@api_key, :user_id=>user_id}
|
@@ -213,29 +213,29 @@ module Legacy
|
|
213
213
|
json
|
214
214
|
end
|
215
215
|
|
216
|
-
|
217
|
-
|
218
|
-
|
216
|
+
=begin
|
217
|
+
:section: TJPlurker provided
|
218
|
+
由TJPlurker提供的工具,非官方有的方法
|
219
219
|
|
220
|
-
|
221
|
-
|
220
|
+
Those methos were all provided by TJPlukrer instead of plurk
|
221
|
+
=end
|
222
222
|
|
223
|
-
|
224
|
-
|
223
|
+
=begin
|
224
|
+
這個方法游TJPlurker提供的非官方功能,改良自get_friends_by_offset,用於取得使用者所有的好友
|
225
225
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
226
|
+
This method is provided by TJPlurker. Improved from get_friends_by_offset for getting all friends of a user
|
227
|
+
[max] 取得多少好友,nil則無限制
|
228
|
+
|
229
|
+
The maximum number of your request. Set +nil+ for unlimited.
|
230
|
+
[return] 陣列
|
231
|
+
|
232
|
+
An array contains friends
|
233
|
+
範例:
|
234
|
+
require 'tjplurker'
|
235
|
+
tjp = TJPlurker.new("API Key", "帳號", "密碼")
|
236
|
+
friend_list = tjp.tjp_get_friends("5874158")
|
237
|
+
friend_list.each{|friend| puts friend["uid"]}
|
238
|
+
=end
|
239
239
|
def tjp_get_friends user_id, max=nil
|
240
240
|
list = []
|
241
241
|
offset = 0;
|
@@ -250,10 +250,10 @@ module Legacy
|
|
250
250
|
return list
|
251
251
|
end
|
252
252
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
253
|
+
=begin
|
254
|
+
用於追蹤大量使用者的河道
|
255
|
+
[level] 深度,如等於1會追蹤使用者的所有好友,等於2則會追蹤使用者所有的好友以及好友的好友
|
256
|
+
=end
|
257
257
|
def tjp_super_become_fan fan_id, level=1
|
258
258
|
return if level<=0
|
259
259
|
become_fan(fan_id)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tjplurker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &17981736 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.5.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17981736
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: oauth
|
27
|
-
requirement: &
|
27
|
+
requirement: &17981448 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,20 +32,21 @@ dependencies:
|
|
32
32
|
version: 0.4.5
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17981448
|
36
36
|
description: A safe Plurk API wrapper based on Ruby and mainly designed for easily
|
37
37
|
making plurk robot.
|
38
|
-
email: tonytonyjan
|
38
|
+
email: tonytonyjan@gmail.com
|
39
39
|
executables: []
|
40
40
|
extensions: []
|
41
41
|
extra_rdoc_files: []
|
42
42
|
files:
|
43
|
-
- lib/tjplurker.rb
|
44
43
|
- lib/tjplurker/core.rb
|
45
44
|
- lib/tjplurker/legacy.rb
|
46
45
|
- lib/tjplurker/robot.rb
|
46
|
+
- lib/tjplurker.rb
|
47
47
|
homepage: http://code.google.com/p/tjplurker
|
48
|
-
licenses:
|
48
|
+
licenses:
|
49
|
+
- New BSD
|
49
50
|
post_install_message:
|
50
51
|
rdoc_options: []
|
51
52
|
require_paths:
|
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
65
|
version: '0'
|
65
66
|
requirements: []
|
66
67
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.7.2
|
68
69
|
signing_key:
|
69
70
|
specification_version: 3
|
70
71
|
summary: A safe Plurk API wrapper based on Ruby and mainly designed for easily making
|