lib/flattr/client/things.rb in flattr-0.2.3 vs lib/flattr/client/things.rb in flattr-0.3.0
- old
+ new
@@ -13,16 +13,31 @@
# f = Flattr.new
# f.thing(450287)
# #=> Flattr::Thing
#
# Returns the thing
- # Raises error on failure
+ # Raises Flattr::Error::NotFound on error
def thing(id)
- thing = get("/rest/v2/things/#{id}")
+ thing = get("/rest/v2/things/#{id}?full")
Flattr::Thing.new(thing)
end
+ # Public: Fetch several things
+ #
+ # ids - a list of thing ids
+ #
+ # Examples
+ #
+ # f = Flattr.new
+ # f.things(450287,543896)
+ # #=> [Flattr::Thing, Flattr::Thing]
+ #
+ # Returns a Array with things
+ def things(*ids)
+ get("/rest/v2/things/#{ids.join(",")}?full").collect { |t| Flattr::Thing.new(t) }
+ end
+
# Public: Create a thing
#
# url - URL you want to submit
# opts - A Hash containing the thing attribtues (default: {})
# :title - title of the thing (optional).
@@ -31,14 +46,15 @@
# :language - language of the thing (optional).
# :tags - tags of the thing (optional).
# :hidden - boolean toggling if thing should be hidden or not (optional).
#
# Returns new thing
- # Raises error on failure
+ # Raises Flattr::Error::BadRequest on validation error
+ # Raises Flattr::Error::NotFound if thing was not found
def thing_new(url, opts = {})
response = post("/rest/v2/things", opts.merge(:url => url))
- thing = get("/rest/v2/things/#{response[:id]}")
+ thing = thing(response["id"])
Flattr::Thing.new(thing)
end
# Public: Update a thing
#
@@ -50,11 +66,12 @@
# :language - language of the thing (optional).
# :tags - tags of the thing (optional).
# :hidden - boolean toggling if thing should be hidden or not (optional).
#
# Returns updated thing
- # Raises Error on failure
+ # Raises Flattr::Error::BadRequest on validation error
+ # Raises Flattr::Error::NotFound if thing was not found
def thing_update(id, opts = {})
patch("/rest/v2/things/#{id}", opts)
thing = get("/rest/v2/things/#{id}")
Flattr::Thing.new(thing)
end
@@ -68,35 +85,20 @@
# f = Flattr.new
# f.thing_delete(1)
# # => true
#
# Returns true if successful
- # Raises Error on failure
+ # Raises Flattr::Error::NotFound if thing was not found
def thing_delete(id)
thing = delete("/rest/v2/things/#{id}")
if thing.nil? || thing == ""
return true
else
return false
end
end
- # Public: Flattr a thing
- #
- # id - id of the thing you want to flattr
- #
- # Example
- #
- # f = Flattr.new
- # f.thing_flattr(1)
- # # => true
- #
- # Returns true
- def thing_flattr(id)
- post("/rest/v2/things/#{id}/flattr")
- end
-
# Public: Search things
#
# params - The Hash options used to configure search (default: {})
# :query - A free text search query (optional).
# :language - Filter by language (optional).
@@ -116,10 +118,11 @@
# f = Flattr.new
# f.things_search(:query => "ruby", :user => 'smgt')
#
# Returns Flattr::Search
def thing_search(params = {})
+ params.merge!({"full" => "full"})
result = get("/rest/v2/things/search", params)
Flattr::Search.new(result)
end
# Public: Check if a URL is registred as a thing
@@ -143,9 +146,24 @@
thing = get(lookup['location'])
Flattr::Thing.new(thing)
else
nil
end
+ end
+
+ # Public: Get flattrs on a thing
+ #
+ # id - id of thing
+ #
+ # Examples
+ #
+ # f = Flattr.new
+ # f.thing_flattrs(450287)
+ # # => [...]
+ #
+ # Returns a Array with flattrs
+ def thing_flattrs(id,params={})
+ get("/rest/v2/things/#{id}/flattrs",params)
end
end
end
end