Module: Flattr::Client::Things
- Included in:
- Flattr::Client
- Defined in:
- lib/flattr/client/things.rb
Instance Method Summary collapse
-
#thing(id) ⇒ Object
Public: Fetch a thing.
-
#thing_delete(id) ⇒ Object
Public: Delete a thing.
-
#thing_flattrs(id, params = {}) ⇒ Object
Public: Get flattrs on a thing.
-
#thing_lookup(url) ⇒ Object
Public: Check if a URL is registred as a thing.
-
#thing_new(url, opts = {}) ⇒ Object
Public: Create a thing.
-
#thing_search(params = {}) ⇒ Object
Public: Search things.
-
#thing_update(id, opts = {}) ⇒ Object
Public: Update a thing.
-
#things(*ids) ⇒ Object
Public: Fetch several things.
Instance Method Details
#thing(id) ⇒ Object
19 20 21 22 |
# File 'lib/flattr/client/things.rb', line 19 def thing(id) thing = get("/rest/v2/things/#{id}?full") Flattr::Thing.new(thing) end |
#thing_delete(id) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/flattr/client/things.rb', line 90 def thing_delete(id) thing = delete("/rest/v2/things/#{id}") if thing.nil? || thing == "" return true else return false end end |
#thing_flattrs(id, params = {}) ⇒ Object
163 164 165 |
# File 'lib/flattr/client/things.rb', line 163 def thing_flattrs(id,params={}) get("/rest/v2/things/#{id}/flattrs",params) end |
#thing_lookup(url) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/flattr/client/things.rb', line 142 def thing_lookup(url) lookup = get("/rest/v2/things/lookup", {:url => url}) if lookup["location"] thing = get(lookup['location']) Flattr::Thing.new(thing) else nil end end |
#thing_new(url, opts = {}) ⇒ Object
Public: Create a thing
url - URL you want to submit opts - A Hash containing the thing attribtues (default: {})
:title - title of the thing (optional).
:description - description of the thing (optional).
:category - category of the thing (optional).
: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 Flattr::Error::BadRequest on validation error Raises Flattr::Error::NotFound if thing was not found
53 54 55 56 |
# File 'lib/flattr/client/things.rb', line 53 def thing_new(url, opts = {}) response = post("/rest/v2/things", opts.merge(:url => url)) thing(response["id"]) end |
#thing_search(params = {}) ⇒ Object
Public: Search things
params - The Hash options used to configure search (default: {})
:query - A free text search query (optional).
:language - Filter by language (optional).
:category - Filter by category (optional).
:user - Search only a users things (optional).
:tags - Filter by tags (optional).
:page - Show page (optional).
:count - How many items per page (optional).
Examples
# Return a search result containgin 'smgt'
f = Flattr.new
f.things_search(:query => "smgt")
# Return a search result containing 'ruby' from user 'smgt'
f = Flattr.new
f.things_search(:query => "ruby", :user => 'smgt')
Returns Flattr::Search
121 122 123 124 125 |
# File 'lib/flattr/client/things.rb', line 121 def thing_search(params = {}) params.merge!({"full" => "full"}) result = get("/rest/v2/things/search", params) Flattr::Search.new(result) end |
#thing_update(id, opts = {}) ⇒ Object
Public: Update a thing
id - id of the thing to update opts - a Hash containing the attributes to update (default: {})
:title - title of the thing (optional).
:description - description of the thing (optional).
:category - category of the thing (optional).
: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 Flattr::Error::BadRequest on validation error Raises Flattr::Error::NotFound if thing was not found
72 73 74 75 76 |
# File 'lib/flattr/client/things.rb', line 72 def thing_update(id, opts = {}) patch("/rest/v2/things/#{id}", opts) thing = get("/rest/v2/things/#{id}") Flattr::Thing.new(thing) end |