Module: Flattr::Client::Things

Included in:
Flattr::Client
Defined in:
lib/flattr/client/things.rb

Instance Method Summary collapse

Instance Method Details

#thing(id) ⇒ Object

Public: Fetch a thing

id - id of the thing you would like to fetch

Examples

f = Flattr.new
f.thing(450287)
#=> Flattr::Thing

Returns the thing Raises Flattr::Error::NotFound on error



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

Public: Delete a thing

id - id of the thing you want to delete

Example

f = Flattr.new
f.thing_delete(1)
# => true

Returns true if successful Raises Flattr::Error::NotFound if thing was not found



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

Public: Get flattrs on a thing

id - id of thing

Examples

f = Flattr.new
f.thing_flattrs(450287)
# => [...]

Returns a Array with flattrs



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

Public: Check if a URL is registred as a thing

url - URL to lookup

Examples

f = Flattr.new
f.things_lookup("http://flattr.com")
# => nil

f = Flattr.new
f.things_lookup("http://github.com/simon/flattr")
# => Flattr::Thing

Returns Flattr::Thing on success and nil on failure



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

#things(*ids) ⇒ Object

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



35
36
37
# File 'lib/flattr/client/things.rb', line 35

def things(*ids)
  get("/rest/v2/things/#{ids.join(",")}?full").collect { |t| Flattr::Thing.new(t) }
end