Skip to content

Commit

Permalink
Add some more API functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
knu committed Feb 26, 2010
1 parent 3f2ac96 commit a74d21f
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions lib/friendfeed/v2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ def validate(options = nil)
Object::Feed.create call_api(compose_uri('validate', options)), self
end

# Gets a feed identified by a given +id+.
# Gets a feed identified by a given +id+. The +id+ can be an
# array such as [username, :friends] or [:list, list_id,
# :summary, n], which elements are joined with slash.
def get_feed(id, options = nil)
Object::Feed.create call_api(compose_uri('feed/%s' % id, options)), self
Object::Feed.create call_api(compose_uri('feed/%s' % join(id, '/'), options)), self
end

# Gets an entry identified by a given +id+.
def get_entry(id, options = nil)
Object::Entry.create call_api(compose_uri('entry/%s' % id, options)), self
Object::Entry.create call_api(compose_uri('entry/%s' % join(id, '/'), options)), self
end

# Gets an entry that an ff.im +short_id+ points to.
Expand All @@ -98,8 +100,28 @@ def encode_short(entry_id, options = nil)
Object::Entry.create call_api('short', merge_hashes({ :entry => entry_id }, options)), self
end

# Gets the feed lists in the side bar of the authenticated user.
def get_feedlist(id, options = nil)
Object::FeedList.create call_api('feedlist'), self
end

# Gets the information about a feed specified by a given +id+.
def get_feedinfo(id, options = nil)
Object::Feed.create call_api('feedinfo/%s' % id), self
end

private

# If an array-like is given, join with delimiter. Convert to
# string otherwise.
def join(object, delimiter = ',')
if array = Array.try_convert(object)
array.join(delimiter)
else
object.to_s
end
end

def merge_hashes(*hashes)
hashes.inject({}) { |i, j|
i.update(j) if j
Expand All @@ -112,11 +134,7 @@ def compose_uri(path, parameters = nil)
if parameters
uri.query = parameters.map { |key, value|
key = key.to_s
if array = Array.try_convert(value)
value = array.join(',')
else
value = value.to_s
end
value = join(value)
URI.encode(key) + "=" + URI.encode(value)
}.join('&')
end
Expand Down

0 comments on commit a74d21f

Please sign in to comment.