dribble 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,21 @@
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
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Robert R Evans
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,19 @@
1
+ = dribble
2
+
3
+ A Dribble API wrapper.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ The name "Dribble" belongs to http://www.dribble.com
18
+
19
+ Copyright (c) 2010 Robert R Evans. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dribble"
8
+ gem.summary = %Q{API Wrapper for the awesome Dribble Site}
9
+ gem.description = %Q{API Wrapper for the awesome Dribble Site}
10
+ gem.email = "robert@codewranglers.org"
11
+ gem.homepage = "http://github.com/revans/dribble"
12
+ gem.authors = ["Robert R Evans"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+
16
+ gem.add_dependency 'yajl-ruby', '= 0.7.7'
17
+
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ begin
39
+ require 'reek/adapters/rake_task'
40
+ Reek::RakeTask.new do |t|
41
+ t.fail_on_error = true
42
+ t.verbose = false
43
+ t.source_files = 'lib/**/*.rb'
44
+ end
45
+ rescue LoadError
46
+ task :reek do
47
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
48
+ end
49
+ end
50
+
51
+ begin
52
+ require 'roodi'
53
+ require 'roodi_task'
54
+ RoodiTask.new do |t|
55
+ t.verbose = false
56
+ end
57
+ rescue LoadError
58
+ task :roodi do
59
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
60
+ end
61
+ end
62
+
63
+ task :default => :spec
64
+
65
+ begin
66
+ require 'yard'
67
+ YARD::Rake::YardocTask.new
68
+ rescue LoadError
69
+ task :yardoc do
70
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
71
+ end
72
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,13 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'dribble')
3
+
4
+ puts "Find Player's Shots by name"
5
+ puts Dribble::Player.find('simplebits').inspect
6
+
7
+ puts
8
+ puts "Find Player's Profile"
9
+ puts Dribble::Player.profile('simplebits').inspect
10
+
11
+ puts
12
+ puts "Find Player's Followers"
13
+ puts Dribble::Player.followers('simplebits').inspect
data/examples/shot.rb ADDED
@@ -0,0 +1,19 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'dribble')
3
+
4
+ puts "Find a specific shot by ID"
5
+ puts Dribble::Shot.for(1).inspect
6
+
7
+ puts
8
+ puts "Everyone's shots"
9
+ puts Dribble::Shot.everyones.inspect
10
+
11
+
12
+ puts
13
+ puts "Debut shots"
14
+ puts Dribble::Shot.everyones.inspect
15
+
16
+
17
+ puts
18
+ puts "Popular shots"
19
+ puts Dribble::Shot.everyones.inspect
@@ -0,0 +1,55 @@
1
+ class Hash
2
+
3
+ ##
4
+ # To query
5
+ #
6
+ # @param [String]
7
+ # @return [String]
8
+ # @api Public
9
+ #
10
+ def to_query(namespace = nil)
11
+ collect do |key, value|
12
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
13
+ end.sort * '&'
14
+ end
15
+
16
+
17
+ ##
18
+ # Symbolize Keys
19
+ #
20
+ # @return [Hash]
21
+ # @api Public
22
+ #
23
+ def symbolize_keys
24
+ inject({}) do |options, (key, value)|
25
+ options[(key.to_sym rescue key) || key] = value
26
+ options
27
+ end
28
+ end
29
+
30
+
31
+ ##
32
+ # Symbolize Keys!
33
+ #
34
+ # @return [Hash]
35
+ # @api Public
36
+ #
37
+ def symbolize_keys!
38
+ self.replace(self.symbolize_keys)
39
+ end
40
+
41
+
42
+ ##
43
+ # Recursively Symbolize Keys!
44
+ #
45
+ # @return [Hash]
46
+ # @api Public
47
+ #
48
+ def recursive_symbolize_keys!
49
+ symbolize_keys!
50
+ values.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
51
+ values.select{|v| v.is_a?(Array) }.flatten.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
52
+ self
53
+ end
54
+
55
+ end
@@ -0,0 +1,19 @@
1
+ class Object
2
+ def blank?
3
+ if respond_to?(:empty?)
4
+ nil? || empty?
5
+ else
6
+ nil?
7
+ end
8
+ end
9
+
10
+
11
+ def to_query(key)
12
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
13
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
14
+ end
15
+
16
+ def to_param
17
+ to_s
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ module Dribble
2
+ class Player
3
+ class << self
4
+
5
+
6
+ ##
7
+ # Find shots for a given player
8
+ #
9
+ # @param [String/Integer]
10
+ # @return [Hash]
11
+ # @api public
12
+ #
13
+ def find(id, options={})
14
+ Dribble::Request.get("/players/#{id}/shots", setup_options(options))
15
+ end
16
+
17
+
18
+ ##
19
+ # Followers
20
+ #
21
+ # @param [String/Integer]
22
+ # @return [Hash]
23
+ # @api public
24
+ #
25
+ def followers(id, options={})
26
+ Dribble::Request.get("/players/#{id}/shots/following", setup_options(options))
27
+ end
28
+
29
+
30
+ ##
31
+ # Profile
32
+ #
33
+ # @param [String/Integer]
34
+ # @return [Hash]
35
+ # @api public
36
+ #
37
+ def profile(id)
38
+ Dribble::Request.get("/players/#{id}")
39
+ end
40
+
41
+
42
+
43
+ private
44
+
45
+ def setup_options(options)
46
+ {:per_page => 30, :page => 1}.merge(options)
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ module Dribble
2
+ class Request
3
+ class << self
4
+
5
+ DRIBBLE_API = 'api.dribbble.com'
6
+ TIMEOUT = 10
7
+
8
+ def get(query, options={})
9
+ uri = options.empty? ? "#{to_url}#{query}" : "#{to_url}#{query}?#{options.to_query}"
10
+ url = ::URI.parse(uri)
11
+ ::Yajl::HttpStream.get(url, :symbolize_keys => true)
12
+ end
13
+
14
+
15
+ private
16
+
17
+ def to_url
18
+ "http://#{DRIBBLE_API}"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,67 @@
1
+ module Dribble
2
+ class Shot
3
+ class << self
4
+
5
+
6
+ ##
7
+ # By ID
8
+ #
9
+ # @param [Integer]
10
+ # @return [Hash]
11
+ # @api public
12
+ #
13
+ def for(id)
14
+ Dribble::Request.get("/shots/#{id.to_i}")
15
+ end
16
+
17
+
18
+ ##
19
+ # Everyones
20
+ #
21
+ # @param [Hash]
22
+ # e.g. {:per_page => 30, :page => 1}
23
+ #
24
+ # @return [Array]
25
+ # @api public
26
+ #
27
+ def everyones(options={})
28
+ Dribble::Request.get("/shots/everyone", setup_options(options))
29
+ end
30
+
31
+
32
+ ##
33
+ # Debuts
34
+ #
35
+ # @param [Hash]
36
+ # e.g. {:per_page => 30, :page => 1}
37
+ #
38
+ # @return [Array]
39
+ # @api public
40
+ #
41
+ def debuts(options={})
42
+ Dribble::Request.get("/shots/debuts", setup_options(options))
43
+ end
44
+
45
+
46
+ ##
47
+ # Popular
48
+ #
49
+ # @param [Hash]
50
+ # e.g. {:per_page => 30, :page => 1}
51
+ #
52
+ # @return [Array]
53
+ # @api public
54
+ #
55
+ def popular(options={})
56
+ Dribble::Request.get("/shots/popular", setup_options(options))
57
+ end
58
+
59
+ private
60
+
61
+ def setup_options(options)
62
+ {:per_page => 30, :page => 1}.merge(options)
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,10 @@
1
+ module Dribble
2
+ module Version
3
+ MAJOR,MINOR,TINY = File.read(File.join(File.dirname(__FILE__), '../../VERSION')).split('.')
4
+ STRING = [MAJOR, MINOR, TINY].join('.')
5
+ end
6
+
7
+ def self.version
8
+ Version::STRING
9
+ end
10
+ end
data/lib/dribble.rb ADDED
@@ -0,0 +1,20 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ # require 'rubygems'
4
+ require 'yajl/http_stream'
5
+ require 'yajl'
6
+
7
+ base = File.expand_path(File.dirname(__FILE__))
8
+
9
+ # Require Open Class Extensions
10
+ Dir[File.join(File.join(base, 'core_ext'), '*.rb')].each { |file| require file }
11
+
12
+ require File.join(base, 'dribble/version')
13
+
14
+ module Dribble
15
+ autoload :Request, 'dribble/request'
16
+
17
+ # The API
18
+ autoload :Player, 'dribble/player'
19
+ autoload :Shot, 'dribble/shot'
20
+ end
data/spec/rcov.opts ADDED
@@ -0,0 +1,4 @@
1
+ --sort coverage
2
+ --profile
3
+ --rails
4
+ --exclue /gems/,/Library/,spec
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format profile
3
+ --loadby mtime
4
+ --reverse
5
+ --drb
6
+ --timeout 20
7
+ --diff
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'dribble'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dribble
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Robert R Evans
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-30 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: yajl-ruby
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 13
60
+ segments:
61
+ - 0
62
+ - 7
63
+ - 7
64
+ version: 0.7.7
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ description: API Wrapper for the awesome Dribble Site
68
+ email: robert@codewranglers.org
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - LICENSE
80
+ - README.rdoc
81
+ - Rakefile
82
+ - VERSION
83
+ - examples/player.rb
84
+ - examples/shot.rb
85
+ - lib/core_ext/hash.rb
86
+ - lib/core_ext/object.rb
87
+ - lib/dribble.rb
88
+ - lib/dribble/player.rb
89
+ - lib/dribble/request.rb
90
+ - lib/dribble/shot.rb
91
+ - lib/dribble/version.rb
92
+ - spec/rcov.opts
93
+ - spec/spec.opts
94
+ - spec/spec_helper.rb
95
+ has_rdoc: true
96
+ homepage: http://github.com/revans/dribble
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options:
101
+ - --charset=UTF-8
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.3.7
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: API Wrapper for the awesome Dribble Site
129
+ test_files:
130
+ - spec/spec_helper.rb
131
+ - examples/player.rb
132
+ - examples/shot.rb