dribble 0.0.31 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.31
1
+ 0.1.0
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.0.31"
8
+ s.version = "0.1.0"
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-05}
12
+ s.date = %q{2010-08-09}
13
13
  s.description = %q{API Wrapper for the awesome Dribble Site}
14
14
  s.email = %q{robert@codewranglers.org}
15
15
  s.extra_rdoc_files = [
@@ -35,13 +35,17 @@ Gem::Specification.new do |s|
35
35
  "lib/dribble/api/shot.rb",
36
36
  "lib/dribble/exceptions.rb",
37
37
  "lib/dribble/player.rb",
38
+ "lib/dribble/players.rb",
38
39
  "lib/dribble/request.rb",
39
40
  "lib/dribble/shot.rb",
40
41
  "lib/dribble/shots.rb",
41
42
  "lib/dribble/version.rb",
43
+ "spec/dribble/core_ext/hash_spec.rb",
44
+ "spec/dribble/core_ext/object_spec.rb",
42
45
  "spec/rcov.opts",
43
46
  "spec/spec.opts",
44
- "spec/spec_helper.rb"
47
+ "spec/spec_helper.rb",
48
+ "spec/support/fakeweb_yajl.rb"
45
49
  ]
46
50
  s.homepage = %q{http://github.com/revans/dribble}
47
51
  s.rdoc_options = ["--charset=UTF-8"]
@@ -49,7 +53,10 @@ Gem::Specification.new do |s|
49
53
  s.rubygems_version = %q{1.3.7}
50
54
  s.summary = %q{API Wrapper for the awesome Dribble Site}
51
55
  s.test_files = [
52
- "spec/spec_helper.rb",
56
+ "spec/dribble/core_ext/hash_spec.rb",
57
+ "spec/dribble/core_ext/object_spec.rb",
58
+ "spec/spec_helper.rb",
59
+ "spec/support/fakeweb_yajl.rb",
53
60
  "examples/barebones/player.rb",
54
61
  "examples/barebones/shot.rb",
55
62
  "examples/player.rb",
@@ -4,11 +4,23 @@ require File.join(dir, 'dribble')
4
4
  # puts "Find Player's Shots by name"
5
5
  # puts Dribble::API::Player.find('simplebits').inspect
6
6
 
7
- puts
8
- puts "Find Player's Profile"
9
- player = Dribble::API::Player.profile('simplebits')
10
- puts player
7
+ # puts
8
+ # puts "Find Player's Profile"
9
+ # player = Dribble::API::Player.profile('simplebits')
10
+ # puts player
11
11
 
12
12
  # puts
13
13
  # puts "Find all the shots a player is following"
14
- # puts Dribble::API::Player.following_shots('simplebits').inspect
14
+ # puts Dribble::API::Player.following_shots('simplebits').inspect
15
+
16
+
17
+ puts
18
+ puts "Find Player's Followers"
19
+ player = Dribble::API::Player.followers('simplebits')
20
+ puts player.inspect
21
+
22
+
23
+ puts
24
+ puts "Find Player's Draftees"
25
+ player = Dribble::API::Player.draftees('simplebits')
26
+ puts player.inspect
data/examples/player.rb CHANGED
@@ -18,16 +18,44 @@ require File.join(dir, 'dribble')
18
18
  # puts player3.inspect
19
19
 
20
20
 
21
+ puts
22
+ puts "Find a players followers"
23
+ player4 = Dribble::Player.followers('simplebits')
24
+ puts player4.inspect
25
+
21
26
 
22
27
  puts
23
- puts "Get a Player's Profile"
24
- player = Dribble::Player.find(1)
25
- puts player.inspect
28
+ puts "Find a players draftees"
29
+ player5 = Dribble::Player.draftees('simplebits')
30
+ puts player5.inspect
31
+
32
+
33
+
34
+
35
+
36
+
37
+ # puts
38
+ # puts "Get a Player's Profile"
39
+ # player = Dribble::Player.find(1)
40
+ # puts player.inspect
41
+
26
42
  # puts
27
43
  # puts "Take this player and see what shots they are following"
28
44
  # following_shots = player.following
29
45
  # puts following_shots.inspect
46
+
30
47
  # puts
31
48
  # puts "Take this player and see what shots they've put up"
32
49
  # my_shots = player.shots
50
+ # puts my_shots.inspect
51
+
52
+
53
+ # puts
54
+ # puts "Take this player and see their followers"
55
+ # my_shots = player.followers
56
+ # puts my_shots.inspect
57
+
58
+ # puts
59
+ # puts "Take this player and see their draftees"
60
+ # my_shots = player.draftees
33
61
  # puts my_shots.inspect
data/lib/dribble.rb CHANGED
@@ -20,12 +20,15 @@ module Dribble
20
20
 
21
21
  # Custom Objects for easy usage of the Dribble API
22
22
  autoload :Player, 'dribble/player'
23
+ autoload :Players, 'dribble/players'
23
24
  autoload :Shot, 'dribble/shot'
24
25
  autoload :Shots, 'dribble/shots'
25
26
  autoload :Popular, 'dribble/shots'
26
27
  autoload :Debut, 'dribble/shots'
27
28
  autoload :Everyone, 'dribble/shots'
28
29
  autoload :Following, 'dribble/shots'
30
+ autoload :Followers, 'dribble/players'
31
+ autoload :Draftees, 'dribble/players'
29
32
 
30
33
  # A slimmer API that converts JSON to a Hash. No Object creation overhead.
31
34
  module API
@@ -37,6 +37,31 @@ module Dribble
37
37
  def self.profile(id)
38
38
  Dribble::Request.get("/players/#{id}")
39
39
  end
40
+
41
+
42
+ ##
43
+ # Followers
44
+ #
45
+ # @param [String/Integer]
46
+ # @return [Hash]
47
+ # @api public
48
+ #
49
+ def self.followers(id, options={})
50
+ Dribble::Request.get("/players/#{id}/followers", setup_options(options))
51
+ end
52
+
53
+
54
+
55
+ ##
56
+ # Followers
57
+ #
58
+ # @param [String/Integer]
59
+ # @return [Hash]
60
+ # @api public
61
+ #
62
+ def self.draftees(id, options={})
63
+ Dribble::Request.get("/players/#{id}/draftees", setup_options(options))
64
+ end
40
65
 
41
66
 
42
67
  private
@@ -36,6 +36,30 @@ module Dribble
36
36
  end
37
37
 
38
38
 
39
+ ##
40
+ # Player's Shots
41
+ #
42
+ # @param [Hash]
43
+ # @return [Array]
44
+ # @api public
45
+ #
46
+ def draftees(options={})
47
+ @draftees ||= Dribble::API::Player.draftees(self.id, options)
48
+ end
49
+
50
+
51
+ ##
52
+ # Player's Shots
53
+ #
54
+ # @param [Hash]
55
+ # @return [Array]
56
+ # @api public
57
+ #
58
+ def followers(options={})
59
+ @followers ||= Dribble::API::Player.followers(self.id, options)
60
+ end
61
+
62
+
39
63
  class << self
40
64
 
41
65
 
@@ -64,6 +88,32 @@ module Dribble
64
88
  Dribble::Shots.new(format_shots(results), results)
65
89
  end
66
90
 
91
+
92
+ ##
93
+ # Followers
94
+ #
95
+ # @param [String/Integer]
96
+ # @return [Object]
97
+ # @api public
98
+ #
99
+ def followers(id, options={})
100
+ results = Dribble::API::Player.followers(id, options)
101
+ Dribble::Players.new(format_players(results), results)
102
+ end
103
+
104
+
105
+ ##
106
+ # Draftees
107
+ #
108
+ # @param [String/Integer]
109
+ # @return [Object]
110
+ # @api public
111
+ #
112
+ def draftees(id, options={})
113
+ results = Dribble::API::Player.draftees(id, options)
114
+ Dribble::Players.new(format_players(results), results)
115
+ end
116
+
67
117
 
68
118
  ##
69
119
  # Profile
@@ -93,6 +143,20 @@ module Dribble
93
143
  Dribble::Shot.new(shot)
94
144
  end
95
145
  end
146
+
147
+
148
+ ##
149
+ # Format Player
150
+ #
151
+ # @param [Array, Symbold]
152
+ # @return [Object]
153
+ # @api private
154
+ #
155
+ def format_players(response, index = :players)
156
+ response[index].map do |player|
157
+ Dribble::Player.new(player)
158
+ end
159
+ end
96
160
  end
97
161
 
98
162
  end
@@ -0,0 +1,33 @@
1
+ module Dribble
2
+ class Players
3
+ attr_reader :players, :page, :pages, :per_page, :total
4
+
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]
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::Player.send(api_endpoint, options)
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+
25
+ module Dribble
26
+ class Followers < Players
27
+ end
28
+ end
29
+
30
+ module Dribble
31
+ class Draftees < Players
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe "Hash Extensions" do
4
+
5
+ describe "Generic extensions" do
6
+ it "should return true if it is blank" do
7
+ {}.blank?.should == true
8
+ end
9
+
10
+ it "should return false if not blank" do
11
+ {:name => 'simplebits'}.blank?.should == false
12
+ end
13
+ end
14
+
15
+
16
+ describe "Symbolizing Keys" do
17
+ before(:all) do
18
+ @stringified_keys = {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
19
+ @recursive = {'name' => 'Hilton', 'address' => {'street' => '1200 Ave.', 'postal' => '92011', 'directions' => {'from' => 'here', 'to' => 'there', 'dive_in' => {'name' => 'something'}}}}
20
+ end
21
+
22
+ it "should create a new hash, keeping the old" do
23
+ a = @stringified_keys.symbolize_keys
24
+ a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
25
+ @stringified_keys.should == {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
26
+ end
27
+
28
+ it "should overwrite the existing hash making the keys symbols" do
29
+ a = @stringified_keys.symbolize_keys!
30
+ a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
31
+ @stringified_keys.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
32
+ end
33
+
34
+ it "should overwrite and recursively make all keys symbols" do
35
+ a = @recursive.recursive_symbolize_keys!
36
+ a.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
37
+ @recursive.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
38
+ end
39
+ end
40
+
41
+
42
+ describe "To Query" do
43
+ before(:all) do
44
+ @query_hash = {:name => 'simplebits', :page => 1}
45
+ end
46
+
47
+ it "should create a standard query string" do
48
+ @query_hash.to_query.should == 'name=simplebits&page=1'
49
+ end
50
+
51
+ it "should create an encoded query string with a namespace" do
52
+ @query_hash.to_query('dribble').should == 'dribble%5Bname%5D=simplebits&dribble%5Bpage%5D=1'
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe "Object Extensions" do
4
+
5
+ before(:all) do
6
+ @namespace = 'dribble'
7
+ @key = 'name'
8
+ @value = 'simplebits'
9
+ end
10
+
11
+ it "should create a key value like: name=simplebits" do
12
+ @value.to_query(@key).should == 'name=simplebits'
13
+ end
14
+
15
+ it "should send back a key value string with namespace like: dribble[name]=simplebits, but encoded" do
16
+ @value.to_query("#{@namespace}[#{@key}]").should == 'dribble%5Bname%5D=simplebits'
17
+ end
18
+
19
+ end
@@ -0,0 +1,17 @@
1
+ module Yajl
2
+ class HttpStream
3
+ class << self
4
+
5
+ def fake_get(uri, opts={}, &block)
6
+ yajl = ::Yajl::Parser.new(:symbolize_keys => true)
7
+ case uri.to_s
8
+ when condition
9
+ else
10
+ raise HttpError.new("TEST: Unknown uri: #{uri.to_s}")
11
+ end
12
+ end
13
+ alias_method :get, :fake_get
14
+
15
+ end
16
+ end
17
+ 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: 33
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 31
10
- version: 0.0.31
10
+ version: 0.1.0
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-05 00:00:00 -07:00
18
+ date: 2010-08-09 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -94,13 +94,17 @@ files:
94
94
  - lib/dribble/api/shot.rb
95
95
  - lib/dribble/exceptions.rb
96
96
  - lib/dribble/player.rb
97
+ - lib/dribble/players.rb
97
98
  - lib/dribble/request.rb
98
99
  - lib/dribble/shot.rb
99
100
  - lib/dribble/shots.rb
100
101
  - lib/dribble/version.rb
102
+ - spec/dribble/core_ext/hash_spec.rb
103
+ - spec/dribble/core_ext/object_spec.rb
101
104
  - spec/rcov.opts
102
105
  - spec/spec.opts
103
106
  - spec/spec_helper.rb
107
+ - spec/support/fakeweb_yajl.rb
104
108
  has_rdoc: true
105
109
  homepage: http://github.com/revans/dribble
106
110
  licenses: []
@@ -136,7 +140,10 @@ signing_key:
136
140
  specification_version: 3
137
141
  summary: API Wrapper for the awesome Dribble Site
138
142
  test_files:
143
+ - spec/dribble/core_ext/hash_spec.rb
144
+ - spec/dribble/core_ext/object_spec.rb
139
145
  - spec/spec_helper.rb
146
+ - spec/support/fakeweb_yajl.rb
140
147
  - examples/barebones/player.rb
141
148
  - examples/barebones/shot.rb
142
149
  - examples/player.rb