dribble 0.1.1 → 0.1.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/dribble.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dribble}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert R Evans"]
12
- s.date = %q{2010-08-13}
12
+ s.date = %q{2010-08-15}
13
13
  s.description = %q{API Wrapper for the awesome Dribbble Site}
14
14
  s.email = %q{robert@codewranglers.org}
15
15
  s.extra_rdoc_files = [
data/examples/player.rb CHANGED
@@ -1,61 +1,72 @@
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
- # player = Dribble::Player.find_shots('simplebits')
6
- # puts player.inspect
7
- #
8
- #
4
+ puts "Find Player's Shots by name"
5
+ player = Dribble::Player.find_shots('simplebits')
6
+ puts player.inspect
7
+
8
+
9
9
  puts
10
10
  puts "Find Player's Profile"
11
11
  player2 = Dribble::Player.profile('simplebits') # OR Dribble::Player.find('simplebits')
12
12
  puts player2.inspect
13
13
 
14
14
 
15
- # puts
16
- # puts "Find the shots that a specific Player is following"
17
- # player3 = Dribble::Player.following_shots('simplebits')
18
- # puts player3.inspect
15
+ puts
16
+ puts "Find the shots that a specific Player is following"
17
+ player3 = Dribble::Player.following_shots('simplebits')
18
+ puts player3.inspect
19
19
 
20
- #
21
- # puts
22
- # puts "Find a players followers"
23
- # player4 = Dribble::Player.followers('simplebits')
24
- # puts player4.inspect
25
- #
26
- #
27
- # puts
28
- # puts "Find a players draftees"
29
- # player5 = Dribble::Player.draftees('simplebits')
30
- # puts player5.inspect
31
20
 
21
+ puts
22
+ puts "Find a players followers"
23
+ player4 = Dribble::Player.followers('simplebits')
24
+ puts player4.inspect
32
25
 
26
+ puts
27
+ puts "Find a players draftees"
28
+ player5 = Dribble::Player.draftees('simplebits')
29
+ puts player5.inspect
33
30
 
34
31
 
32
+ puts
33
+ puts "Page 2 of draftees"
34
+ p2 = player5.next_page
35
+ puts p2.inspect
35
36
 
37
+ puts
38
+ puts "Page 4 of draftees"
39
+ p4 = player5.paginate(:page => 4)
40
+ puts p4.inspect
36
41
 
37
- # puts
38
- # puts "Get a Player's Profile"
39
- # player = Dribble::Player.find(1)
40
- # puts player.inspect
42
+ puts
43
+ puts "Page 3 of draftees"
44
+ p5 = p4.prev_page
45
+ puts p5.inspect
41
46
 
42
- # puts
43
- # puts "Take this player and see what shots they are following"
44
- # following_shots = player.following
45
- # puts following_shots.inspect
46
47
 
47
- # puts
48
- # puts "Take this player and see what shots they've put up"
49
- # my_shots = player.shots
50
- # puts my_shots.inspect
48
+ puts
49
+ puts "Get a Player's Profile"
50
+ player = Dribble::Player.find(1)
51
+ puts player.inspect
52
+
53
+ puts
54
+ puts "Take this player and see what shots they are following"
55
+ following_shots = player.following
56
+ puts following_shots.inspect
51
57
 
58
+ puts
59
+ puts "Take this player and see what shots they've put up"
60
+ my_shots = player.shots
61
+ puts my_shots.inspect
52
62
 
53
- # puts
54
- # puts "Take this player and see their followers"
55
- # my_shots = player.followers
56
- # puts my_shots.inspect
57
63
 
58
- # puts
59
- # puts "Take this player and see their draftees"
60
- # my_shots = player.draftees
61
- # puts my_shots.inspect
64
+ puts
65
+ puts "Take this player and see their followers"
66
+ my_shots = player.followers
67
+ puts my_shots.inspect
68
+
69
+ puts
70
+ puts "Take this player and see their draftees"
71
+ my_shots = player.draftees
72
+ puts my_shots.inspect
data/examples/shot.rb CHANGED
@@ -4,7 +4,7 @@ require File.join(dir, 'dribble')
4
4
  # puts "Find a specific shot by ID"
5
5
  # shot = Dribble::Shot.for(1)
6
6
  # puts shot.inspect
7
- #
7
+ #
8
8
  # puts
9
9
  # puts "Everyone's shots"
10
10
  # puts Dribble::Shot.everyones.inspect
@@ -19,15 +19,39 @@ require File.join(dir, 'dribble')
19
19
  # puts "Popular shots"
20
20
  # popular = Dribble::Shot.popular
21
21
  # puts popular.inspect
22
+
23
+
22
24
  # puts
25
+ # puts "Page 2 of popular shots"
23
26
  # popular_page_2 = popular.next_page
24
27
  # puts popular_page_2.inspect
25
28
 
26
29
 
30
+ # puts
31
+ # puts "Page 3 of popular shots"
32
+ # popular_page_3 = popular.next_page
33
+ # puts popular_page_3.inspect
34
+
35
+
36
+
37
+ # puts
38
+ # puts "Page 2 of popular shots"
39
+ # popular_page_2 = popular_page_3.prev_page
40
+ # puts popular_page_2.inspect
41
+
42
+
43
+ # puts
44
+ # puts "Page 10 of popular shots"
45
+ # popular_page_10 = popular.paginate(:page => 10)
46
+ # puts popular_page_10.inspect
47
+
48
+
27
49
  # puts
28
50
  # puts "Dan's Following these shots"
29
51
  # following = Dribble::Shot.following(1)
30
52
  # puts following.inspect
53
+
54
+
31
55
  # puts
32
56
  # following_page_2 = following.next_page
33
57
  # puts following_page_2.inspect
@@ -2,7 +2,8 @@ module Dribble
2
2
  class Player
3
3
  attr_reader :id, :name, :url, :avatar_url, :location, :created_at, :draftees_count,
4
4
  :following_count, :shots_count, :followers_count, :following, :shots,
5
- :drafted_by_player_id, :draftees_count
5
+ :drafted_by_player_id, :draftees_count, :players, :page, :pages, :per_page,
6
+ :total
6
7
 
7
8
 
8
9
  def initialize(attr={})
@@ -13,13 +14,13 @@ module Dribble
13
14
 
14
15
 
15
16
  ##
16
- # Following
17
+ # Following shots
17
18
  #
18
19
  # @param [Hash]
19
20
  # @return [Array]
20
21
  # @api public
21
22
  #
22
- def following(options={})
23
+ def following_shots(options={})
23
24
  @following ||= Dribble::API::Shot.following(self.id, options)
24
25
  end
25
26
 
@@ -72,7 +73,7 @@ module Dribble
72
73
  #
73
74
  def find_shots(id, options={})
74
75
  results = Dribble::API::Player.find_shots(id, options)
75
- Dribble::Shots.new(format_shots(results), results)
76
+ Dribble::Shots.new(format_shots(results), results.merge(:player_name => id))
76
77
  end
77
78
 
78
79
 
@@ -85,7 +86,7 @@ module Dribble
85
86
  #
86
87
  def following_shots(id, options={})
87
88
  results = Dribble::API::Player.following_shots(id, options)
88
- Dribble::Shots.new(format_shots(results), results)
89
+ Dribble::Following.new(format_shots(results), results.merge(:player_name => id))
89
90
  end
90
91
 
91
92
 
@@ -97,8 +98,9 @@ module Dribble
97
98
  # @api public
98
99
  #
99
100
  def followers(id, options={})
101
+ puts "ID: #{id} OPTIONS: #{options.inspect}"
100
102
  results = Dribble::API::Player.followers(id, options)
101
- Dribble::Players.new(format_players(results), results)
103
+ Dribble::Followers.new(format_players(results), results.merge(:player_name => id))
102
104
  end
103
105
 
104
106
 
@@ -111,7 +113,7 @@ module Dribble
111
113
  #
112
114
  def draftees(id, options={})
113
115
  results = Dribble::API::Player.draftees(id, options)
114
- Dribble::Players.new(format_players(results), results)
116
+ Dribble::Draftees.new(format_players(results), results.merge(:player_name => id))
115
117
  end
116
118
 
117
119
 
@@ -1,23 +1,67 @@
1
1
  module Dribble
2
2
  class Players
3
- attr_reader :players, :page, :pages, :per_page, :total
3
+ attr_reader :players, :page, :pages, :per_page, :total, :api_endpoint, :player_name
4
4
 
5
5
  def initialize(players, attributes={})
6
- @players = players
7
- @page = attributes[:page]
8
- @pages = attributes[:pages]
9
- @per_page = attributes[:per_page]
10
- @total = attributes[:total]
6
+ @players = players
7
+ @page = attributes[:page]
8
+ @pages = attributes[:pages]
9
+ @per_page = attributes[:per_page]
10
+ @total = attributes[:total]
11
+ @player_name = attributes[:player_name]
12
+ @api_endpoint = self.class.to_s.split('::').last.downcase.to_sym
11
13
  end
12
14
 
13
15
 
16
+ ##
17
+ # Previous Page
18
+ #
19
+ # @return [Object]
20
+ # @api public
21
+ #
22
+ def prev_page
23
+ options = {:page => self.page.to_i - 1}
24
+ raise Dribble::NoMorePagesAvailable.new('You are already on the first page.') if options[:page] <= 0
25
+ send_request(options)
26
+ end
27
+
28
+
29
+ ##
30
+ # Next Page
31
+ #
32
+ # @return [Object]
33
+ # @api public
34
+ #
14
35
  def next_page
15
- api_endpoint = self.class.to_s.split('::').last.downcase.to_sym
16
36
  options = {:page => self.page.to_i + 1}
17
37
  raise Dribble::NoMorePagesAvailable.new('You are already on the last page.') if options[:page] > self.pages.to_i
18
- Dribble::Player.send(api_endpoint, options)
38
+ send_request(options)
19
39
  end
20
40
 
41
+
42
+ ##
43
+ # Paginate
44
+ #
45
+ # @param [Hash] {:page => 3, :per_page => 15}
46
+ # @return [Object]
47
+ # @api public
48
+ #
49
+ def paginate(options)
50
+ raise Dribble::NoMorePagesAvailable.new('You are already on the last page.') if options[:page] > self.pages.to_i
51
+ send_request(options)
52
+ end
53
+
54
+
55
+ private
56
+
57
+ def send_request(options)
58
+ if self.player_name
59
+ Dribble::Player.send(@api_endpoint, self.player_name, options)
60
+ else
61
+ Dribble::Player.send(@api_endpoint, options)
62
+ end
63
+ end
64
+
21
65
  end
22
66
  end
23
67
 
data/lib/dribble/shot.rb CHANGED
@@ -33,7 +33,7 @@ module Dribble
33
33
  #
34
34
  def self.following(id, options={})
35
35
  results = Dribble::API::Shot.following(id, options)
36
- Dribble::Following.new(format_shots(results), results)
36
+ Dribble::Following.new(format_shots(results), results.merge(:player_name => id))
37
37
  end
38
38
 
39
39
 
data/lib/dribble/shots.rb CHANGED
@@ -1,27 +1,69 @@
1
1
  module Dribble
2
2
  class Shots
3
- attr_reader :shots, :page, :pages, :per_page, :total
3
+ attr_reader :shots, :page, :pages, :per_page, :total, :api_endpoint, :player_name
4
4
 
5
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]
6
+ @shots = shots
7
+ @page = attributes[:page]
8
+ @pages = attributes[:pages]
9
+ @per_page = attributes[:per_page]
10
+ @total = attributes[:total]
11
+ @player_name = attributes[:player_name] || nil
12
+ @api_endpoint = self.class.to_s.split('::').last.downcase.to_sym
11
13
  end
12
14
 
13
15
 
16
+ ##
17
+ # Previous Page
18
+ #
19
+ # @return [Object]
20
+ # @api public
21
+ #
22
+ def prev_page
23
+ options = {:page => self.page.to_i - 1}
24
+ raise Dribble::NoMorePagesAvailable.new('You are already on the first page.') if options[:page] <= 0
25
+ send_request(options)
26
+ end
27
+
28
+
29
+ ##
30
+ # Next Page
31
+ #
32
+ # @return [Object]
33
+ # @api public
34
+ #
14
35
  def next_page
15
- api_endpoint = self.class.to_s.split('::').last.downcase.to_sym
16
36
  options = {:page => self.page.to_i + 1}
17
37
  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)
38
+ send_request(options)
19
39
  end
20
40
 
41
+
42
+ ##
43
+ # Paginate
44
+ #
45
+ # @param [Hash] {:page => 3, :per_page => 15}
46
+ # @return [Object]
47
+ # @api public
48
+ #
49
+ def paginate(options)
50
+ raise Dribble::NoMorePagesAvailable.new('You are already on the last page.') if options[:page] > self.pages.to_i
51
+ send_request(options)
52
+ end
53
+
54
+ private
55
+
56
+ def send_request(options)
57
+ if self.player_name
58
+ Dribble::Shot.send(@api_endpoint, self.player_name, options)
59
+ else
60
+ Dribble::Shot.send(@api_endpoint, options)
61
+ end
62
+ end
63
+
21
64
  end
22
65
  end
23
66
 
24
-
25
67
  module Dribble
26
68
  class Popular < Shots
27
69
  end
data/lib/dribble.rb CHANGED
@@ -19,15 +19,19 @@ module Dribble
19
19
 
20
20
  # Custom Objects for easy usage of the Dribble API
21
21
  autoload :Player, 'dribble/player'
22
+
22
23
  autoload :Players, 'dribble/players'
24
+ autoload :Followers, 'dribble/players'
25
+ autoload :Draftees, 'dribble/players'
26
+
23
27
  autoload :Shot, 'dribble/shot'
28
+
24
29
  autoload :Shots, 'dribble/shots'
25
30
  autoload :Popular, 'dribble/shots'
26
31
  autoload :Debut, 'dribble/shots'
27
- autoload :Everyone, 'dribble/shots'
32
+ autoload :Everyones, 'dribble/shots'
28
33
  autoload :Following, 'dribble/shots'
29
- autoload :Followers, 'dribble/players'
30
- autoload :Draftees, 'dribble/players'
34
+
31
35
 
32
36
  # A slimmer API that converts JSON to a Hash. No Object creation overhead.
33
37
  module API
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.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-08-13 00:00:00 -07:00
18
+ date: 2010-08-15 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency