Permalink
Browse files

Adds finding and searching users

  • Loading branch information...
1 parent 9a1e58d commit 5a0cfb4777d2062d63b7d710adc2b68b8785c4f7 @vesan committed Mar 24, 2013
View
@@ -2,6 +2,7 @@
require "kippt/account"
require "kippt/clips"
require "kippt/lists"
+require "kippt/users"
class Kippt::Client
include Kippt::Connection
@@ -30,4 +31,8 @@ def lists
def clips
Kippt::Clips.new(self)
end
+
+ def users
+ Kippt::Users.new(self)
+ end
end
View
@@ -0,0 +1,11 @@
+require "ostruct"
+
+class Kippt::User
+ include Kippt::Resource
+
+ attributes :username, :bio, :app_url, :avatar_url, :twitter,
+ :id, :github, :website_url, :full_name, :dribble,
+ :counts, :resource_uri
+
+ boolean_attributes :is_pro
+end
@@ -0,0 +1,10 @@
+require "kippt/collection"
+require "kippt/user"
+
+class Kippt::UserCollection
+ include Kippt::Collection
+
+ def object_class
+ Kippt::User
+ end
+end
View
@@ -0,0 +1,51 @@
+require "kippt/connection"
+require "kippt/collection_resource"
+require "kippt/user_collection"
+require "kippt/user"
+
+class Kippt::Users
+ include Kippt::CollectionResource
+ VALID_SEARCH_PARAMETERS = [:q]
+
+ def initialize(client)
+ @client = client
+ end
+
+ def self.valid_filter_parameters
+ [:limit, :offset]
+ end
+
+ def object_class
+ Kippt::User
+ end
+
+ def collection_class
+ Kippt::UserCollection
+ end
+
+ def base_uri
+ "users"
+ end
+
+ def search(parameters)
+ if parameters.is_a?(String)
+ Kippt::UserCollection.new(
+ @client.get("#{base_uri}/search", {:q => parameters}).body,
+ self)
+ else
+ validate_search_parameters(parameters)
+
+ Kippt::UserCollection.new(
+ @client.get("#{base_uri}/search", parameters).body,
+ self)
+ end
+ end
+
+ private
+
+ def validate_search_parameters(parameters)
+ parameters.each do |key, value|
+ raise ArgumentError.new("'#{key}' is not a valid search parameter") unless VALID_SEARCH_PARAMETERS.include?(key)
+ end
+ end
+end
@@ -0,0 +1 @@
+{"username": "vesan", "bio": "Ruby developer at Kisko Labs. Dangerous, but not foolish.", "app_url": "/vesan", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/3b2958fd-db1d-4b80-acd1-d7e344fe5124/160x160", "twitter": "vesan", "id": 10, "github": "vesan", "website_url": "http://vesavanska.com/", "full_name": "Vesa V\u00e4nsk\u00e4", "dribbble": "vesan", "counts": {"follows": 21, "followed_by": 26}, "is_pro": true, "resource_uri": "/api/users/10/"}
@@ -0,0 +1,2 @@
+
+{"meta": {"total_count": 1277, "next": null, "limit": 20, "offset": 0, "query": "developer", "previous": null}, "objects": [{"username": "qzapaia", "bio": "developer", "app_url": "/qzapaia", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "qzapaia", "id": 4143, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/4143/"}, {"username": "erik_", "bio": "developer", "app_url": "/erik_", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "eriklieben", "id": 23427, "github": "", "website_url": "http://www.eriklieben.com", "full_name": "", "dribbble": "", "counts": {"follows": 10, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/23427/"}, {"username": "szahn", "bio": "Developer", "app_url": "/szahn", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/66fd7dfe-22b6-45a3-8fde-fe1ccb9fedcd/160x160", "twitter": "szahn", "id": 51839, "github": "", "website_url": "Stuart Zahn", "full_name": "", "dribbble": "", "counts": {"follows": 40, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/51839/"}, {"username": "aminudin", "bio": "Web Development, Hosting, IT Learning, Aplication Development", "app_url": "/aminudin", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "", "id": 35567, "github": "", "website_url": "http://www.aicsi.com/", "full_name": "", "dribbble": "", "counts": {"follows": 9, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/35567/"}, {"username": "risico", "bio": "w3 Software Developer. Hobbyist game developer.", "app_url": "/risico", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/575922f4-2cba-4587-b9a2-ec84b3786172/160x160", "twitter": "risico", "id": 25897, "github": "", "website_url": "http://robert.zimtea.com", "full_name": "", "dribbble": "", "counts": {"follows": 15, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/25897/"}, {"username": "chitsaou", "bio": "Web Developer / Rails Developer", "app_url": "/chitsaou", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/f7d35db9-948f-4e57-9447-15bba539f27e/160x160", "twitter": "yorkxin", "id": 21531, "github": "chitsaou", "website_url": "http://blog.yorkxin.org/", "full_name": "", "dribbble": "", "counts": {"follows": 7, "followed_by": 10}, "is_pro": false, "resource_uri": "/api/users/21531/"}, {"username": "thedev", "bio": "Web developer, Software developer, Freelancer", "app_url": "/thedev", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/46ef210c-44f1-4dce-a0bd-8f5949016861/160x160", "twitter": "the_dev", "id": 23494, "github": "", "website_url": "http://www.thedev.ro", "full_name": "", "dribbble": "", "counts": {"follows": 1, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/23494/"}, {"username": "koopajah", "bio": "Linux embedded C developer starting web development", "app_url": "/koopajah", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "koopajah", "id": 44740, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 2, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/44740/"}, {"username": "ahmednadar", "bio": "Web developer", "app_url": "/ahmednadar", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "ahmednadar", "id": 14286, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 3, "followed_by": 1}, "is_pro": false, "resource_uri": "/api/users/14286/"}, {"username": "yaandil", "bio": "Developer", "app_url": "/yaandil", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/fcd9078b-823f-49ba-8f0f-e56000eabf98/160x160", "twitter": "mkanski", "id": 10467, "github": "realez", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 7, "followed_by": 2}, "is_pro": false, "resource_uri": "/api/users/10467/"}, {"username": "julianosaless", "bio": "Software Developer", "app_url": "/julianosaless", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/cd2f2575-f4b5-4430-a941-eab804a0e303/160x160", "twitter": "JulianoSaless", "id": 40872, "github": "", "website_url": "http://www.devjulianosales.wordpress.com", "full_name": "", "dribbble": "", "counts": {"follows": 9, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/40872/"}, {"username": "dynamik", "bio": "under development!!!", "app_url": "/dynamik", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "dynamikus", "id": 33627, "github": "", "website_url": "http://www.dynamik.us", "full_name": "", "dribbble": "", "counts": {"follows": 12, "followed_by": 1}, "is_pro": false, "resource_uri": "/api/users/33627/"}, {"username": "danielveneg", "bio": "Web Developer", "app_url": "/danielveneg", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "danielveneg", "id": 32525, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/32525/"}, {"username": "mphome", "bio": "Software Developer", "app_url": "/mphome", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/5de37e1a-f190-4cc4-b579-70284be8582a/160x160", "twitter": "mphome", "id": 38248, "github": "", "website_url": "http://mphome.dp.ua", "full_name": "", "dribbble": "", "counts": {"follows": 9, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/38248/"}, {"username": "nevron", "bio": "Designer / Developer", "app_url": "/nevron", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/237cb878-fcc9-4b97-af60-86e795630634/160x160", "twitter": "nevron", "id": 26380, "github": "", "website_url": "http://www.erhantunali.com/blog", "full_name": "", "dribbble": "", "counts": {"follows": 13, "followed_by": 1}, "is_pro": false, "resource_uri": "/api/users/26380/"}, {"username": "garciademarina", "bio": "OSClass developer", "app_url": "/garciademarina", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/f73d31e5-8a97-4b50-adf8-b967e4331bc7/160x160", "twitter": "garciademarina", "id": 26878, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 14, "followed_by": 2}, "is_pro": false, "resource_uri": "/api/users/26878/"}, {"username": "sgcet", "bio": "web developer", "app_url": "/sgcet", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "sgcet", "id": 21324, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/21324/"}, {"username": "tzumby", "bio": "Rails developer", "app_url": "/tzumby", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/17d650d7-8874-416f-a1d7-27e85a42e3be/160x160", "twitter": "tzumby", "id": 28621, "github": "", "website_url": "http://www.razlab.com", "full_name": "", "dribbble": "", "counts": {"follows": 5, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/28621/"}, {"username": "arjoonkanth", "bio": "Web Developer", "app_url": "/arjoonkanth", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "", "id": 54311, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 11, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/54311/"}, {"username": "janerist", "bio": "Software developer", "app_url": "/janerist", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/ed084049-4d12-45c0-b2f1-d3d2d4a2f346/160x160", "twitter": "janerist", "id": 22629, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/22629/"}]}
@@ -0,0 +1 @@
+{"meta": {"total_count": 1277, "next": "/api/users/search/?q=developer&limit=20&offset=20", "limit": 20, "offset": 20, "query": "developer", "previous": "/api/users/search/?q=developer&limit=20&offset=0"}, "objects": [{"username": "qzapaia", "bio": "developer", "app_url": "/qzapaia", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "qzapaia", "id": 4143, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/4143/"}, {"username": "erik_", "bio": "developer", "app_url": "/erik_", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "eriklieben", "id": 23427, "github": "", "website_url": "http://www.eriklieben.com", "full_name": "", "dribbble": "", "counts": {"follows": 10, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/23427/"}, {"username": "szahn", "bio": "Developer", "app_url": "/szahn", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/66fd7dfe-22b6-45a3-8fde-fe1ccb9fedcd/160x160", "twitter": "szahn", "id": 51839, "github": "", "website_url": "Stuart Zahn", "full_name": "", "dribbble": "", "counts": {"follows": 40, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/51839/"}, {"username": "aminudin", "bio": "Web Development, Hosting, IT Learning, Aplication Development", "app_url": "/aminudin", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "", "id": 35567, "github": "", "website_url": "http://www.aicsi.com/", "full_name": "", "dribbble": "", "counts": {"follows": 9, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/35567/"}, {"username": "risico", "bio": "w3 Software Developer. Hobbyist game developer.", "app_url": "/risico", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/575922f4-2cba-4587-b9a2-ec84b3786172/160x160", "twitter": "risico", "id": 25897, "github": "", "website_url": "http://robert.zimtea.com", "full_name": "", "dribbble": "", "counts": {"follows": 15, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/25897/"}, {"username": "chitsaou", "bio": "Web Developer / Rails Developer", "app_url": "/chitsaou", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/f7d35db9-948f-4e57-9447-15bba539f27e/160x160", "twitter": "yorkxin", "id": 21531, "github": "chitsaou", "website_url": "http://blog.yorkxin.org/", "full_name": "", "dribbble": "", "counts": {"follows": 7, "followed_by": 10}, "is_pro": false, "resource_uri": "/api/users/21531/"}, {"username": "thedev", "bio": "Web developer, Software developer, Freelancer", "app_url": "/thedev", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/46ef210c-44f1-4dce-a0bd-8f5949016861/160x160", "twitter": "the_dev", "id": 23494, "github": "", "website_url": "http://www.thedev.ro", "full_name": "", "dribbble": "", "counts": {"follows": 1, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/23494/"}, {"username": "koopajah", "bio": "Linux embedded C developer starting web development", "app_url": "/koopajah", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "koopajah", "id": 44740, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 2, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/44740/"}, {"username": "ahmednadar", "bio": "Web developer", "app_url": "/ahmednadar", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "ahmednadar", "id": 14286, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 3, "followed_by": 1}, "is_pro": false, "resource_uri": "/api/users/14286/"}, {"username": "yaandil", "bio": "Developer", "app_url": "/yaandil", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/fcd9078b-823f-49ba-8f0f-e56000eabf98/160x160", "twitter": "mkanski", "id": 10467, "github": "realez", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 7, "followed_by": 2}, "is_pro": false, "resource_uri": "/api/users/10467/"}, {"username": "julianosaless", "bio": "Software Developer", "app_url": "/julianosaless", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/cd2f2575-f4b5-4430-a941-eab804a0e303/160x160", "twitter": "JulianoSaless", "id": 40872, "github": "", "website_url": "http://www.devjulianosales.wordpress.com", "full_name": "", "dribbble": "", "counts": {"follows": 9, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/40872/"}, {"username": "dynamik", "bio": "under development!!!", "app_url": "/dynamik", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "dynamikus", "id": 33627, "github": "", "website_url": "http://www.dynamik.us", "full_name": "", "dribbble": "", "counts": {"follows": 12, "followed_by": 1}, "is_pro": false, "resource_uri": "/api/users/33627/"}, {"username": "danielveneg", "bio": "Web Developer", "app_url": "/danielveneg", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "danielveneg", "id": 32525, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/32525/"}, {"username": "mphome", "bio": "Software Developer", "app_url": "/mphome", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/5de37e1a-f190-4cc4-b579-70284be8582a/160x160", "twitter": "mphome", "id": 38248, "github": "", "website_url": "http://mphome.dp.ua", "full_name": "", "dribbble": "", "counts": {"follows": 9, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/38248/"}, {"username": "nevron", "bio": "Designer / Developer", "app_url": "/nevron", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/237cb878-fcc9-4b97-af60-86e795630634/160x160", "twitter": "nevron", "id": 26380, "github": "", "website_url": "http://www.erhantunali.com/blog", "full_name": "", "dribbble": "", "counts": {"follows": 13, "followed_by": 1}, "is_pro": false, "resource_uri": "/api/users/26380/"}, {"username": "garciademarina", "bio": "OSClass developer", "app_url": "/garciademarina", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/f73d31e5-8a97-4b50-adf8-b967e4331bc7/160x160", "twitter": "garciademarina", "id": 26878, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 14, "followed_by": 2}, "is_pro": false, "resource_uri": "/api/users/26878/"}, {"username": "sgcet", "bio": "web developer", "app_url": "/sgcet", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "sgcet", "id": 21324, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/21324/"}, {"username": "tzumby", "bio": "Rails developer", "app_url": "/tzumby", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/17d650d7-8874-416f-a1d7-27e85a42e3be/160x160", "twitter": "tzumby", "id": 28621, "github": "", "website_url": "http://www.razlab.com", "full_name": "", "dribbble": "", "counts": {"follows": 5, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/28621/"}, {"username": "arjoonkanth", "bio": "Web Developer", "app_url": "/arjoonkanth", "avatar_url": "https://d17f28g3dsa4vh.cloudfront.net/img/default-avatar.png", "twitter": "", "id": 54311, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 11, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/54311/"}, {"username": "janerist", "bio": "Software developer", "app_url": "/janerist", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/ed084049-4d12-45c0-b2f1-d3d2d4a2f346/160x160", "twitter": "janerist", "id": 22629, "github": "", "website_url": "", "full_name": "", "dribbble": "", "counts": {"follows": 0, "followed_by": 0}, "is_pro": false, "resource_uri": "/api/users/22629/"}]}
@@ -74,4 +74,13 @@
clips.should be_a(Kippt::Clips)
end
end
+
+ describe "#users" do
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
+
+ it "returns a Kippt::Users instance" do
+ users = subject.users
+ users.should be_a(Kippt::Users)
+ end
+ end
end
@@ -0,0 +1,14 @@
+require "spec_helper"
+require "kippt/user_collection"
+
+describe Kippt::UserCollection do
+ let(:data) { MultiJson.load(fixture("users.json").read) }
+ let(:data_with_multiple_pages) {
+ MultiJson.load(fixture("users_with_multiple_pages.json").read)
+ }
+ subject { Kippt::UserCollection.new(data, collection_resource) }
+ let(:subject_with_multiple_pages) { Kippt::UserCollection.new(data_with_multiple_pages, collection_resource) }
+ let(:collection_resource) { nil }
+
+ it_behaves_like "collection"
+end
@@ -0,0 +1,23 @@
+require "spec_helper"
+require "kippt/user"
+
+describe Kippt::User do
+ subject { Kippt::User.new(data, collection_resource) }
+ let(:collection_resource) { Kippt::Client.new(valid_user_credentials).users }
+
+ let(:data) { MultiJson.load(fixture("user.json").read) }
+ let(:attributes) {
+ [:username, :bio, :app_url, :avatar_url, :twitter,
+ :id, :github, :website_url, :full_name, :dribble,
+ :counts, :resource_uri]
+ }
+
+ it_behaves_like "resource"
+
+ describe "#pro?" do
+ it "gets data from is_pro" do
+ user = Kippt::User.new({:is_pro => true}, nil)
+ user.pro?.should be_true
+ end
+ end
+end
Oops, something went wrong. Retry.

0 comments on commit 5a0cfb4

Please sign in to comment.