Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from shabankarumba/master
Browse files Browse the repository at this point in the history
Allowing api requests for users followers, following, most active forums
  • Loading branch information
jeremyvdw committed Jan 28, 2013
2 parents e93fdca + 3d9ccf0 commit 4b3629a
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 9 deletions.
22 changes: 22 additions & 0 deletions lib/disqussion/client/threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ def listMostLiked(*args)
response = get('threads/listMostLiked', options)
end

# 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
# @return [Hashie::Rash] List of the hottest threads sorted by hotness.
# @option options [Integer] :category. Looks up a category by ID. Defualts to null.
# @option options [String] :forum. Defaults to null. Looks up a forum by ID (aka short name)
# @option options [String, Integer] :author. Defaults to null. Looks up a user by ID. You may look up a user by username using the 'username' query type.
# @option options [String, Array] :related. allows multiple. Defaults to []. You may specify relations to include with your response. Choices: forum, author,category
# @option options [Integer] :limit. Defaults to 25. Maximum length of 100
# @option options [String, Array] :include .allows multiple. Defaults to ["open", "close"]. Choices: open, closed, killed.
# @example Return list of hottest threads of the forum specified
# Disqussion::Client.threadslistHot(:forum => "cnn")
# @see: http://disqus.com/api/3.0/threads/listHot.json
def listHot(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
response = get('threads/listHot', options)
end

# Returns a list of posts within a thread.
# @accessibility: public key, secret key
# @methods: GET
Expand Down
50 changes: 46 additions & 4 deletions lib/disqussion/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def listActiveThreads(*args)

# BETA
# Returns a list of various activity types made by the user.
# @accessibility: public key, secret key
# @accessibility: public key, secret key
# @methods: GET
# @format: json, jsonp
# @authenticated: false
Expand All @@ -111,14 +111,44 @@ def listActivity(*args)

# BETA
# Returns a list of users a user is being followed by.
# @accessibility: public key, secret key
# @methods: GET
# @format: json, jsonp
# @authenticated: false
# @limited: true
# @return [Hashie::Rash] Details on the users the user is being followed by.
# @option options [Datetime, Timestamp] :since. Unix timestamp (or ISO datetime standard). Defaults to null
# @option options [Integer] :cursor. Defaults to null
# @option options [Integer] :limit. Defaults to 25. Maximum length of 100
# @option options [Integer] :user. Defaults to null. Looks up a user by ID. You may look up a user by username using the 'username' query type.
# @option options [String] :order. Defaults to "asc". Choices: asc, desc
# @example Return a list of users the user is currently being followed by
# Disqussion::Client.users.listFollowers(:user => 1234)
# @see: http://disqus.com/api/3.0/users/listFollowers.json
def listFollowers(*args)

options = args.last.is_a?(Hash) ? args.pop : {}
response = get('users/listFollowers', options)
end

# BETA
# Returns a list of users a user is following.
# @accessibility: public key, secret key
# @methods: GET
# @format: json, jsonp
# @authenticated: false
# @limited: true
# @return [Hashie::Rash] Details on the users the user is following.
# @option options [Datetime, Timestamp] :since. Unix timestamp (or ISO datetime standard). Defaults to null
# @option options [Integer] :cursor. Defaults to null
# @option options [Integer] :limit. Defaults to 25. Maximum length of 100
# @option options [Integer] :user. Defaults to null. Looks up a user by ID. You may look up a user by username using the 'username' query type.
# @option options [String] :order. Defaults to "asc". Choices: asc, desc
# @example Return a list of users the user is currently following
# Disqussion::Client.users.listFollowing(:user => 1234)
# @see: http://disqus.com/api/3.0/users/listFollowing.json
def listFollowing(*args)

options = args.last.is_a?(Hash) ? args.pop : {}
response = get('users/listFollowing', options)
end

# Returns a list of forums a user owns.
Expand All @@ -144,8 +174,20 @@ def listForums(*args)

# BETA
# Returns a list of forums a user has been active on recenty, sorted by the user's activity.
# @accessibility: public key, secret key
# @methods: GET
# @format: json, jsonp
# @authenticated: false
# @limited: true
# @return [Hashie::Rash] Details on the users list of forums they have been most active on recently.
# @option options [Integer] :limit. Defaults to 25. Maximum length of 100
# @option options [Integer] :user. Defaults to null. Looks up a user by ID. You may look up a user by username using the 'username' query type.
# @example Return a list of the forums the user has been most active on recently.
# Disqussion::Client.users.listMostActiveForums(:user => 1234)
# @see: http://disqus.com/api/3.0/users/listMostActiveForums.json
def listMostActiveForums(*args)

options = args.last.is_a?(Hash) ? args.pop : {}
response = get('users/listMostActiveForums', options)
end

# Returns a list of posts made by the user.
Expand Down
11 changes: 10 additions & 1 deletion spec/disqussion/client/threads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@
end

describe ".listHot" do
pending
before do
stub_get("threads/listHot.json", :query => { :forum => "cnn" }).
to_return(:body => fixture("threads/listHot.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end

it "returns a list of hot threads of a forum" do
@client.listHot(:forum => "cnn")
a_get("threads/listHot.json", :query => { :forum => "cnn" }).
should have_been_made
end
end

describe ".listMostLiked" do
Expand Down
29 changes: 25 additions & 4 deletions spec/disqussion/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,29 @@
end

describe ".listFollowers" do
pending
it "gets a list of users followers." do
stub_get("users/listFollowers.json", :query => { :user => "1234"}).
to_return(:body => fixture("users/listFollowers.json"), :headers => {:content_type => "application/json; charset=utf-8"})

@client.listFollowers(:user => 1234)

a_get("users/listFollowers.json", :query => { :user => "1234"}).should have_been_made
end
end

describe ".listFollowing" do
pending
it "gets a list of users the user is following on Disqus." do
stub_get("users/listFollowing.json", :query => { :user => "1"}).
to_return(:body => fixture("users/listFollowing.json"), :headers => {:content_type => "application/json; charset=utf-8"})

@client.listFollowing(:user => 1)

a_get("users/listFollowing.json", :query => { :user => "1"}).should have_been_made
end
end

describe ".listForums" do
it "get list of users forums." do
it "gets list of users forums." do
stub_get("users/listForums.json", :query => { :user => "1234" }).
to_return(:body => fixture("users/listForums.json"), :headers => {:content_type => "application/json; charset=utf-8"})

Expand All @@ -82,7 +96,14 @@
end

describe "listMostActiveForums" do
pending
it "gets list of forums the user is most active on" do
stub_get("users/listMostActiveForums.json", :query => { :user => "1" }).
to_return(:body => fixture("users/listMostActiveForums.json"), :headers => {:content_type => "application/json; charset=utf-8"})

@client.listMostActiveForums(:user => 1)

a_get("users/listMostActiveForums.json", :query => { :user => "1"}).should have_been_made
end
end

describe ".listPosts" do
Expand Down
28 changes: 28 additions & 0 deletions spec/fixtures/threads/listHot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"code": 0,
"response": [
{
"feed": "http://cnn.disqus.com/sarah_palins_fall_from_media_stardom/latest.rss",
"reactions": 0,
"identifiers": [
"/2013/01/28/opinion/kurtz-palin-commentator/index.html"
],
"forum": "cnn",
"title": "Sarah Palin's fall from media stardom",
"dislikes": 0,
"isDeleted": false,
"author": "335648",
"userScore": 0,
"id": "1051008353",
"isClosed": false,
"posts": 2262,
"userSubscription": false,
"link": "http://www.cnn.com/2013/01/28/opinion/kurtz-palin-commentator/index.html",
"likes": 8,
"message": "",
"category": "198834",
"slug": "sarah_palins_fall_from_media_stardom",
"createdAt": "2013-01-28T11:19:39"
}
]
}
42 changes: 42 additions & 0 deletions spec/fixtures/users/listFollowers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"cursor": {
"prev": null,
"hasNext": false,
"next": "219244:1:0",
"hasPrev": false,
"total": null,
"id": "219244:1:0",
"more": false
},
"code": 0,
"response": [
{
"username": "terrybain",
"about": "Author of You Are a Dog and We Are the Cat.",
"name": "Terry Bain",
"url": "http://flavors.me/terrybain",
"isAnonymous": false,
"rep": 1.286317,
"profileUrl": "http://disqus.com/terrybain/",
"emailHash": "2c8f6b13613a93350ce3e2c01260eeff",
"reputation": 1.286317,
"location": "Spokane",
"isPrimary": true,
"joinedAt": "2007-10-31T17:37:00",
"id": "962",
"avatar": {
"small": {
"permalink": "http://disqus.com/api/users/avatars/terrybain.jpg",
"cache": "http://mediacdn.disqus.com/uploads/users/962/avatar32.jpg?1281549414"
},
"isCustom": false,
"permalink": "http://disqus.com/api/users/avatars/terrybain.jpg",
"cache": "http://mediacdn.disqus.com/uploads/users/962/avatar92.jpg?1281549414",
"large": {
"permalink": "http://disqus.com/api/users/avatars/terrybain.jpg",
"cache": "http://mediacdn.disqus.com/uploads/users/962/avatar92.jpg?1281549414"
}
}
}
]
}
42 changes: 42 additions & 0 deletions spec/fixtures/users/listFollowing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"cursor": {
"prev": null,
"hasNext": false,
"next": "0:0:0",
"hasPrev": false,
"total": null,
"id": "0:0:0",
"more": false
},
"code": 0,
"response": [
{
"username": "paulgraham",
"about": "",
"name": "paulgraham",
"url": "",
"isAnonymous": false,
"rep": 1.329051,
"profileUrl": "http://disqus.com/paulgraham/",
"emailHash": "d41d8cd98f00b204e9800998ecf8427e",
"reputation": 1.329051,
"location": "",
"isPrimary": true,
"joinedAt": "2007-07-31T18:09:39",
"id": "2",
"avatar": {
"small": {
"permalink": "http://disqus.com/api/users/avatars/paulgraham.jpg",
"cache": "http://mediacdn.disqus.com/1359151009/images/noavatar32.png"
},
"isCustom": false,
"permalink": "http://disqus.com/api/users/avatars/paulgraham.jpg",
"cache": "http://mediacdn.disqus.com/1359151009/images/noavatar92.png",
"large": {
"permalink": "http://disqus.com/api/users/avatars/paulgraham.jpg",
"cache": "http://mediacdn.disqus.com/1359151009/images/noavatar92.png"
}
}
}
]
}
24 changes: 24 additions & 0 deletions spec/fixtures/users/listMostActiveForums.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"code": 0,
"response": [
{
"name": "The Disqus Blog",
"language": "en",
"settings": {
"allowAnonPost": true,
"audienceSyncEnabled": false,
"allowMedia": true,
"hasReactions": true,
"ssoRequired": false,
"backplaneEnabled": false
},
"url": "http://blog.disqus.com/",
"favicon": {
"permalink": "http://disqus.com/api/forums/favicons/disqus.jpg",
"cache": "http://mediacdn.disqus.com/uploads/forums/11/favicon.png"
},
"founder": "3",
"id": "disqus"
}
]
}

0 comments on commit 4b3629a

Please sign in to comment.