Class: Disqussion::Threads

Inherits:
Client
  • Object
show all
Defined in:
lib/disqussion/client/threads.rb

Instance Method Summary collapse

Methods included from Request

#get, #post

Instance Method Details

#close(*args) ⇒ Hashie::Rash

Closes a thread @accessibility: public key, secret key @methods: POST @format: json, jsonp @authenticated: true @limited: false @see: http://disqus.com/api/3.0/threads/close.json

Examples:

Closes thread 12345678

Disqussion::Client.threads.close(12345678)

Parameters:

  • thread (Array, Integer)

    allows multiple. Looks up a thread by ID. You must be a moderator on the selected thread's forum. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    ID of the closed thread.



45
46
47
48
49
50
# File 'lib/disqussion/client/threads.rb', line 45

def close(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = post('threads/close', options)
end

#create(*args) ⇒ Hashie::Rash

@accessibility: public key, secret key @methods: POST @format: json, jsonp @authenticated: true @limited: false @see: http://disqus.com/api/3.0/threads/create.json

Examples:

Create thread "Hello World"

Disqussion::Client.threads.create("bobross","Hello World")

Parameters:

  • forum (String)

    Looks up a forum by ID (aka forum shortname).

  • title (String)

    Title of the the new thread

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    New thread is created.



22
23
24
25
26
27
28
29
30
31
# File 'lib/disqussion/client/threads.rb', line 22

def create(*args)
	options = args.last.is_a?(Hash) ? args.pop : {}
	if args.length == 2 
		options.merge!(:forum => args[0])
		options.merge!(:title => args[1])
	 	response = post('threads/create', options)
  else
    puts "#{Kernel.caller.first}: threads.create expects 2 arguments: forum name (aka forum short name) and title for the thread"
  end
end

#details(*args) ⇒ Hashie::Rash

Returns thread details. @accessibility: public key, secret key @methods: GET @format: json, jsonp @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/details.json

Examples:

Return extended information for forum 'myforum'

Disqussion::Client.threads.details("mythread")

Parameters:

  • thread (Integer)

    Looks up a thread by ID. You must be a moderator on the selected thread's forum. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    A customizable set of options.

Returns:

  • (Hashie::Rash)

    Details on the requested threads.



66
67
68
69
70
71
# File 'lib/disqussion/client/threads.rb', line 66

def details(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = get('threads/details', options)
end

#list(*args) ⇒ Hashie::Rash

Returns a list of threads sorted by the date created. @accessibility: public key, secret key @methods: GET @format: json, jsonp, rss @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/list.json

Examples:

Return extended information for forum 'myforum'

Disqussion::Client.threads.list(:forum => "the88")

Parameters:

  • options (Hash)

    A customizable set of options.

Returns:

  • (Hashie::Rash)

    List of threads.



94
95
96
97
# File 'lib/disqussion/client/threads.rb', line 94

def list(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = get('threads/list', options)
end

#listHot(*args) ⇒ Hashie::Rash

BETA Returns a list of threads sorted by hotness (date and likes). @accessibility: public key, secret key @methods: GET @format: json, jsonp, rss @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/listHot.json

Examples:

Return list of hottest threads of the forum specified

Disqussion::Client.threadslistHot(:forum => "cnn")

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    List of the hottest threads sorted by hotness.



138
139
140
141
# File 'lib/disqussion/client/threads.rb', line 138

def listHot(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = get('threads/listHot', options)
end

#listMostLiked(*args) ⇒ Hashie::Rash

Returns a list of threads sorted by number of likes. @accessibility: public key, secret key @methods: GET @format: json, jsonp, rss @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/listMostLiked.json

Examples:

Return extended information for forum 'myforum'

Disqussion::Client.threads.listMostLiked()

Parameters:

  • options (Hash)

    A customizable set of options.

Returns:

  • (Hashie::Rash)

    List of the most liked threads.



116
117
118
119
# File 'lib/disqussion/client/threads.rb', line 116

def listMostLiked(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = get('threads/listMostLiked', options)
end

#listPopular(*args) ⇒ Hashie::Rash

Returns a list of threads sorted by number of posts made since "interval". If you are using both "category" and "forum" parameters, the forum of the category must match that as the parameter value for "forum". @accessibility: public key, secret key @methods: GET @format: json, jsonp, rss @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/listPopular.json

Examples:

Return list of the most populat threads in a given interval

Disqussion::Client.threadslistPopular(:forum => "bobross")

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    List of the most popular threads which have had the most posts in an interval.



160
161
162
163
# File 'lib/disqussion/client/threads.rb', line 160

def listPopular(*args)
	options = args.last.is_a?(Hash) ? args.pop : {}
	response = get('threads/listPopular', options)
end

#listPosts(*args) ⇒ Hashie::Rash

Returns a list of posts within a thread. @accessibility: public key, secret key @methods: GET @format: json, jsonp, rss @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/listPosts.json

Examples:

Return extended information for forum 'myforum'

Disqussion::Client.threads.list()

Parameters:

  • thread (Integer)

    Looks up a thread by ID. You must be a moderator on the selected thread's forum. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    A customizable set of options.

Returns:

  • (Hashie::Rash)

    List of threads post.



185
186
187
188
189
190
# File 'lib/disqussion/client/threads.rb', line 185

def listPosts(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = get('threads/listPosts', options)
end

#open(*args) ⇒ Hashie::Rash

Opens a thread @accessibility: public key, secret key @methods: POST @format: json, jsonp @authenticated: true @limited: false @see: http://disqus.com/api/3.0/threads/open.json

Examples:

Opens thread 12345678

Disqussion::Client.threads.open(12345678)

Parameters:

  • thread (Array, Integer)

    allows multiple. Looks up a thread by ID. You must be a moderator on the selected thread's forum. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    ID of the opened thread.



204
205
206
207
208
209
# File 'lib/disqussion/client/threads.rb', line 204

def open(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = post('threads/open', options)
end

#remove(*args) ⇒ Hashie::Rash

Removes a thread @accessibility: public key, secret key @methods: POST @format: json, jsonp @authenticated: true @limited: false @see: http://disqus.com/api/3.0/threads/remove.json

Examples:

Removes thread 12345678

Disqussion::Client.threads.remove(12345678)

Parameters:

  • thread (Array, Integer)

    allows multiple. Looks up a thread by ID. You must be a moderator on the selected thread's forum. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    ID of the deleted thread.



223
224
225
226
227
228
# File 'lib/disqussion/client/threads.rb', line 223

def remove(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = post('threads/remove', options)
end

#restore(*args) ⇒ Hashie::Rash

Restores a thread @accessibility: public key, secret key @methods: POST @format: json, jsonp @authenticated: true @limited: false @see: http://disqus.com/api/3.0/threads/restore.json

Examples:

Removes thread 12345678

Disqussion::Client.threads.restore(12345678)

Parameters:

  • thread (Array, Integer)

    allows multiple. Looks up a thread by ID. You must be a moderator on the selected thread's forum. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    ID of the restored thread.



242
243
244
245
246
247
# File 'lib/disqussion/client/threads.rb', line 242

def restore(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = post('threads/restore', options)
end

#set(*args) ⇒ Object

Returns an unsorted set of threads given a list of ids. @accessibility: public key, secret key @methods: GET @format: json, jsonp @authenticated: false @limited: false @see: http://disqus.com/api/3.0/threads/set.json

Examples:

Set thread 12345678

Disqussion::Client.threads.set(12345678)

Parameters:

  • options (Hash)

    a customizable set of options



260
261
262
263
264
265
# File 'lib/disqussion/client/threads.rb', line 260

def set(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  thread = args.first
  options.merge!(:thread => thread) if ([:ident, :link] & options.keys).empty?
  response = get('threads/set', options)
end

#subscribe(*args) ⇒ Object



267
268
269
270
# File 'lib/disqussion/client/threads.rb', line 267

def subscribe(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = post('threads/subscribe', options)
end

#unsubscribe(*args) ⇒ Object



272
273
274
275
# File 'lib/disqussion/client/threads.rb', line 272

def unsubscribe(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = post('threads/unsubscribe', options)
end

#vote(*args) ⇒ Hashie::Rash

Register a vote on a thread. @accessibility: public key, secret key @methods: POST @format: json, jsonp @authenticated: true @limited: false @see: http://disqus.com/api/3.0/threads/vote.json

Examples:

Removes thread 12345678

Disqussion::Client.threads.vote(1, 12345678)

Parameters:

  • thread (Integer)

    Choices: -1, 0, 1

  • thread (Integer)

    Looks up a thread by ID. You may pass use the 'ident' or 'link' query types instead of an ID by including 'forum'.

  • options (Hash)

    a customizable set of options

Returns:

  • (Hashie::Rash)

    Details on the thread.



314
315
316
317
318
319
320
321
322
323
# File 'lib/disqussion/client/threads.rb', line 314

def vote(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  if args.length == 2
    options.merge!(:vote => args[0])
    options.merge!(:thread => args[1]) if ([:ident, :link] & options.keys).empty?
    response = post('threads/vote', options)
  else
    puts "#{Kernel.caller.first}: threads.vote expects 2 arguments: vote([-1..1]), thread (you may pass use the 'ident' or 'link' query types instead of an thread ID by including :forum)"
  end
end