dribble 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,16 +4,17 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.name = "dribble"
8
- gem.summary = %Q{API Wrapper for the awesome Dribbble Site}
7
+ gem.name = "dribble"
8
+ gem.summary = %Q{API Wrapper for the awesome Dribbble Site}
9
9
  gem.description = %Q{API Wrapper for the awesome Dribbble Site}
10
- gem.email = "robert@codewranglers.org"
11
- gem.homepage = "http://github.com/revans/dribble"
12
- gem.authors = ["Robert R Evans"]
13
-
10
+ gem.email = "robert@codewranglers.org"
11
+ gem.homepage = "http://github.com/revans/dribble"
12
+ gem.authors = ["Robert R Evans"]
13
+
14
14
  gem.add_development_dependency "rspec", '= 1.3.0'
15
15
  gem.add_development_dependency "yard", '= 0.5.8'
16
16
 
17
+ gem.add_dependency 'yajl-ruby', '= 0.7.7'
17
18
  gem.add_dependency 'em-http-request', '= 0.2.10'
18
19
 
19
20
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dribble}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
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-15}
12
+ s.date = %q{2010-09-29}
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 = [
@@ -44,6 +44,8 @@ Gem::Specification.new do |s|
44
44
  "spec/core_ext/object_spec.rb",
45
45
  "spec/dribble/api/player_spec.rb",
46
46
  "spec/dribble/api/shot_spec.rb",
47
+ "spec/dribble/player_spec.rb",
48
+ "spec/dribble/request_spec.rb",
47
49
  "spec/dribble/version_spec.rb",
48
50
  "spec/fake_data/player/player_draftees.json",
49
51
  "spec/fake_data/player/player_find_shots.json",
@@ -68,6 +70,8 @@ Gem::Specification.new do |s|
68
70
  "spec/core_ext/object_spec.rb",
69
71
  "spec/dribble/api/player_spec.rb",
70
72
  "spec/dribble/api/shot_spec.rb",
73
+ "spec/dribble/player_spec.rb",
74
+ "spec/dribble/request_spec.rb",
71
75
  "spec/dribble/version_spec.rb",
72
76
  "spec/spec_helper.rb",
73
77
  "spec/support/fake_eventmachine_requests.rb",
@@ -84,15 +88,18 @@ Gem::Specification.new do |s|
84
88
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
85
89
  s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
86
90
  s.add_development_dependency(%q<yard>, ["= 0.5.8"])
91
+ s.add_runtime_dependency(%q<yajl-ruby>, ["= 0.7.7"])
87
92
  s.add_runtime_dependency(%q<em-http-request>, ["= 0.2.10"])
88
93
  else
89
94
  s.add_dependency(%q<rspec>, ["= 1.3.0"])
90
95
  s.add_dependency(%q<yard>, ["= 0.5.8"])
96
+ s.add_dependency(%q<yajl-ruby>, ["= 0.7.7"])
91
97
  s.add_dependency(%q<em-http-request>, ["= 0.2.10"])
92
98
  end
93
99
  else
94
100
  s.add_dependency(%q<rspec>, ["= 1.3.0"])
95
101
  s.add_dependency(%q<yard>, ["= 0.5.8"])
102
+ s.add_dependency(%q<yajl-ruby>, ["= 0.7.7"])
96
103
  s.add_dependency(%q<em-http-request>, ["= 0.2.10"])
97
104
  end
98
105
  end
@@ -1,76 +1,76 @@
1
1
  module Dribble
2
2
  module API
3
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
4
+ class << self
5
+
6
+ ##
7
+ # Find shots for a given player
8
+ #
9
+ # @param [String/Integer]
10
+ # @return [Hash]
11
+ # @api public
12
+ #
13
+ def find_shots(id, options={})
14
+ Dribble::Request.get("/players/#{id}/shots", setup_options(options))
15
+ end
16
16
 
17
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
18
+ ##
19
+ # Following Shots
20
+ #
21
+ # @param [String/Integer]
22
+ # @return [Hash]
23
+ # @api public
24
+ #
25
+ def following_shots(id, options={})
26
+ Dribble::Request.get("/players/#{id}/shots/following", setup_options(options))
27
+ end
28
28
 
29
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
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
40
 
41
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
42
+ ##
43
+ # Followers
44
+ #
45
+ # @param [String/Integer]
46
+ # @return [Hash]
47
+ # @api public
48
+ #
49
+ def followers(id, options={})
50
+ Dribble::Request.get("/players/#{id}/followers", setup_options(options))
51
+ end
52
52
 
53
53
 
54
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
55
+ ##
56
+ # Followers
57
+ #
58
+ # @param [String/Integer]
59
+ # @return [Hash]
60
+ # @api public
61
+ #
62
+ def draftees(id, options={})
63
+ Dribble::Request.get("/players/#{id}/draftees", setup_options(options))
64
+ end
65
65
 
66
66
 
67
- private
67
+ private
68
68
 
69
- def self.setup_options(options)
70
- {:per_page => 30, :page => 1}.merge(options)
71
- end
69
+ def setup_options(options)
70
+ {:per_page => 30, :page => 1}.merge(options)
71
+ end
72
72
 
73
-
73
+ end
74
74
  end
75
75
  end
76
76
  end
@@ -2,83 +2,85 @@ module Dribble
2
2
  module API
3
3
  class Shot
4
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
5
+ class << self
6
+
7
+ ##
8
+ # By ID
9
+ #
10
+ # @param [Integer]
11
+ # @return [Hash]
12
+ # @api public
13
+ #
14
+ def for(id)
15
+ Dribble::Request.get("/shots/#{id.to_i}")
16
+ end
16
17
 
17
18
 
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
19
+ ##
20
+ # Following
21
+ #
22
+ # @param [String/Integer, Hash]
23
+ # e.g. {:per_page => 30, :page => 1}
24
+ #
25
+ # @return [Hash]
26
+ # @api public
27
+ #
28
+ def following(id, options={})
29
+ Dribble::Request.get("/players/#{id}/shots/following", setup_options(options))
30
+ end
30
31
 
31
32
 
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
-
33
+ ##
34
+ # Everyones
35
+ #
36
+ # @param [Hash]
37
+ # e.g. {:per_page => 30, :page => 1}
38
+ #
39
+ # @return [Array]
40
+ # @api public
41
+ #
42
+ def everyones(options={})
43
+ Dribble::Request.get("/shots/everyone", setup_options(options))
44
+ end
45
+ alias_method :everyone, :everyones
46
+
45
47
 
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
48
+ ##
49
+ # Debuts
50
+ #
51
+ # @param [Hash]
52
+ # e.g. {:per_page => 30, :page => 1}
53
+ #
54
+ # @return [Array]
55
+ # @api public
56
+ #
57
+ def debuts(options={})
58
+ Dribble::Request.get("/shots/debuts", setup_options(options))
59
+ end
58
60
 
59
61
 
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
62
+ ##
63
+ # Popular
64
+ #
65
+ # @param [Hash]
66
+ # e.g. {:per_page => 30, :page => 1}
67
+ #
68
+ # @return [Array]
69
+ # @api public
70
+ #
71
+ def popular(options={})
72
+ Dribble::Request.get("/shots/popular", setup_options(options))
73
+ end
72
74
 
73
75
 
74
- private
76
+ private
75
77
 
76
78
 
77
- def self.setup_options(options)
78
- {:per_page => 30, :page => 1}.merge(options)
79
- end
80
-
81
-
79
+ def setup_options(options)
80
+ {:per_page => 30, :page => 1}.merge(options)
81
+ end
82
+
83
+ end
82
84
  end
83
85
  end
84
86
  end
@@ -1,9 +1,11 @@
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
- :drafted_by_player_id, :draftees_count, :players, :page, :pages, :per_page,
6
- :total
3
+ attr_reader :id, :name, :url, :avatar_url, :location, :twitter_screen_name,
4
+ :drafted_by_player_id, :shots_count, :draftees_count,
5
+ :followers_count, :following_count, :comments_count, :comments_received_count,
6
+ :likes_count, :likes_receive_count, :rebounds_count, :rebounds_received_count,
7
+ :created_at,
8
+ :following, :shots, :players, :page, :pages, :per_page, :total
7
9
 
8
10
 
9
11
  def initialize(attr={})
@@ -14,10 +14,10 @@ module Dribble
14
14
  def get(query, options={})
15
15
  meth = options.delete(:api_endpoint)
16
16
  ::EventMachine.run do
17
- http = ::EventMachine::HttpRequest.new("#{to_url}#{query}").get(:query => options, :timeout => 10)
17
+ http = ::EventMachine::HttpRequest.new("#{to_url(query)}").get(:query => options, :timeout => 10)
18
18
  http.callback do
19
19
  @response = {
20
- :status => http.response_header.status,
20
+ :status => http.response_header.status.to_i,
21
21
  :header => http.response_header,
22
22
  :body => http.response,
23
23
  :data => ::Yajl::Parser.new(:symbolize_keys => true).parse(http.response)
@@ -25,15 +25,16 @@ module Dribble
25
25
  ::EventMachine.stop
26
26
  end
27
27
  end
28
+
28
29
  @response[:data][:api_endpoint] = meth if meth
29
- @response[:data]
30
+ @response[:status] == 200 ? @response[:data] : @response[:data][:message]
30
31
  end
31
32
 
32
33
 
33
34
  private
34
35
 
35
- def to_url
36
- "http://#{DRIBBLE_API}"
36
+ def to_url(query)
37
+ "http://#{DRIBBLE_API}#{query}"
37
38
  end
38
39
 
39
40
  end
@@ -1,7 +1,8 @@
1
1
  module Dribble
2
2
  class Shot
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
3
+ attr_reader :id, :title, :url, :short_url, :image_url, :image_teaser_url, :width, :height,
4
+ :views_count, :likes_count, :comments_count, :rebounds_count, :created_at,
5
+ :player
5
6
 
6
7
 
7
8
  def initialize(attributes={})
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+
3
+ describe Dribble::Player do
4
+ describe "Successful player requests" do
5
+
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+
3
+ describe "The request api" do
4
+
5
+ describe "A successful request" do
6
+
7
+ before(:all) do
8
+ @success = Dribble::Request.get("/players/revans")
9
+ end
10
+
11
+ it "should make a successful get request" do
12
+ @success.should be_true
13
+ end
14
+
15
+ it "should be a hash" do
16
+ @success.class.should == Hash
17
+ end
18
+
19
+ end
20
+
21
+
22
+ describe "An unsuccessful request" do
23
+
24
+ before(:all) do
25
+ @failure = Dribble::Request.get("/players/simblebits238952352342342")
26
+ end
27
+
28
+ it "should make a successful get request" do
29
+ @failure.should == "Not found"
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -6,14 +6,6 @@ require 'spec/autorun'
6
6
 
7
7
  require 'rubygems'
8
8
 
9
- # require 'fakeweb'
10
- # require 'fakeweb_matcher'
11
-
12
- # Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |file| require file }
13
- # FakeWeb.allow_net_connect = false
14
-
15
-
16
- # require File.join(File.dirname(__FILE__), '../lib/dribble.rb')
17
9
 
18
10
  Spec::Runner.configure do |config|
19
11
 
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
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-15 00:00:00 -07:00
18
+ date: 2010-09-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,9 +51,25 @@ dependencies:
51
51
  type: :development
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: em-http-request
54
+ name: yajl-ruby
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - "="
60
+ - !ruby/object:Gem::Version
61
+ hash: 13
62
+ segments:
63
+ - 0
64
+ - 7
65
+ - 7
66
+ version: 0.7.7
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: em-http-request
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
57
73
  none: false
58
74
  requirements:
59
75
  - - "="
@@ -65,7 +81,7 @@ dependencies:
65
81
  - 10
66
82
  version: 0.2.10
67
83
  type: :runtime
68
- version_requirements: *id003
84
+ version_requirements: *id004
69
85
  description: API Wrapper for the awesome Dribbble Site
70
86
  email: robert@codewranglers.org
71
87
  executables: []
@@ -103,6 +119,8 @@ files:
103
119
  - spec/core_ext/object_spec.rb
104
120
  - spec/dribble/api/player_spec.rb
105
121
  - spec/dribble/api/shot_spec.rb
122
+ - spec/dribble/player_spec.rb
123
+ - spec/dribble/request_spec.rb
106
124
  - spec/dribble/version_spec.rb
107
125
  - spec/fake_data/player/player_draftees.json
108
126
  - spec/fake_data/player/player_find_shots.json
@@ -155,6 +173,8 @@ test_files:
155
173
  - spec/core_ext/object_spec.rb
156
174
  - spec/dribble/api/player_spec.rb
157
175
  - spec/dribble/api/shot_spec.rb
176
+ - spec/dribble/player_spec.rb
177
+ - spec/dribble/request_spec.rb
158
178
  - spec/dribble/version_spec.rb
159
179
  - spec/spec_helper.rb
160
180
  - spec/support/fake_eventmachine_requests.rb