dribble 0.0.1 → 0.0.2
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/LICENSE +1 -1
- data/README.rdoc +20 -2
- data/VERSION +1 -1
- data/dribble.gemspec +78 -0
- data/examples/barebones/player.rb +14 -0
- data/examples/barebones/shot.rb +21 -0
- data/examples/player.rb +12 -7
- data/examples/shot.rb +38 -10
- data/lib/dribble/api/player.rb +51 -0
- data/lib/dribble/api/shot.rb +84 -0
- data/lib/dribble/exceptions.rb +3 -0
- data/lib/dribble/player.rb +65 -18
- data/lib/dribble/request.rb +6 -5
- data/lib/dribble/shot.rb +88 -61
- data/lib/dribble/shots.rb +43 -0
- data/lib/dribble.rb +21 -6
- metadata +13 -4
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,24 @@
|
|
1
|
-
=
|
1
|
+
= Dribble
|
2
2
|
|
3
|
-
|
3
|
+
This is the unofficial dribble api.
|
4
|
+
|
5
|
+
There is a very thin wrapper for the Dribble API that is labeled as Dribble::API. This uses the bare minimum to get the desired data from Dribble and returns a symbolized hash. This implementation is focused on simplicity and speed. However, I have yet to really work on the speed aspect.
|
6
|
+
|
7
|
+
== Dribble::API
|
8
|
+
|
9
|
+
Dribble::API::Player.profile('simplebits')
|
10
|
+
Dribble::API::Shot.popular
|
11
|
+
|
12
|
+
|
13
|
+
Dribble::Player and Dribble::Shot is another layer on-top of the API to add that object look and feel. This is more for convenience and ease of use.
|
14
|
+
|
15
|
+
This is meant for convenience and ease of use.
|
16
|
+
|
17
|
+
|
18
|
+
== Dribble::Player && Dribble::Shot
|
19
|
+
|
20
|
+
Dribble::Player.find('simplebits')
|
21
|
+
Dribble::Shot.popular
|
4
22
|
|
5
23
|
== Note on Patches/Pull Requests
|
6
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/dribble.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
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{dribble}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Robert R Evans"]
|
12
|
+
s.date = %q{2010-08-02}
|
13
|
+
s.description = %q{API Wrapper for the awesome Dribble Site}
|
14
|
+
s.email = %q{robert@codewranglers.org}
|
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
|
+
"dribble.gemspec",
|
27
|
+
"examples/barebones/player.rb",
|
28
|
+
"examples/barebones/shot.rb",
|
29
|
+
"examples/player.rb",
|
30
|
+
"examples/shot.rb",
|
31
|
+
"lib/core_ext/hash.rb",
|
32
|
+
"lib/core_ext/object.rb",
|
33
|
+
"lib/dribble.rb",
|
34
|
+
"lib/dribble/api/player.rb",
|
35
|
+
"lib/dribble/api/shot.rb",
|
36
|
+
"lib/dribble/exceptions.rb",
|
37
|
+
"lib/dribble/player.rb",
|
38
|
+
"lib/dribble/request.rb",
|
39
|
+
"lib/dribble/shot.rb",
|
40
|
+
"lib/dribble/shots.rb",
|
41
|
+
"lib/dribble/version.rb",
|
42
|
+
"spec/rcov.opts",
|
43
|
+
"spec/spec.opts",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/revans/dribble}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.7}
|
50
|
+
s.summary = %q{API Wrapper for the awesome Dribble Site}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/spec_helper.rb",
|
53
|
+
"examples/barebones/player.rb",
|
54
|
+
"examples/barebones/shot.rb",
|
55
|
+
"examples/player.rb",
|
56
|
+
"examples/shot.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["= 0.7.7"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
69
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
70
|
+
s.add_dependency(%q<yajl-ruby>, ["= 0.7.7"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
74
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
75
|
+
s.add_dependency(%q<yajl-ruby>, ["= 0.7.7"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,14 @@
|
|
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::API::Player.find('simplebits').inspect
|
6
|
+
|
7
|
+
puts
|
8
|
+
puts "Find Player's Profile"
|
9
|
+
player = Dribble::API::Player.profile('simplebits')
|
10
|
+
puts player
|
11
|
+
|
12
|
+
# puts
|
13
|
+
# puts "Find all the shots a player is following"
|
14
|
+
# puts Dribble::API::Player.following_shots('simplebits').inspect
|
@@ -0,0 +1,21 @@
|
|
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
|
+
# shot = Dribble::API::Shot.for(1)
|
6
|
+
# puts shot.inspect
|
7
|
+
|
8
|
+
# puts
|
9
|
+
# puts "Everyone's shots"
|
10
|
+
# puts Dribble::API::Shot.everyones.inspect
|
11
|
+
|
12
|
+
|
13
|
+
# puts
|
14
|
+
# puts "Debut shots"
|
15
|
+
# puts Dribble::API::Shot.debuts.inspect
|
16
|
+
|
17
|
+
|
18
|
+
puts
|
19
|
+
puts "Popular shots"
|
20
|
+
popular = Dribble::API::Shot.popular
|
21
|
+
puts popular.inspect
|
data/examples/player.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
require File.join(dir, 'dribble')
|
3
3
|
|
4
|
-
puts "Find Player's Shots by name"
|
5
|
-
|
4
|
+
# puts "Find Player's Shots by name"
|
5
|
+
# player = Dribble::Player.find_shots('simplebits')
|
6
|
+
# puts player.inspect
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# puts
|
10
|
+
# puts "Find Player's Profile"
|
11
|
+
# player2 = Dribble::Player.profile('simplebits') # OR Dribble::Player.find('simplebits')
|
12
|
+
# puts player.inspect
|
6
13
|
|
7
|
-
puts
|
8
|
-
puts "Find Player's Profile"
|
9
|
-
puts Dribble::Player.profile('simplebits').inspect
|
10
14
|
|
11
15
|
puts
|
12
|
-
puts "Find Player
|
13
|
-
|
16
|
+
puts "Find the shots that a specific Player is following"
|
17
|
+
player3 = Dribble::Player.following_shots('simplebits')
|
18
|
+
puts player3.inspect
|
data/examples/shot.rb
CHANGED
@@ -1,19 +1,47 @@
|
|
1
1
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
require File.join(dir, 'dribble')
|
3
3
|
|
4
|
-
puts "Find a specific shot by ID"
|
5
|
-
|
4
|
+
# puts "Find a specific shot by ID"
|
5
|
+
# shot = Dribble::Shot.for(1)
|
6
|
+
# puts shot.inspect
|
7
|
+
#
|
8
|
+
# puts
|
9
|
+
# puts "Everyone's shots"
|
10
|
+
# puts Dribble::Shot.everyones.inspect
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# puts
|
14
|
+
# puts "Debut shots"
|
15
|
+
# puts Dribble::Shot.debuts.inspect
|
6
16
|
|
7
|
-
puts
|
8
|
-
puts "Everyone's shots"
|
9
|
-
puts Dribble::Shot.everyones.inspect
|
10
17
|
|
18
|
+
# puts
|
19
|
+
# puts "Popular shots"
|
20
|
+
# popular = Dribble::Shot.popular
|
21
|
+
# puts popular.inspect
|
22
|
+
# puts
|
23
|
+
# popular_page_2 = popular.next_page
|
24
|
+
# puts popular_page_2.inspect
|
11
25
|
|
12
|
-
|
13
|
-
puts
|
14
|
-
puts
|
26
|
+
|
27
|
+
# puts
|
28
|
+
# puts "Dan's Following these shots"
|
29
|
+
# following = Dribble::Shot.following(1)
|
30
|
+
# puts following.inspect
|
31
|
+
# puts
|
32
|
+
# following_page_2 = following.next_page
|
33
|
+
# puts following_page_2.inspect
|
15
34
|
|
16
35
|
|
17
36
|
puts
|
18
|
-
puts "
|
19
|
-
|
37
|
+
puts "Get a Player's Profile"
|
38
|
+
player = Dribble::Player.find(1)
|
39
|
+
puts player.inspect
|
40
|
+
puts
|
41
|
+
puts "Take this player and see what shots they are following"
|
42
|
+
following_shots = player.following
|
43
|
+
puts following_shots.inspect
|
44
|
+
puts
|
45
|
+
puts "Take this player and see what shots they've put up"
|
46
|
+
my_shots = player.shots
|
47
|
+
puts my_shots.inspect
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Dribble
|
2
|
+
module API
|
3
|
+
class Player
|
4
|
+
|
5
|
+
|
6
|
+
##
|
7
|
+
# Find shots for a given player
|
8
|
+
#
|
9
|
+
# @param [String/Integer]
|
10
|
+
# @return [Hash]
|
11
|
+
# @api public
|
12
|
+
#
|
13
|
+
def self.find_shots(id, options={})
|
14
|
+
Dribble::Request.get("/players/#{id}/shots", setup_options(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
##
|
19
|
+
# Following Shots
|
20
|
+
#
|
21
|
+
# @param [String/Integer]
|
22
|
+
# @return [Hash]
|
23
|
+
# @api public
|
24
|
+
#
|
25
|
+
def self.following_shots(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 self.profile(id)
|
38
|
+
Dribble::Request.get("/players/#{id}")
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.setup_options(options)
|
45
|
+
{:per_page => 30, :page => 1}.merge(options)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Dribble
|
2
|
+
module API
|
3
|
+
class Shot
|
4
|
+
|
5
|
+
|
6
|
+
##
|
7
|
+
# By ID
|
8
|
+
#
|
9
|
+
# @param [Integer]
|
10
|
+
# @return [Hash]
|
11
|
+
# @api public
|
12
|
+
#
|
13
|
+
def self.for(id)
|
14
|
+
Dribble::Request.get("/shots/#{id.to_i}")
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
##
|
19
|
+
# Following
|
20
|
+
#
|
21
|
+
# @param [String/Integer, Hash]
|
22
|
+
# e.g. {:per_page => 30, :page => 1}
|
23
|
+
#
|
24
|
+
# @return [Hash]
|
25
|
+
# @api public
|
26
|
+
#
|
27
|
+
def self.following(id, options={})
|
28
|
+
Dribble::Request.get("/players/#{id}/shots/following", setup_options(options))
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
##
|
33
|
+
# Everyones
|
34
|
+
#
|
35
|
+
# @param [Hash]
|
36
|
+
# e.g. {:per_page => 30, :page => 1}
|
37
|
+
#
|
38
|
+
# @return [Array]
|
39
|
+
# @api public
|
40
|
+
#
|
41
|
+
def self.everyones(options={})
|
42
|
+
Dribble::Request.get("/shots/everyone", setup_options(options))
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
##
|
47
|
+
# Debuts
|
48
|
+
#
|
49
|
+
# @param [Hash]
|
50
|
+
# e.g. {:per_page => 30, :page => 1}
|
51
|
+
#
|
52
|
+
# @return [Array]
|
53
|
+
# @api public
|
54
|
+
#
|
55
|
+
def self.debuts(options={})
|
56
|
+
Dribble::Request.get("/shots/debuts", setup_options(options))
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
##
|
61
|
+
# Popular
|
62
|
+
#
|
63
|
+
# @param [Hash]
|
64
|
+
# e.g. {:per_page => 30, :page => 1}
|
65
|
+
#
|
66
|
+
# @return [Array]
|
67
|
+
# @api public
|
68
|
+
#
|
69
|
+
def self.popular(options={})
|
70
|
+
Dribble::Request.get("/shots/popular", setup_options(options))
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
|
77
|
+
def self.setup_options(options)
|
78
|
+
{:per_page => 30, :page => 1}.merge(options)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/dribble/player.rb
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
module Dribble
|
2
2
|
class Player
|
3
|
+
attr_reader :id, :name, :url, :avatar_url, :location, :created_at, :draftees_count,
|
4
|
+
:following_count, :shots_count, :followers_count, :following, :shots
|
5
|
+
|
6
|
+
|
7
|
+
def initialize(attr={})
|
8
|
+
attr.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
##
|
15
|
+
# Following
|
16
|
+
#
|
17
|
+
# @param [Hash]
|
18
|
+
# @return [Array]
|
19
|
+
# @api public
|
20
|
+
#
|
21
|
+
def following(options={})
|
22
|
+
@following ||= Dribble::API::Shot.following(self.id, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
##
|
27
|
+
# Player's Shots
|
28
|
+
#
|
29
|
+
# @param [Hash]
|
30
|
+
# @return [Array]
|
31
|
+
# @api public
|
32
|
+
#
|
33
|
+
def shots(options={})
|
34
|
+
@shots ||= Dribble::API::Player.find_shots(self.id, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
3
38
|
class << self
|
4
39
|
|
5
40
|
|
@@ -7,45 +42,57 @@ module Dribble
|
|
7
42
|
# Find shots for a given player
|
8
43
|
#
|
9
44
|
# @param [String/Integer]
|
10
|
-
# @return [
|
45
|
+
# @return [Object]
|
11
46
|
# @api public
|
12
47
|
#
|
13
|
-
def
|
14
|
-
Dribble::
|
48
|
+
def find_shots(id, options={})
|
49
|
+
results = Dribble::API::Player.find_shots(id, options)
|
50
|
+
Dribble::Shots.new(format_shots(results), results)
|
15
51
|
end
|
16
|
-
|
17
|
-
|
52
|
+
|
53
|
+
|
18
54
|
##
|
19
|
-
#
|
55
|
+
# Following Shots
|
20
56
|
#
|
21
57
|
# @param [String/Integer]
|
22
|
-
# @return [
|
58
|
+
# @return [Object]
|
23
59
|
# @api public
|
24
60
|
#
|
25
|
-
def
|
26
|
-
Dribble::
|
61
|
+
def following_shots(id, options={})
|
62
|
+
results = Dribble::API::Player.following_shots(id, options)
|
63
|
+
Dribble::Shots.new(format_shots(results), results)
|
27
64
|
end
|
28
|
-
|
29
|
-
|
65
|
+
|
66
|
+
|
30
67
|
##
|
31
68
|
# Profile
|
32
69
|
#
|
33
70
|
# @param [String/Integer]
|
34
|
-
# @return [
|
71
|
+
# @return [Object]
|
35
72
|
# @api public
|
36
73
|
#
|
37
74
|
def profile(id)
|
38
|
-
Dribble::
|
75
|
+
new(Dribble::API::Player.profile(id))
|
39
76
|
end
|
77
|
+
alias_method :find, :profile
|
40
78
|
|
41
|
-
|
42
|
-
|
79
|
+
|
43
80
|
private
|
44
81
|
|
45
|
-
|
46
|
-
|
82
|
+
|
83
|
+
##
|
84
|
+
# Format Shots
|
85
|
+
#
|
86
|
+
# @param [Array, Symbold]
|
87
|
+
# @return [Object]
|
88
|
+
# @api private
|
89
|
+
#
|
90
|
+
def format_shots(response, index = :shots)
|
91
|
+
response[index].map do |shot|
|
92
|
+
Dribble::Shot.new(shot)
|
93
|
+
end
|
47
94
|
end
|
48
|
-
|
49
95
|
end
|
96
|
+
|
50
97
|
end
|
51
98
|
end
|
data/lib/dribble/request.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module Dribble
|
2
2
|
class Request
|
3
3
|
class << self
|
4
|
-
|
5
4
|
DRIBBLE_API = 'api.dribbble.com'
|
6
|
-
TIMEOUT = 10
|
7
5
|
|
8
6
|
def get(query, options={})
|
9
|
-
|
10
|
-
|
11
|
-
::
|
7
|
+
meth = options.delete(:api_endpoint)
|
8
|
+
uri = options.empty? ? "#{to_url}#{query}" : "#{to_url}#{query}?#{options.to_query}"
|
9
|
+
url = ::URI.parse(uri)
|
10
|
+
results = ::Yajl::HttpStream.get(url, :symbolize_keys => true)
|
11
|
+
results[:api_endpoint] = meth if meth
|
12
|
+
results
|
12
13
|
end
|
13
14
|
|
14
15
|
|
data/lib/dribble/shot.rb
CHANGED
@@ -1,67 +1,94 @@
|
|
1
1
|
module Dribble
|
2
2
|
class Shot
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# @return [Hash]
|
11
|
-
# @api public
|
12
|
-
#
|
13
|
-
def for(id)
|
14
|
-
Dribble::Request.get("/shots/#{id.to_i}")
|
3
|
+
attr_reader :id, :title, :url, :image_url, :image_teaser_url, :width, :height, :created_at, :player,
|
4
|
+
:views_count, :likes_count, :comments_count, :rebounds_count
|
5
|
+
|
6
|
+
|
7
|
+
def initialize(attributes={})
|
8
|
+
attributes.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value)
|
15
10
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
11
|
+
@player = Dribble::Player.new(attributes[:player]) if attributes[:player]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
# By ID
|
17
|
+
#
|
18
|
+
# @param [Integer]
|
19
|
+
# @return [Object]
|
20
|
+
# @api public
|
21
|
+
#
|
22
|
+
def self.for(id)
|
23
|
+
new(Dribble::API::Shot.for(id))
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
##
|
28
|
+
# Following
|
29
|
+
#
|
30
|
+
# @param [String/Integer]
|
31
|
+
# @return [Object]
|
32
|
+
# @api public
|
33
|
+
#
|
34
|
+
def self.following(id, options={})
|
35
|
+
results = Dribble::API::Shot.following(id, options)
|
36
|
+
Dribble::Following.new(format_shots(results), results)
|
65
37
|
end
|
38
|
+
|
39
|
+
|
40
|
+
##
|
41
|
+
# Everyones
|
42
|
+
#
|
43
|
+
# @param [Hash]
|
44
|
+
# e.g. {:per_page => 30, :page => 1}
|
45
|
+
#
|
46
|
+
# @return [Object]
|
47
|
+
# @api public
|
48
|
+
#
|
49
|
+
def self.everyones(options={})
|
50
|
+
results = Dribble::API::Shot.everyones(options)
|
51
|
+
Dribble::Everyones.new(format_shots(results), results)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
##
|
56
|
+
# Debuts
|
57
|
+
#
|
58
|
+
# @param [Hash]
|
59
|
+
# e.g. {:per_page => 30, :page => 1}
|
60
|
+
#
|
61
|
+
# @return [Object]
|
62
|
+
# @api public
|
63
|
+
#
|
64
|
+
def self.debuts(options={})
|
65
|
+
results = Dribble::API::Shot.debuts(options)
|
66
|
+
Dribble::Debuts.new(format_shots(results), results)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
##
|
71
|
+
# Popular
|
72
|
+
#
|
73
|
+
# @param [Hash]
|
74
|
+
# e.g. {:per_page => 30, :page => 1}
|
75
|
+
#
|
76
|
+
# @return [Object]
|
77
|
+
# @api public
|
78
|
+
#
|
79
|
+
def self.popular(options={})
|
80
|
+
results = Dribble::API::Shot.popular(options)
|
81
|
+
Dribble::Popular.new(format_shots(results), results)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def self.format_shots(response, index = :shots)
|
88
|
+
response[index].map do |shot|
|
89
|
+
new(shot)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
66
93
|
end
|
67
94
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Dribble
|
2
|
+
class Shots
|
3
|
+
attr_reader :shots, :page, :pages, :per_page, :total
|
4
|
+
|
5
|
+
def initialize(shots, attributes={})
|
6
|
+
@shots = shots
|
7
|
+
@page = attributes[:page]
|
8
|
+
@pages = attributes[:pages]
|
9
|
+
@per_page = attributes[:per_page]
|
10
|
+
@total = attributes[:total]
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def next_page
|
15
|
+
api_endpoint = self.class.to_s.split('::').last.downcase.to_sym
|
16
|
+
options = {:page => self.page.to_i + 1}
|
17
|
+
raise Dribble::NoMorePagesAvailable.new('You are already on the last page.') if options[:page] > self.pages.to_i
|
18
|
+
Dribble::Shot.send(api_endpoint, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
module Dribble
|
26
|
+
class Popular < Shots
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Dribble
|
31
|
+
class Everyones < Shots
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Dribble
|
36
|
+
class Debuts < Shots
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Dribble
|
41
|
+
class Following < Shots
|
42
|
+
end
|
43
|
+
end
|
data/lib/dribble.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
2
|
|
3
|
-
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'yajl/gzip'
|
7
|
+
require 'yajl/deflate'
|
4
8
|
require 'yajl/http_stream'
|
5
|
-
require 'yajl'
|
6
9
|
|
7
10
|
base = File.expand_path(File.dirname(__FILE__))
|
8
11
|
|
@@ -12,9 +15,21 @@ Dir[File.join(File.join(base, 'core_ext'), '*.rb')].each { |file| require file }
|
|
12
15
|
require File.join(base, 'dribble/version')
|
13
16
|
|
14
17
|
module Dribble
|
15
|
-
autoload :Request,
|
18
|
+
autoload :Request, 'dribble/request'
|
19
|
+
autoload :NoMorePagesAvailable, 'dribble/exceptions'
|
20
|
+
|
21
|
+
# Custom Objects for easy usage of the Dribble API
|
22
|
+
autoload :Player, 'dribble/player'
|
23
|
+
autoload :Shot, 'dribble/shot'
|
24
|
+
autoload :Shots, 'dribble/shots'
|
25
|
+
autoload :Popular, 'dribble/shots'
|
26
|
+
autoload :Debut, 'dribble/shots'
|
27
|
+
autoload :Everyone, 'dribble/shots'
|
28
|
+
autoload :Following, 'dribble/shots'
|
16
29
|
|
17
|
-
#
|
18
|
-
|
19
|
-
|
30
|
+
# A slimmer API that converts JSON to a Hash. No Object creation overhead.
|
31
|
+
module API
|
32
|
+
autoload :Player, 'dribble/api/player'
|
33
|
+
autoload :Shot, 'dribble/api/shot'
|
34
|
+
end
|
20
35
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dribble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Robert R Evans
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-02 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -80,14 +80,21 @@ files:
|
|
80
80
|
- README.rdoc
|
81
81
|
- Rakefile
|
82
82
|
- VERSION
|
83
|
+
- dribble.gemspec
|
84
|
+
- examples/barebones/player.rb
|
85
|
+
- examples/barebones/shot.rb
|
83
86
|
- examples/player.rb
|
84
87
|
- examples/shot.rb
|
85
88
|
- lib/core_ext/hash.rb
|
86
89
|
- lib/core_ext/object.rb
|
87
90
|
- lib/dribble.rb
|
91
|
+
- lib/dribble/api/player.rb
|
92
|
+
- lib/dribble/api/shot.rb
|
93
|
+
- lib/dribble/exceptions.rb
|
88
94
|
- lib/dribble/player.rb
|
89
95
|
- lib/dribble/request.rb
|
90
96
|
- lib/dribble/shot.rb
|
97
|
+
- lib/dribble/shots.rb
|
91
98
|
- lib/dribble/version.rb
|
92
99
|
- spec/rcov.opts
|
93
100
|
- spec/spec.opts
|
@@ -128,5 +135,7 @@ specification_version: 3
|
|
128
135
|
summary: API Wrapper for the awesome Dribble Site
|
129
136
|
test_files:
|
130
137
|
- spec/spec_helper.rb
|
138
|
+
- examples/barebones/player.rb
|
139
|
+
- examples/barebones/shot.rb
|
131
140
|
- examples/player.rb
|
132
141
|
- examples/shot.rb
|