Class: FriendFeed::Client
- Inherits:
-
Object
- Object
- FriendFeed::Client
- Defined in:
- lib/friendfeed.rb,
lib/friendfeed/unofficial.rb,
bin/tw2ff
Overview
Client library for FriendFeed API.
Constant Summary collapse
- API_URI =
Official API
ROOT_URI + "/api/"
- LOGIN_URI =
Unofficial API
ROOT_URI + "/account/login?v=2"
- EDIT_GROUP_URI =
ROOT_URI + '/a/editprofile'
Instance Attribute Summary collapse
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#remote_key ⇒ Object
readonly
Returns the value of attribute remote_key.
Instance Method Summary collapse
-
#add_blog(id, url, options = nil) ⇒ Object
Adds a blog feed to the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#add_comment(entryid, body) ⇒ Object
Adds a comment to a given entry.
-
#add_entry(title, options = nil) ⇒ Object
(also: #publish, #share)
Publishes (shares) a given entry.
-
#add_feed(id, url, options = nil) ⇒ Object
Adds a feed to the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#add_like(entryid) ⇒ Object
Adds a “like” to a given entry.
-
#add_service(id, service, options = nil) ⇒ Object
Adds a feed to the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#add_twitter(id, twitter_name) ⇒ Object
Adds a Twitter service to the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#api_login(nickname, remote_key) ⇒ Object
Performs a login with a
nickname
and remote key and returns self. -
#call_api(path, get_parameters = nil, post_parameters = nil, raw = false) ⇒ Object
Calls an official API specified by a
path
with optionalget_parameters
andpost_parameters
, and returns an object parsed from a JSON response. -
#change_picture(id, io) ⇒ Object
Changes the picture of the authenticated user, a group or an imaginary friend.
- #change_picture_to_url(id, url) ⇒ Object
-
#create_group(nickname, name, type = 'group') ⇒ Object
Creates a new feed of a given (unique)
nickname
and displayname
, and returns a unique ID string on success. -
#create_imaginary_friend(nickname) ⇒ Object
Creates an imaginary friend of a given
nickname
and returns a unique ID string on success. -
#delete_comment(entryid, commentid) ⇒ Object
Deletes a given comment.
-
#delete_entry(entryid) ⇒ Object
Deletes an existing entry of a given
entryid
. -
#delete_like(entryid) ⇒ Object
Deletes an existing “like” from a given entry.
-
#edit_blog(id, url, options = nil) ⇒ Object
Adds a blog feed to the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#edit_comment(entryid, commentid, body) ⇒ Object
Edits a given comment.
-
#edit_feed(id, serviceid, url, options = nil) ⇒ Object
Edits a feed of the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#edit_group(id, hash) ⇒ Object
Edits profile information of a group specified by a unique ID.
-
#edit_profile(hash) ⇒ Object
Edits profile information of the authenticated user.
-
#edit_service(id, serviceid, service, options = nil) ⇒ Object
Edits a service of the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#edit_twitter(id, serviceid, twitter_name) ⇒ Object
Edits a Twitter service of the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#get_entries(entryids) ⇒ Object
Gets an array of entries of given
entryids
. -
#get_entry(entryid) ⇒ Object
Gets an entry of a given
entryid
. -
#get_group(id) ⇒ Object
Gets profile information of a group specified by a unique ID.
-
#get_home_entries(options = nil) ⇒ Object
Gets an array of the entries the authenticated user would see on their home page.
-
#get_imaginary_friend(id) ⇒ Object
Gets profile information of one of the authenticated user’s imaginary friends.
-
#get_imaginary_friends ⇒ Object
Gets an array of profile information of the authenticated user’s imaginary friends.
-
#get_list_entries(nickname, options = nil) ⇒ Object
Gets an array of the entries for the authenticated user’s list of a given
nickname
. -
#get_list_profile(nickname) ⇒ Object
Gets profile information of the authenticated user’s list of a given
nickname
in hash. -
#get_multi_user_entries(nicknames, options = nil) ⇒ Object
Gets an array of the most recent entries from users of given
nicknames
. -
#get_picture(nickname = @nickname, size = 'small') ⇒ Object
Gets a picture of a user of a given
nickname
(defaulted to the authenticated user) in blob. -
#get_profile(nickname = @nickname) ⇒ Object
Gets profile information of a user of a given
nickname
, defaulted to the authenticated user, in hash. -
#get_profiles(nicknames) ⇒ Object
Gets an array of profile information of users of given
nicknames
. -
#get_public_entries(options = nil) ⇒ Object
Gets an array of the most recent public entries.
-
#get_real_friends(nickname = @nickname) ⇒ Object
Gets an array of profile information of friends of a user of a given
nickname
(defaulted to the authenticated user) is subscribing to. -
#get_room_entries(nickname, options = nil) ⇒ Object
Gets an array of the most recent entries in a room of a given
nickname
. -
#get_room_picture(nickname, size = 'small') ⇒ Object
Gets a picture of a room of a given
nickname
in blob. -
#get_room_profile(nickname) ⇒ Object
Gets profile information of a room of a given
nickname
in hash. -
#get_rooms_entries(options = nil) ⇒ Object
Gets an array of the entries the authenticated user would see on their rooms page.
-
#get_services(nickname = @nickname) ⇒ Object
Gets a list of services of a user or a room of a given
nickname
, defaulted to the authenticated user. -
#get_user_commented_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries a user of a given
nickname
(defaulted to the authenticated user) has commented on. -
#get_user_discussed_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries a user of a given
nickname
(defaulted to the authenticated user) has commented on or like’d. -
#get_user_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries from a user of a given
nickname
(defaulted to the authenticated user). -
#get_user_friend_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries from friends of a user of a given
nickname
(defaulted to the authenticated user). -
#get_user_liked_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries a user of a given
nickname
(defaulted to the authenticated user) has like’d. -
#hide_entry(entryid) ⇒ Object
Hides an existing entry of a given
entryid
. -
#login(nickname, password) ⇒ Object
Performs a login with a
nickname
andpassword
and returns self. -
#post(uri, query = {}) ⇒ Object
Posts a request to an internal API of FriendFeed and returns either a parser object for an HTML response or an object parsed from a JSON response).
-
#refresh_service(id, serviceid, service, options = nil) ⇒ Object
Refreshes a feed of the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#remove_blog(id, serviceid, url, options = nil) ⇒ Object
Removes a blog feed from the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#remove_feed(id, serviceid, url, options = nil) ⇒ Object
Removes a feed from the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#remove_service(id, serviceid, service, options = nil) ⇒ Object
Removes a service of the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#remove_twitter(id, serviceid, twitter_name, options = nil) ⇒ Object
Removes a Twitter service from the authenticated user, a group or an imaginary friend specified by a unique ID.
-
#rename_imaginary_friend(id, nickname) ⇒ Object
Renames an imaginary friend specified by a unique ID to a given
nickname
. -
#search(query, options = nil) ⇒ Object
Gets an array of entries that match a given
query
. -
#search_for_domain(url, options = nil) ⇒ Object
Gets an array of entries that link to a given
domain
. -
#search_for_url(url, options = nil) ⇒ Object
Gets an array of entries that link to a given
url
. -
#subscribe_to_room(nickname) ⇒ Object
Subscribes to a room of a given
nickname
and returns a status string. -
#subscribe_to_user(nickname) ⇒ Object
Subscribes to a user of a given
nickname
and returns a status string. -
#undelete_comment(entryid, commentid) ⇒ Object
Undeletes a given comment that is already deleted.
-
#undelete_entry(entryid) ⇒ Object
Undeletes a given entry that is already deleted.
-
#unhide_entry(entryid) ⇒ Object
Unhides a given entry that is already hidden.
-
#unsubscribe_from(id) ⇒ Object
Unsubscribe from a friend, a group or an imaginary friend specified by a unique ID.
-
#unsubscribe_from_room(nickname) ⇒ Object
Unsubscribes from a room of a given
nickname
and returns a status string. -
#unsubscribe_from_user(nickname) ⇒ Object
Unsubscribes from a user of a given
nickname
and returns a status string.
Instance Attribute Details
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
22 23 24 |
# File 'lib/friendfeed.rb', line 22 def nickname @nickname end |
#remote_key ⇒ Object (readonly)
Returns the value of attribute remote_key.
56 57 58 |
# File 'lib/friendfeed.rb', line 56 def remote_key @remote_key end |
Instance Method Details
#add_blog(id, url, options = nil) ⇒ Object
Adds a blog feed to the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘multiauth’
> ‘on’ when the blog has multiple authors, and ‘author’ =>
‘(name)’ to limit entries to those written by a specific author. [unofficial]
238 239 240 241 242 |
# File 'lib/friendfeed/unofficial.rb', line 238 def add_blog(id, url, = nil) params = { 'url' => url } params.update() if add_service(id, 'blog', ) end |
#add_comment(entryid, body) ⇒ Object
Adds a comment to a given entry.
345 346 347 348 349 350 351 |
# File 'lib/friendfeed.rb', line 345 def add_comment(entryid, body) require_api_login call_api('comment', nil, { 'entry' => entryid, 'body' => body, }) end |
#add_entry(title, options = nil) ⇒ Object Also known as: publish,
Publishes (shares) a given entry.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/friendfeed.rb', line 267 def add_entry(title, = nil) require_api_login = { 'title' => title } if .each { |key, value| case key = key.to_s when 'title', 'link', 'comment', 'room' [key] = value when 'images' value.each_with_index { |value, i| if url = String.try_convert(value) link = nil else if array = Array.try_convert(value) value1, value2 = *array elsif hash = Hash.try_convert(value) value1, value2 = *hash.values_at('url', 'link') else raise TypeError, "Each image must be specified by <image URL>, [<image URL>, <link URL>], or {'url' => <image URL>, 'link' => <link URL>}." end url = String.try_convert(value1) or raise TypeError, "can't convert #{value1.class} into String" link = String.try_convert(value2) or raise TypeError, "can't convert #{value2.class} into String" end ['image%d_url' % i] = url ['image%d_link' % i] = link if link } when 'audios' value.each_with_index { |value, i| if url = String.try_convert(value) link = nil else if array = Array.try_convert(value) value1, value2 = *array elsif hash = Hash.try_convert(value) value1, value2 = *hash.values_at('url', 'link') else raise TypeError, "Each audio must be specified by <audio URL>, [<audio URL>, <link URL>], or {'url' => <audio URL>, 'link' => <link URL>}." end url = String.try_convert(value1) or raise TypeError, "can't convert #{value1.class} into String" link = String.try_convert(value2) or raise TypeError, "can't convert #{value2.class} into String" end ['audio%d_url' % i] = url ['audio%d_link' % i] = link if link } when 'files' value.each_with_index { |value, i| if file = IO.try_convert(value) link = nil else if array = Array.try_convert(value) value1, value2 = *array elsif hash = Hash.try_convert(value) value1, value2 = *hash.values_at('file', 'link') else raise TypeError, "Each file must be specified by <file IO>, [<file IO>, <link URL>], or {'file' => <file IO>, 'link' => <link URL>}." end file = IO.try_convert(value1) or raise TypeError, "can't convert #{value1.class} into IO" link = String.try_convert(value2) or raise TypeError, "can't convert #{value2.class} into String" end ['file%d' % i] = file ['file%d_link' % i] = link if link } end } end call_api('share', nil, )['entries'].first end |
#add_feed(id, url, options = nil) ⇒ Object
Adds a feed to the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘isstatus’ => ‘on’ to display entries as messages (no link), and ‘importcomment’ => ‘on’ to include entry description as a comment. [unofficial]
227 228 229 230 231 |
# File 'lib/friendfeed/unofficial.rb', line 227 def add_feed(id, url, = nil) params = { 'url' => url } params.update() if add_service(id, 'feed', ) end |
#add_like(entryid) ⇒ Object
Adds a “like” to a given entry.
383 384 385 386 387 388 |
# File 'lib/friendfeed.rb', line 383 def add_like(entryid) require_api_login call_api('like', nil, { 'entry' => entryid, }) end |
#add_service(id, service, options = nil) ⇒ Object
Adds a feed to the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘isstatus’ => ‘on’ to display entries as messages (no link), and ‘importcomment’ => ‘on’ to include entry description as a comment. [unofficial]
178 179 180 181 182 183 184 185 |
# File 'lib/friendfeed/unofficial.rb', line 178 def add_service(id, service, = nil) params = { 'stream' => id, 'service' => service, } params.update() if post(ROOT_URI + '/a/configureservice', params) end |
#add_twitter(id, twitter_name) ⇒ Object
Adds a Twitter service to the authenticated user, a group or an imaginary friend specified by a unique ID. [unofficial]
246 247 248 |
# File 'lib/friendfeed/unofficial.rb', line 246 def add_twitter(id, twitter_name) add_service(id, 'twitter', 'username' => twitter_name) end |
#api_login(nickname, remote_key) ⇒ Object
Performs a login with a nickname
and remote key and returns self. This enables call of any official API that requires authentication. It is not needed to call this method if you have called login(), which internally obtains a remote key and calls this method. An exception is raised if authentication fails.
64 65 66 67 68 69 70 71 72 |
# File 'lib/friendfeed.rb', line 64 def api_login(nickname, remote_key) @nickname = nickname @remote_key = remote_key @api_agent = get_api_agent() @api_agent.auth(@nickname, @remote_key) validate self end |
#call_api(path, get_parameters = nil, post_parameters = nil, raw = false) ⇒ Object
Calls an official API specified by a path
with optional get_parameters
and post_parameters
, and returns an object parsed from a JSON response. If post_parameters
is given, a POST request is issued. A GET request is issued otherwise.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/friendfeed.rb', line 78 def call_api(path, get_parameters = nil, post_parameters = nil, raw = false) api_agent = get_api_agent() uri = API_URI + path if get_parameters uri.query = get_parameters.map { |key, value| if array = Array.try_convert(value) value = array.join(',') end URI.encode(key) + "=" + URI.encode(value) }.join('&') end if post_parameters body = api_agent.post(uri, post_parameters).body else body = api_agent.get_file(uri) end if raw body else JSON.parse(body) end end |
#change_picture(id, io) ⇒ Object
Changes the picture of the authenticated user, a group or an imaginary friend. [unofficial]
309 310 311 312 |
# File 'lib/friendfeed/unofficial.rb', line 309 def change_picture(id, io) post(ROOT_URI + '/a/changepicture', 'stream' => id, 'picture' => io) end |
#change_picture_to_url(id, url) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'bin/tw2ff', line 100 def change_picture_to_url(id, url) t = Tempfile.open("picture") t.write get_file(url) t.close File.open(t.path) { |f| change_picture(id, f) } t.unlink end |
#create_group(nickname, name, type = 'group') ⇒ Object
Creates a new feed of a given (unique) nickname
and display name
, and returns a unique ID string on success. The type
can be one of “group”, “microblog” and “public”. Like other methods in general, an exception is raised on failure. [unofficial]
133 134 135 |
# File 'lib/friendfeed/unofficial.rb', line 133 def create_group(nickname, name, type = 'group') post(ROOT_URI + '/a/createfeed', 'nickname' => nickname, 'name' => name, 'type' => type).xpath("(//a[@class='l_feedinvite'])[1]/@sid").to_s end |
#create_imaginary_friend(nickname) ⇒ Object
Creates an imaginary friend of a given nickname
and returns a unique ID string on success. Like other methods in general, an exception is raised on failure. [unofficial]
323 324 325 |
# File 'lib/friendfeed/unofficial.rb', line 323 def create_imaginary_friend(nickname) post(ROOT_URI + '/a/createimaginary', 'name' => nickname).xpath("//*[@id='serviceseditor']/@streamid").to_s end |
#delete_comment(entryid, commentid) ⇒ Object
Deletes a given comment.
364 365 366 367 368 369 370 |
# File 'lib/friendfeed.rb', line 364 def delete_comment(entryid, commentid) require_api_login call_api('comment/delete', nil, { 'entry' => entryid, 'comment' => commentid, }) end |
#delete_entry(entryid) ⇒ Object
Deletes an existing entry of a given entryid
.
399 400 401 402 403 404 |
# File 'lib/friendfeed.rb', line 399 def delete_entry(entryid) require_api_login call_api('entry/delete', nil, { 'entry' => entryid, }) end |
#delete_like(entryid) ⇒ Object
Deletes an existing “like” from a given entry.
391 392 393 394 395 396 |
# File 'lib/friendfeed.rb', line 391 def delete_like(entryid) require_api_login call_api('like/delete', nil, { 'entry' => entryid, }) end |
#edit_blog(id, url, options = nil) ⇒ Object
Adds a blog feed to the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘multiauth’
> ‘on’ when the blog has multiple authors, and ‘author’ =>
‘(name)’ to limit entries to those written by a specific author. [unofficial]
265 266 267 268 269 |
# File 'lib/friendfeed/unofficial.rb', line 265 def edit_blog(id, url, = nil) params = { 'url' => url } params.update() if edit_service(id, 'blog', ) end |
#edit_comment(entryid, commentid, body) ⇒ Object
Edits a given comment.
354 355 356 357 358 359 360 361 |
# File 'lib/friendfeed.rb', line 354 def edit_comment(entryid, commentid, body) require_api_login call_api('comment', nil, { 'entry' => entryid, 'comment' => commentid, 'body' => body, }) end |
#edit_feed(id, serviceid, url, options = nil) ⇒ Object
Edits a feed of the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘isstatus’ => ‘on’ to display entries as messages (no link), and ‘importcomment’ => ‘on’ to include entry description as a comment. [unofficial]
254 255 256 257 258 |
# File 'lib/friendfeed/unofficial.rb', line 254 def edit_feed(id, serviceid, url, = nil) params = { 'url' => url } params.update() if edit_service(id, 'feed', ) end |
#edit_group(id, hash) ⇒ Object
Edits profile information of a group specified by a unique ID. Supported fields are ‘nickname’, ‘name’, ‘description’, ‘access’ (‘private’, ‘semipublic’ or ‘public’), and ‘anyoneinvite’ (none or ‘1’). [unofficial]
168 169 170 171 172 |
# File 'lib/friendfeed/unofficial.rb', line 168 def edit_group(id, hash) param_hash = get_group(id) param_hash.update(hash) post(EDIT_GROUP_URI, param_hash) end |
#edit_profile(hash) ⇒ Object
Edits profile information of the authenticated user. The fields “name” and “picture” are supported.
113 114 115 116 |
# File 'lib/friendfeed.rb', line 113 def edit_profile(hash) nickname or require_api_login call_api('user/%s/profile' % URI.encode(nickname), nil, hash) end |
#edit_service(id, serviceid, service, options = nil) ⇒ Object
Edits a service of the authenticated user, a group or an imaginary friend specified by a unique ID. [unofficial]
189 190 191 192 193 194 195 196 197 |
# File 'lib/friendfeed/unofficial.rb', line 189 def edit_service(id, serviceid, service, = nil) params = { 'stream' => id, 'service' => service, 'serviceid' => serviceid, } params.update() if post(ROOT_URI + '/a/configureservice', params) end |
#edit_twitter(id, serviceid, twitter_name) ⇒ Object
Edits a Twitter service of the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘isstatus’
> ‘on’ to display entries as messages (no link), and
‘importcomment’ => ‘on’ to include entry description as a comment. [unofficial]
276 277 278 |
# File 'lib/friendfeed/unofficial.rb', line 276 def edit_twitter(id, serviceid, twitter_name) edit_service(id, serviceid, 'twitter', 'username' => twitter_name) end |
#get_entries(entryids) ⇒ Object
Gets an array of entries of given entryids
. An exception is raised when it fails.
241 242 243 |
# File 'lib/friendfeed.rb', line 241 def get_entries(entryids) call_api('feed/entry', 'entry_id' => entryids)['entries'] end |
#get_entry(entryid) ⇒ Object
Gets an entry of a given entryid
. An exception is raised when it fails.
235 236 237 |
# File 'lib/friendfeed.rb', line 235 def get_entry(entryid) call_api('feed/entry/%s' % URI.encode(entryid))['entries'].first end |
#get_group(id) ⇒ Object
Gets profile information of a group specified by a unique ID. [unofficial]
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/friendfeed/unofficial.rb', line 141 def get_group(id) parser = post(ROOT_URI + '/a/profiledialog', 'stream' => id)['html_parser'] form = parser.xpath("//form[1]") hash = { 'stream' => id } form.xpath(".//input").each { |input| case input['type'].downcase when 'text' hash[input['name']] = input['value'] when 'radio', 'checkbox' if input['checked'] value = input['value'] if value && !value.empty? hash[input['name']] = value end end end } form.xpath(".//textarea").each { |input| hash[input['name']] = input.text } hash end |
#get_home_entries(options = nil) ⇒ Object
Gets an array of the entries the authenticated user would see on their home page.
164 165 166 167 |
# File 'lib/friendfeed.rb', line 164 def get_home_entries( = nil) require_api_login call_api('feed/home', )['entries'] end |
#get_imaginary_friend(id) ⇒ Object
Gets profile information of one of the authenticated user’s imaginary friends.
153 154 155 |
# File 'lib/friendfeed.rb', line 153 def get_imaginary_friend(id) get_profile(id) end |
#get_imaginary_friends ⇒ Object
Gets an array of profile information of the authenticated user’s imaginary friends.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/friendfeed.rb', line 140 def get_imaginary_friends nickname or require_api_login profiles = [] get_profile(@nickname)['subscriptions'].each { |subscription| if subscription['nickname'].nil? profiles << get_profile(subscription['id']) end } profiles end |
#get_list_entries(nickname, options = nil) ⇒ Object
Gets an array of the entries for the authenticated user’s list of a given nickname
171 172 173 174 |
# File 'lib/friendfeed.rb', line 171 def get_list_entries(nickname, = nil) require_api_login call_api('feed/list/%s' % URI.encode(nickname), )['entries'] end |
#get_list_profile(nickname) ⇒ Object
Gets profile information of the authenticated user’s list of a given nickname
in hash.
454 455 456 |
# File 'lib/friendfeed.rb', line 454 def get_list_profile(nickname) call_api('list/%s/profile' % URI.encode(nickname)) end |
#get_multi_user_entries(nicknames, options = nil) ⇒ Object
Gets an array of the most recent entries from users of given nicknames
.
185 186 187 188 189 |
# File 'lib/friendfeed.rb', line 185 def get_multi_user_entries(nicknames, = nil) = { 'nickname' => nicknames } .merge!() if call_api('feed/user', )['entries'] end |
#get_picture(nickname = @nickname, size = 'small') ⇒ Object
Gets a picture of a user of a given nickname
(defaulted to the authenticated user) in blob. Size can be ‘small’ (default), ‘medium’ or ‘large’,
435 436 437 438 |
# File 'lib/friendfeed.rb', line 435 def get_picture(nickname = @nickname, size = 'small') nickname or require_api_login call_api('/%s/picture' % URI.escape(nickname), { 'size' => size }, nil, true) end |
#get_profile(nickname = @nickname) ⇒ Object
Gets profile information of a user of a given nickname
, defaulted to the authenticated user, in hash.
106 107 108 109 |
# File 'lib/friendfeed.rb', line 106 def get_profile(nickname = @nickname) nickname or require_api_login call_api('user/%s/profile' % URI.encode(nickname)) end |
#get_profiles(nicknames) ⇒ Object
Gets an array of profile information of users of given nicknames
.
120 121 122 |
# File 'lib/friendfeed.rb', line 120 def get_profiles(nicknames) call_api('profiles', 'nickname' => nicknames)['profiles'] end |
#get_public_entries(options = nil) ⇒ Object
Gets an array of the most recent public entries.
158 159 160 |
# File 'lib/friendfeed.rb', line 158 def get_public_entries( = nil) call_api('feed/public', )['entries'] end |
#get_real_friends(nickname = @nickname) ⇒ Object
Gets an array of profile information of friends of a user of a given nickname
(defaulted to the authenticated user) is subscribing to.
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/friendfeed.rb', line 127 def get_real_friends(nickname = @nickname) nickname or require_api_login nicknames = [] get_profile(@nickname)['subscriptions'].each { |subscription| if nickname = subscription['nickname'] nicknames << nickname end } get_profiles(nicknames) end |
#get_room_entries(nickname, options = nil) ⇒ Object
Gets an array of the most recent entries in a room of a given nickname
.
223 224 225 |
# File 'lib/friendfeed.rb', line 223 def get_room_entries(nickname, = nil) call_api('feed/room/%s' % URI.encode(nickname), )['entries'] end |
#get_room_picture(nickname, size = 'small') ⇒ Object
Gets a picture of a room of a given nickname
in blob. Size can be ‘small’ (default), ‘medium’ or ‘large’,
442 443 444 |
# File 'lib/friendfeed.rb', line 442 def get_room_picture(nickname, size = 'small') call_api('/rooms/%s/picture' % URI.escape(nickname), { 'size' => size }, nil, true) end |
#get_room_profile(nickname) ⇒ Object
Gets profile information of a room of a given nickname
in hash.
448 449 450 |
# File 'lib/friendfeed.rb', line 448 def get_room_profile(nickname) call_api('room/%s/profile' % URI.encode(nickname)) end |
#get_rooms_entries(options = nil) ⇒ Object
Gets an array of the entries the authenticated user would see on their rooms page.
229 230 231 |
# File 'lib/friendfeed.rb', line 229 def get_rooms_entries( = nil) call_api('feed/rooms', )['entries'] end |
#get_services(nickname = @nickname) ⇒ Object
Gets a list of services of a user or a room of a given nickname
, defaulted to the authenticated user.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/friendfeed/unofficial.rb', line 92 def get_services(nickname = @nickname) agent = get_login_agent() services_uri = ROOT_URI + ("/%s/services" % URI.encode(nickname)) parser = agent.get(services_uri).parser active_servicelist = parser.xpath("//*[@class='active']//ul[@class='servicelist']") if !active_servicelist.empty? services = active_servicelist.xpath("./li/a").map { |a| { 'service' => a['class'].split.find { |a_class| a_class != 'l_editservice' && a_class != 'service' }, 'serviceid' => a['serviceid'].to_s, } } profile_uri = ROOT_URI + ("/%s" % URI.encode(nickname)) agent.get(profile_uri).parser.xpath("//div[@class='servicespreview']/a").each_with_index { |a, i| href = (profile_uri + a['href'].to_s).to_s break if profile_uri.route_to(href).relative? services[i]['profileUrl'] = href } else services = parser.xpath("//ul[@class='servicelist']/li/a").map { |a| { 'service' => a['class'].split.find { |a_class| a_class != 'service' }, 'profileUrl' => (services_uri + a['href'].to_s).to_s, } } end services end |
#get_user_commented_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries a user of a given nickname
(defaulted to the authenticated user) has commented on.
194 195 196 197 |
# File 'lib/friendfeed.rb', line 194 def get_user_commented_entries(nickname = @nickname, = nil) nickname or require_api_login call_api('feed/user/%s/comments' % URI.encode(nickname), )['entries'] end |
#get_user_discussed_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries a user of a given nickname
(defaulted to the authenticated user) has commented on or like’d.
209 210 211 212 |
# File 'lib/friendfeed.rb', line 209 def get_user_discussed_entries(nickname = @nickname, = nil) nickname or require_api_login call_api('feed/user/%s/discussion' % URI.encode(nickname), )['entries'] end |
#get_user_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries from a user of a given nickname
(defaulted to the authenticated user).
178 179 180 181 |
# File 'lib/friendfeed.rb', line 178 def get_user_entries(nickname = @nickname, = nil) nickname or require_api_login call_api('feed/user/%s' % URI.encode(nickname), )['entries'] end |
#get_user_friend_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries from friends of a user of a given nickname
(defaulted to the authenticated user).
216 217 218 219 |
# File 'lib/friendfeed.rb', line 216 def get_user_friend_entries(nickname = @nickname, = nil) nickname or require_api_login call_api('feed/user/%s/friends' % URI.encode(nickname), )['entries'] end |
#get_user_liked_entries(nickname = @nickname, options = nil) ⇒ Object
Gets an array of the most recent entries a user of a given nickname
(defaulted to the authenticated user) has like’d.
201 202 203 204 |
# File 'lib/friendfeed.rb', line 201 def get_user_liked_entries(nickname = @nickname, = nil) nickname or require_api_login call_api('feed/user/%s/likes' % URI.encode(nickname), )['entries'] end |
#hide_entry(entryid) ⇒ Object
Hides an existing entry of a given entryid
.
416 417 418 419 420 421 |
# File 'lib/friendfeed.rb', line 416 def hide_entry(entryid) require_api_login call_api('entry/hide', nil, { 'entry' => entryid, }) end |
#login(nickname, password) ⇒ Object
Performs a login with a nickname
and password
and returns self. This enables call of any API, including both official API and unofficial API.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/friendfeed/unofficial.rb', line 36 def login(nickname, password) @nickname = nickname @password = password @login_agent = Mechanize.new page = @login_agent.get(LOGIN_URI) login_form = page.forms.find { |form| LOGIN_URI + form.action == LOGIN_URI } or raise 'Cannot locate a login form' login_form.set_fields(:email => @nickname, :password => @password) page = login_form.submit login_form = page.forms.find { |form| LOGIN_URI + form.action == LOGIN_URI } and raise 'Login failed' page = @login_agent.get(ROOT_URI + "/account/api") remote_key = page.parser.xpath("(//table[@class='remotekey']//td[@class='value'])[2]/text()").to_s api_login(nickname, remote_key) end |
#post(uri, query = {}) ⇒ Object
Posts a request to an internal API of FriendFeed and returns either a parser object for an HTML response or an object parsed from a JSON response). [unofficial]
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/friendfeed/unofficial.rb', line 64 def post(uri, query = {}) agent = get_login_agent() page = agent.post(uri, { 'at' => agent..find { || .domain == 'friendfeed.com' && .name == 'AT' }.value }.update(query)) if page.respond_to?(:parser) parser = page.parser = parser.xpath("//div[@id='errormessage']/text()") .empty? or raise .map { || .to_s }.join(" ") parser else json = JSON.parse(page.body) = json['error'] and raise if html_frag = json['html'] html_body = '<html><body>' << html_frag << '</body></html>' json['html_parser'] = Mechanize.html_parser.parse(html_body) end json end end |
#refresh_service(id, serviceid, service, options = nil) ⇒ Object
Refreshes a feed of the authenticated user, a group or an imaginary friend specified by a unique ID. [unofficial]
214 215 216 217 218 219 220 221 |
# File 'lib/friendfeed/unofficial.rb', line 214 def refresh_service(id, serviceid, service, = nil) params = { 'stream' => id, 'serviceid' => serviceid, } params.update() if post(ROOT_URI + '/a/crawlservice', params) end |
#remove_blog(id, serviceid, url, options = nil) ⇒ Object
Removes a blog feed from the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘deleteentries’ => ‘on’ to delete entries also. [unofficial]
292 293 294 295 296 |
# File 'lib/friendfeed/unofficial.rb', line 292 def remove_blog(id, serviceid, url, = nil) params = { 'url' => url } params.update() if remove_service(id, serviceid, 'blog', = nil) end |
#remove_feed(id, serviceid, url, options = nil) ⇒ Object
Removes a feed from the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘deleteentries’ => ‘on’ to delete entries also. [unofficial]
283 284 285 286 287 |
# File 'lib/friendfeed/unofficial.rb', line 283 def remove_feed(id, serviceid, url, = nil) params = { 'url' => url } params.update() if remove_service(id, serviceid, 'feed', = nil) end |
#remove_service(id, serviceid, service, options = nil) ⇒ Object
Removes a service of the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘deleteentries’ => ‘on’ to delete entries also. [unofficial]
202 203 204 205 206 207 208 209 210 |
# File 'lib/friendfeed/unofficial.rb', line 202 def remove_service(id, serviceid, service, = nil) params = { 'stream' => id, 'service' => service, 'serviceid' => serviceid, } params.update() if post(ROOT_URI + '/a/removeservice', params) end |
#remove_twitter(id, serviceid, twitter_name, options = nil) ⇒ Object
Removes a Twitter service from the authenticated user, a group or an imaginary friend specified by a unique ID. Specify ‘deleteentries’ => ‘on’ to delete entries also. [unofficial]
301 302 303 304 305 |
# File 'lib/friendfeed/unofficial.rb', line 301 def remove_twitter(id, serviceid, twitter_name, = nil) params = { 'username' => twitter_name } params.update() if remove_service(id, serviceid, 'twitter', = nil) end |
#rename_imaginary_friend(id, nickname) ⇒ Object
Renames an imaginary friend specified by a unique ID to a given nickname
. [unofficial]
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/friendfeed/unofficial.rb', line 329 def rename_imaginary_friend(id, nickname) parser = post(ROOT_URI + '/a/profiledialog', 'stream' => id)['html_parser'] form = parser.xpath("//form[1]") hash = { 'stream' => id } form.xpath(".//input").each { |input| case input['type'].downcase when 'text' hash[input['name']] = input['value'] end } form.xpath(".//textarea").each { |input| hash[input['name']] = input.text } hash['name'] = nickname post(ROOT_URI + '/a/editprofile', hash) end |
#search(query, options = nil) ⇒ Object
Gets an array of entries that match a given query
.
246 247 248 249 250 |
# File 'lib/friendfeed.rb', line 246 def search(query, = nil) = { 'q' => query } .merge!() if call_api('feed/search', 'q' => )['entries'] end |
#search_for_domain(url, options = nil) ⇒ Object
Gets an array of entries that link to a given domain
.
260 261 262 263 264 |
# File 'lib/friendfeed.rb', line 260 def search_for_domain(url, = nil) = { 'url' => url } .merge!() if call_api('feed/domain', )['entries'] end |
#search_for_url(url, options = nil) ⇒ Object
Gets an array of entries that link to a given url
.
253 254 255 256 257 |
# File 'lib/friendfeed.rb', line 253 def search_for_url(url, = nil) = { 'url' => url } .merge!() if call_api('feed/url', )['entries'] end |
#subscribe_to_room(nickname) ⇒ Object
Subscribes to a room of a given nickname
and returns a status string.
472 473 474 |
# File 'lib/friendfeed.rb', line 472 def subscribe_to_room(nickname) call_subscription_api('room/%s/subscribe' % URI.encode(nickname))['status'] end |
#subscribe_to_user(nickname) ⇒ Object
Subscribes to a user of a given nickname
and returns a status string.
460 461 462 |
# File 'lib/friendfeed.rb', line 460 def subscribe_to_user(nickname) call_subscription_api('user/%s/subscribe' % URI.encode(nickname))['status'] end |
#undelete_comment(entryid, commentid) ⇒ Object
Undeletes a given comment that is already deleted.
373 374 375 376 377 378 379 380 |
# File 'lib/friendfeed.rb', line 373 def undelete_comment(entryid, commentid) require_api_login call_api('comment/delete', nil, { 'entry' => entryid, 'comment' => commentid, 'undelete' => 'on', }) end |
#undelete_entry(entryid) ⇒ Object
Undeletes a given entry that is already deleted.
407 408 409 410 411 412 413 |
# File 'lib/friendfeed.rb', line 407 def undelete_entry(entryid) require_api_login call_api('entry/delete', nil, { 'entry' => entryid, 'undelete' => 'on', }) end |
#unhide_entry(entryid) ⇒ Object
Unhides a given entry that is already hidden.
424 425 426 427 428 429 430 |
# File 'lib/friendfeed.rb', line 424 def unhide_entry(entryid) require_api_login call_api('entry/hide', nil, { 'entry' => entryid, 'unhide' => 'on', }) end |
#unsubscribe_from(id) ⇒ Object
Unsubscribe from a friend, a group or an imaginary friend specified by a unique ID. [unofficial]
316 317 318 |
# File 'lib/friendfeed/unofficial.rb', line 316 def unsubscribe_from(id) post(ROOT_URI + '/a/unsubscribe', 'stream' => id) end |
#unsubscribe_from_room(nickname) ⇒ Object
Unsubscribes from a room of a given nickname
and returns a status string.
478 479 480 |
# File 'lib/friendfeed.rb', line 478 def unsubscribe_from_room(nickname) call_subscription_api('room/%s/subscribe?unsubscribe=1' % URI.encode(nickname))['status'] end |
#unsubscribe_from_user(nickname) ⇒ Object
Unsubscribes from a user of a given nickname
and returns a status string.
466 467 468 |
# File 'lib/friendfeed.rb', line 466 def unsubscribe_from_user(nickname) call_subscription_api('user/%s/subscribe?unsubscribe=1' % URI.encode(nickname))['status'] end |