Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version bump to 0.1.0

  • Loading branch information...
commit 33fec574922483691fac5d3260731fe25c55749b 1 parent 1d0c88f
Jeremy Weiskotten authored
View
1  .gitignore
@@ -19,3 +19,4 @@ rdoc
pkg
## PROJECT::SPECIFIC
+swish*.gem
View
2  LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 Jeremy Weiskotten
+Copyright (c) 2010 Jeremy Weiskotten
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
52 README.rdoc
@@ -1,6 +1,54 @@
-= swish
+= Swish! A Ruby wrapper for the Dribbble API
+
+Learn about the Dribbble API at http://dribbble.com/api.
+
+== Installation
+
+Swish is just a Ruby gem:
+
+ gem install swish
+
+== Examples
+
+ require 'swish'
+
+ # Find a shot
+ shot = Dribbble::Shot.find(21603)
+
+ # See some data about the shot
+ shot.title
+ shot.image_url
+ shot.url
+ shot.player.name
+
+ # Find more shots
+ inspiring = Dribbble::Shot.popular
+ call_the_police = Dribbble::Shot.everyone
+ yay_noobs = Dribbble::Shot.debuts
+
+ # Paginate through shots (default is 15 per page, max 30)
+ Dribbble::Shot.popular(:page => 2, :per_page => 3)
+ Dribbble::Shot.everyone(:page => 10, :per_page => 5)
+ Dribbble::Shot.debuts(:page => 5, :per_page => 30)
+
+ # Find a player
+ player = Dribbble::Player.find('jeremy')
+
+ # See some data about the player
+ player.name
+ player.avatar_url
+ player.url
+ player.location
+
+ # List a player's shots
+ player.shots
+ player.shots(:page => 2, :per_page => 10)
+
+ # List shots by player's that this player follows
+ player.shots_following
+ player.shots_following(:page => 5, :per_page => 30)
+
-Description goes here.
== Note on Patches/Pull Requests
View
6 Rakefile
@@ -10,6 +10,8 @@ begin
gem.email = "jeremy@weiskotten.com"
gem.homepage = "http://github.com/jeremyw/swish"
gem.authors = ["Jeremy Weiskotten"]
+ gem.add_development_dependency "crack", ">= 0.1.8"
+ gem.add_development_dependency "httparty", ">= 0.6.1"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
@@ -20,7 +22,7 @@ end
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
+ test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
@@ -28,7 +30,7 @@ begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
+ test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
rescue LoadError
View
1  VERSION
@@ -0,0 +1 @@
+0.1.0
View
42 lib/dribbble/base.rb
@@ -0,0 +1,42 @@
+module Dribbble
+ class Base
+ include HTTParty
+ extend HTTParty
+
+ base_uri 'api.dribbble.com'
+
+ def initialize(attributes={})
+ attributes ||= {}
+ attributes.each do |key, value|
+ instance_variable_set "@#{key}", value
+ end
+
+ after_initialize(attributes)
+ end
+
+ def ==(other)
+ other.equal?(self) || (other.instance_of?(self.class) && other.id == id)
+ end
+
+ # Delegates to ==
+ def eql?(other)
+ self == other
+ end
+
+ protected
+
+ def after_initialize(attributes)
+ # no-op, can be overridden
+ end
+
+ def self.paginated_list(result, list_key='shots')
+ # result['total']
+ # result['page']
+ # result['pages']
+ # result['per_page']
+ result[list_key].map do |attributes|
+ new(attributes)
+ end
+ end
+ end
+end
View
20 lib/dribbble/player.rb
@@ -0,0 +1,20 @@
+module Dribbble
+ class Player < Base
+ attr_accessor :id, :name, :url, :avatar_url, :location
+
+ def self.find(id)
+ new(get("/players/#{id}"))
+ end
+
+ # Fetches this player's shots.
+ # Options: :page, :per_page
+ def shots(options={})
+ Shot.paginated_list(self.class.get("/players/#{@id}/shots", :query => options))
+ end
+
+ # Fetches shots by players that this player follows.
+ def shots_following(options={})
+ Shot.paginated_list(self.class.get("/players/#{@id}/shots/following", :query => options))
+ end
+ end
+end
View
28 lib/dribbble/shot.rb
@@ -0,0 +1,28 @@
+module Dribbble
+ class Shot < Base
+ attr_accessor :id, :title, :url, :image_url, :image_teaser_url, :width, :height, :player
+
+ def after_initialize(attributes)
+ @player = Dribbble::Player.new(attributes['player'])
+ end
+
+ def self.find(id)
+ new(get("/shots/#{id}"))
+ end
+
+ # Options: :page, :per_page
+ def self.debuts(options={})
+ paginated_list(get("/shots/debuts", :query => options))
+ end
+
+ # Options: :page, :per_page
+ def self.everyone(options={})
+ paginated_list(get("/shots/everyone", :query => options))
+ end
+
+ # Options: :page, :per_page
+ def self.popular(options={})
+ paginated_list(get("/shots/popular", :query => options))
+ end
+ end
+end
View
4 lib/swish.rb
@@ -0,0 +1,4 @@
+require 'httparty'
+require 'dribbble/base'
+require 'dribbble/shot'
+require 'dribbble/player'
View
61 swish.gemspec
@@ -0,0 +1,61 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{swish}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Jeremy Weiskotten"]
+ s.date = %q{2010-07-29}
+ s.description = %q{A Ruby wrapper for the Dribbble API}
+ s.email = %q{jeremy@weiskotten.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/dribbble/base.rb",
+ "lib/dribbble/player.rb",
+ "lib/dribbble/shot.rb",
+ "lib/swish.rb",
+ "test/helper.rb",
+ "test/player_test.rb",
+ "test/shot_test.rb"
+ ]
+ s.homepage = %q{http://github.com/jeremyw/swish}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{A Ruby wrapper for the Dribbble API}
+ s.test_files = [
+ "test/helper.rb",
+ "test/player_test.rb",
+ "test/shot_test.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<crack>, [">= 0.1.8"])
+ s.add_development_dependency(%q<httparty>, [">= 0.6.1"])
+ else
+ s.add_dependency(%q<crack>, [">= 0.1.8"])
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
+ end
+ else
+ s.add_dependency(%q<crack>, [">= 0.1.8"])
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
+ end
+end
+
View
1  test/helper.rb
@@ -4,6 +4,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'swish'
+# require 'ruby-debug'
class Test::Unit::TestCase
end
View
45 test/player_test.rb
@@ -0,0 +1,45 @@
+require 'helper'
+
+class PlayerTest < Test::Unit::TestCase
+ def test_find
+ player = Dribbble::Player.find(1)
+ assert_equal 1, player.id
+ assert_equal 'Dan Cederholm', player.name
+ assert_equal 'http://dribbble.com/players/simplebits', player.url
+ assert_equal 'Salem, MA', player.location
+ end
+
+ def test_shots
+ player = Dribbble::Player.find(1)
+ shots = player.shots
+ assert_equal 15, shots.size, "default page size"
+ shots.each do |shot|
+ assert_kind_of Dribbble::Shot, shot
+ assert_kind_of Dribbble::Player, shot.player
+ assert_equal player, shot.player
+ end
+
+ shots = player.shots(:per_page => 2)
+ assert_equal 2, shots.size
+ shots.each do |shot|
+ assert_equal player, shot.player
+ end
+ end
+
+ def test_shots_following
+ player = Dribbble::Player.find(1)
+ shots = player.shots_following
+ assert_equal 15, shots.size, "default page size"
+ shots.each do |shot|
+ assert_kind_of Dribbble::Shot, shot
+ assert_kind_of Dribbble::Player, shot.player
+ assert_not_equal player, shot.player
+ end
+
+ shots = player.shots_following(:per_page => 2)
+ assert_equal 2, shots.size
+ shots.each do |shot|
+ assert_not_equal player, shot.player
+ end
+ end
+end
View
60 test/shot_test.rb
@@ -0,0 +1,60 @@
+require 'helper'
+
+class ShotTest < Test::Unit::TestCase
+ def test_initialize
+ shot = Dribbble::Shot.new(
+ 'id' => 999,
+ 'title' => 'Title',
+ 'url' => 'http://url',
+ 'image_url' => 'http://image_url',
+ 'image_teaser_url' => 'http://image_teaser_url',
+ 'width' => 3,
+ 'height' => 2)
+
+ assert_equal 999, shot.id
+ assert_equal 'Title', shot.title
+ assert_equal 'http://url', shot.url
+ assert_equal 'http://image_url', shot.image_url
+ assert_equal 'http://image_teaser_url', shot.image_teaser_url
+ assert_equal 3, shot.width
+ assert_equal 2, shot.height
+ end
+
+ def test_find
+ shot = Dribbble::Shot.find(21603)
+ assert_kind_of Dribbble::Shot, shot
+ assert_equal 21603, shot.id
+ assert_equal 'Moon', shot.title
+ assert_equal 'http://dribbble.com/shots/21603-Moon', shot.url
+ assert_equal 'http://dribbble.com/system/users/1/screenshots/21603/shot_1274474082.png', shot.image_url
+ assert_equal 'http://dribbble.com/system/users/1/screenshots/21603/shot_1274474082_teaser.png', shot.image_teaser_url
+ assert_equal 400, shot.width
+ assert_equal 300, shot.height
+
+ assert_kind_of Dribbble::Player, shot.player
+ end
+
+ def test_debuts
+ shots = Dribbble::Shot.debuts
+ assert_kind_of Array, shots
+ assert_kind_of Dribbble::Shot, shots.first
+
+ shots_page2 = Dribbble::Shot.debuts(:page => 2)
+ assert_not_equal shots_page2[0], shots[0]
+
+ s = Dribbble::Shot.debuts(:per_page => 3)
+ assert_equal 3, s.size
+ end
+
+ def test_everyone
+ shots = Dribbble::Shot.everyone(:per_page => 2)
+ assert_equal 2, shots.size
+ assert_kind_of Dribbble::Shot, shots.first
+ end
+
+ def test_popular
+ shots = Dribbble::Shot.popular(:per_page => 2)
+ assert_equal 2, shots.size
+ assert_kind_of Dribbble::Shot, shots.first
+ end
+end
View
7 test/test_swish.rb
@@ -1,7 +0,0 @@
-require 'helper'
-
-class TestSwish < Test::Unit::TestCase
- def test_something_for_real
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.