swish 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ swish*.gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jeremy Weiskotten
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,65 @@
1
+ = Swish! A Ruby wrapper for the Dribbble API
2
+
3
+ Learn about the Dribbble API at http://dribbble.com/api.
4
+
5
+ == Installation
6
+
7
+ Swish is just a Ruby gem:
8
+
9
+ gem install swish
10
+
11
+ == Examples
12
+
13
+ require 'swish'
14
+
15
+ # Find a shot
16
+ shot = Dribbble::Shot.find(21603)
17
+
18
+ # See some data about the shot
19
+ shot.title
20
+ shot.image_url
21
+ shot.url
22
+ shot.player.name
23
+
24
+ # Find more shots
25
+ inspiring = Dribbble::Shot.popular
26
+ call_the_police = Dribbble::Shot.everyone
27
+ yay_noobs = Dribbble::Shot.debuts
28
+
29
+ # Paginate through shots (default is 15 per page, max 30)
30
+ Dribbble::Shot.popular(:page => 2, :per_page => 3)
31
+ Dribbble::Shot.everyone(:page => 10, :per_page => 5)
32
+ Dribbble::Shot.debuts(:page => 5, :per_page => 30)
33
+
34
+ # Find a player
35
+ player = Dribbble::Player.find('jeremy')
36
+
37
+ # See some data about the player
38
+ player.name
39
+ player.avatar_url
40
+ player.url
41
+ player.location
42
+
43
+ # List a player's shots
44
+ player.shots
45
+ player.shots(:page => 2, :per_page => 10)
46
+
47
+ # List shots by player's that this player follows
48
+ player.shots_following
49
+ player.shots_following(:page => 5, :per_page => 30)
50
+
51
+
52
+
53
+ == Note on Patches/Pull Requests
54
+
55
+ * Fork the project.
56
+ * Make your feature addition or bug fix.
57
+ * Add tests for it. This is important so I don't break it in a
58
+ future version unintentionally.
59
+ * Commit, do not mess with rakefile, version, or history.
60
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
61
+ * Send me a pull request. Bonus points for topic branches.
62
+
63
+ == Copyright
64
+
65
+ Copyright (c) 2010 Jeremy Weiskotten. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "swish"
8
+ gem.summary = %Q{A Ruby wrapper for the Dribbble API}
9
+ gem.description = %Q{A Ruby wrapper for the Dribbble API}
10
+ gem.email = "jeremy@weiskotten.com"
11
+ gem.homepage = "http://github.com/jeremyw/swish"
12
+ gem.authors = ["Jeremy Weiskotten"]
13
+ gem.add_development_dependency "crack", ">= 0.1.8"
14
+ gem.add_development_dependency "httparty", ">= 0.6.1"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "swish #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,42 @@
1
+ module Dribbble
2
+ class Base
3
+ include HTTParty
4
+ extend HTTParty
5
+
6
+ base_uri 'api.dribbble.com'
7
+
8
+ def initialize(attributes={})
9
+ attributes ||= {}
10
+ attributes.each do |key, value|
11
+ instance_variable_set "@#{key}", value
12
+ end
13
+
14
+ after_initialize(attributes)
15
+ end
16
+
17
+ def ==(other)
18
+ other.equal?(self) || (other.instance_of?(self.class) && other.id == id)
19
+ end
20
+
21
+ # Delegates to ==
22
+ def eql?(other)
23
+ self == other
24
+ end
25
+
26
+ protected
27
+
28
+ def after_initialize(attributes)
29
+ # no-op, can be overridden
30
+ end
31
+
32
+ def self.paginated_list(result, list_key='shots')
33
+ # result['total']
34
+ # result['page']
35
+ # result['pages']
36
+ # result['per_page']
37
+ result[list_key].map do |attributes|
38
+ new(attributes)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ module Dribbble
2
+ class Player < Base
3
+ attr_accessor :id, :name, :url, :avatar_url, :location
4
+
5
+ def self.find(id)
6
+ new(get("/players/#{id}"))
7
+ end
8
+
9
+ # Fetches this player's shots.
10
+ # Options: :page, :per_page
11
+ def shots(options={})
12
+ Shot.paginated_list(self.class.get("/players/#{@id}/shots", :query => options))
13
+ end
14
+
15
+ # Fetches shots by players that this player follows.
16
+ def shots_following(options={})
17
+ Shot.paginated_list(self.class.get("/players/#{@id}/shots/following", :query => options))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module Dribbble
2
+ class Shot < Base
3
+ attr_accessor :id, :title, :url, :image_url, :image_teaser_url, :width, :height, :player
4
+
5
+ def after_initialize(attributes)
6
+ @player = Dribbble::Player.new(attributes['player'])
7
+ end
8
+
9
+ def self.find(id)
10
+ new(get("/shots/#{id}"))
11
+ end
12
+
13
+ # Options: :page, :per_page
14
+ def self.debuts(options={})
15
+ paginated_list(get("/shots/debuts", :query => options))
16
+ end
17
+
18
+ # Options: :page, :per_page
19
+ def self.everyone(options={})
20
+ paginated_list(get("/shots/everyone", :query => options))
21
+ end
22
+
23
+ # Options: :page, :per_page
24
+ def self.popular(options={})
25
+ paginated_list(get("/shots/popular", :query => options))
26
+ end
27
+ end
28
+ end
data/lib/swish.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'httparty'
2
+ require 'dribbble/base'
3
+ require 'dribbble/shot'
4
+ require 'dribbble/player'
data/swish.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{swish}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeremy Weiskotten"]
12
+ s.date = %q{2010-07-29}
13
+ s.description = %q{A Ruby wrapper for the Dribbble API}
14
+ s.email = %q{jeremy@weiskotten.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/dribbble/base.rb",
27
+ "lib/dribbble/player.rb",
28
+ "lib/dribbble/shot.rb",
29
+ "lib/swish.rb",
30
+ "swish.gemspec",
31
+ "test/helper.rb",
32
+ "test/player_test.rb",
33
+ "test/shot_test.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/jeremyw/swish}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{A Ruby wrapper for the Dribbble API}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/player_test.rb",
43
+ "test/shot_test.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<crack>, [">= 0.1.8"])
52
+ s.add_development_dependency(%q<httparty>, [">= 0.6.1"])
53
+ else
54
+ s.add_dependency(%q<crack>, [">= 0.1.8"])
55
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<crack>, [">= 0.1.8"])
59
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
60
+ end
61
+ end
62
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'swish'
7
+ # require 'ruby-debug'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ class PlayerTest < Test::Unit::TestCase
4
+ def test_find
5
+ player = Dribbble::Player.find(1)
6
+ assert_equal 1, player.id
7
+ assert_equal 'Dan Cederholm', player.name
8
+ assert_equal 'http://dribbble.com/players/simplebits', player.url
9
+ assert_equal 'Salem, MA', player.location
10
+ end
11
+
12
+ def test_shots
13
+ player = Dribbble::Player.find(1)
14
+ shots = player.shots
15
+ assert_equal 15, shots.size, "default page size"
16
+ shots.each do |shot|
17
+ assert_kind_of Dribbble::Shot, shot
18
+ assert_kind_of Dribbble::Player, shot.player
19
+ assert_equal player, shot.player
20
+ end
21
+
22
+ shots = player.shots(:per_page => 2)
23
+ assert_equal 2, shots.size
24
+ shots.each do |shot|
25
+ assert_equal player, shot.player
26
+ end
27
+ end
28
+
29
+ def test_shots_following
30
+ player = Dribbble::Player.find(1)
31
+ shots = player.shots_following
32
+ assert_equal 15, shots.size, "default page size"
33
+ shots.each do |shot|
34
+ assert_kind_of Dribbble::Shot, shot
35
+ assert_kind_of Dribbble::Player, shot.player
36
+ assert_not_equal player, shot.player
37
+ end
38
+
39
+ shots = player.shots_following(:per_page => 2)
40
+ assert_equal 2, shots.size
41
+ shots.each do |shot|
42
+ assert_not_equal player, shot.player
43
+ end
44
+ end
45
+ end
data/test/shot_test.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+
3
+ class ShotTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ shot = Dribbble::Shot.new(
6
+ 'id' => 999,
7
+ 'title' => 'Title',
8
+ 'url' => 'http://url',
9
+ 'image_url' => 'http://image_url',
10
+ 'image_teaser_url' => 'http://image_teaser_url',
11
+ 'width' => 3,
12
+ 'height' => 2)
13
+
14
+ assert_equal 999, shot.id
15
+ assert_equal 'Title', shot.title
16
+ assert_equal 'http://url', shot.url
17
+ assert_equal 'http://image_url', shot.image_url
18
+ assert_equal 'http://image_teaser_url', shot.image_teaser_url
19
+ assert_equal 3, shot.width
20
+ assert_equal 2, shot.height
21
+ end
22
+
23
+ def test_find
24
+ shot = Dribbble::Shot.find(21603)
25
+ assert_kind_of Dribbble::Shot, shot
26
+ assert_equal 21603, shot.id
27
+ assert_equal 'Moon', shot.title
28
+ assert_equal 'http://dribbble.com/shots/21603-Moon', shot.url
29
+ assert_equal 'http://dribbble.com/system/users/1/screenshots/21603/shot_1274474082.png', shot.image_url
30
+ assert_equal 'http://dribbble.com/system/users/1/screenshots/21603/shot_1274474082_teaser.png', shot.image_teaser_url
31
+ assert_equal 400, shot.width
32
+ assert_equal 300, shot.height
33
+
34
+ assert_kind_of Dribbble::Player, shot.player
35
+ end
36
+
37
+ def test_debuts
38
+ shots = Dribbble::Shot.debuts
39
+ assert_kind_of Array, shots
40
+ assert_kind_of Dribbble::Shot, shots.first
41
+
42
+ shots_page2 = Dribbble::Shot.debuts(:page => 2)
43
+ assert_not_equal shots_page2[0], shots[0]
44
+
45
+ s = Dribbble::Shot.debuts(:per_page => 3)
46
+ assert_equal 3, s.size
47
+ end
48
+
49
+ def test_everyone
50
+ shots = Dribbble::Shot.everyone(:per_page => 2)
51
+ assert_equal 2, shots.size
52
+ assert_kind_of Dribbble::Shot, shots.first
53
+ end
54
+
55
+ def test_popular
56
+ shots = Dribbble::Shot.popular(:per_page => 2)
57
+ assert_equal 2, shots.size
58
+ assert_kind_of Dribbble::Shot, shots.first
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swish
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jeremy Weiskotten
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-29 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: crack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 8
34
+ version: 0.1.8
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: httparty
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 5
46
+ segments:
47
+ - 0
48
+ - 6
49
+ - 1
50
+ version: 0.6.1
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: A Ruby wrapper for the Dribbble API
54
+ email: jeremy@weiskotten.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - .gitignore
65
+ - LICENSE
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION
69
+ - lib/dribbble/base.rb
70
+ - lib/dribbble/player.rb
71
+ - lib/dribbble/shot.rb
72
+ - lib/swish.rb
73
+ - swish.gemspec
74
+ - test/helper.rb
75
+ - test/player_test.rb
76
+ - test/shot_test.rb
77
+ has_rdoc: true
78
+ homepage: http://github.com/jeremyw/swish
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --charset=UTF-8
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.3.7
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A Ruby wrapper for the Dribbble API
111
+ test_files:
112
+ - test/helper.rb
113
+ - test/player_test.rb
114
+ - test/shot_test.rb