mlb 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,14 +1,8 @@
1
1
  *.gem
2
- *~
3
- .#*
4
2
  .DS_Store
5
- .hg/*
6
- .hgignore
7
- .svn/*
8
- TAGS
9
- TODO
3
+ .bundle
4
+ .yardoc
10
5
  coverage/*
11
6
  doc/*
7
+ log/*
12
8
  pkg/*
13
- src/*
14
- tmp/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.mkd
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem "httparty", "~> 0.6"
4
- gem "json", "~> 1.4"
5
- gem "sqlite3-ruby", "~> 1.3", :require => 'sqlite3'
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,16 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mlb (0.3.0)
5
+ faraday (~> 0.5.2)
6
+ sqlite3-ruby (~> 1.3.2)
7
+ yajl-ruby (~> 0.7.8)
8
+
1
9
  GEM
2
10
  remote: http://rubygems.org/
3
11
  specs:
12
+ ZenTest (4.4.0)
13
+ addressable (2.2.2)
4
14
  crack (0.1.8)
5
- httparty (0.6.1)
6
- crack (= 0.1.8)
7
- json (1.4.6)
8
- sqlite3-ruby (1.3.1)
15
+ diff-lcs (1.1.2)
16
+ faraday (0.5.2)
17
+ addressable (~> 2.2.2)
18
+ multipart-post (~> 1.0.1)
19
+ rack (>= 1.1.0, < 2)
20
+ multipart-post (1.0.1)
21
+ rack (1.2.1)
22
+ rake (0.8.7)
23
+ rcov (0.9.9)
24
+ rspec (2.0.1)
25
+ rspec-core (~> 2.0.1)
26
+ rspec-expectations (~> 2.0.1)
27
+ rspec-mocks (~> 2.0.1)
28
+ rspec-core (2.0.1)
29
+ rspec-expectations (2.0.1)
30
+ diff-lcs (>= 1.1.2)
31
+ rspec-mocks (2.0.1)
32
+ rspec-core (~> 2.0.1)
33
+ rspec-expectations (~> 2.0.1)
34
+ sqlite3-ruby (1.3.2)
35
+ webmock (1.5.0)
36
+ addressable (>= 2.2.2)
37
+ crack (>= 0.1.7)
38
+ yajl-ruby (0.7.8)
39
+ yard (0.6.1)
9
40
 
10
41
  PLATFORMS
11
42
  ruby
12
43
 
13
44
  DEPENDENCIES
14
- httparty (~> 0.6)
15
- json (~> 1.4)
16
- sqlite3-ruby (~> 1.3)
45
+ ZenTest (~> 4.4)
46
+ bundler (~> 1.0)
47
+ faraday (~> 0.5.2)
48
+ mlb!
49
+ rake (~> 0.8)
50
+ rcov (~> 0.9)
51
+ rspec (~> 2.0)
52
+ sqlite3-ruby (~> 1.3.2)
53
+ webmock (~> 1.5)
54
+ yajl-ruby (~> 0.7.8)
55
+ yard (~> 0.6)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Erik Michaels-Ober
1
+ Copyright (c) 2010 Erik Michaels-Ober
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.mkd ADDED
@@ -0,0 +1,84 @@
1
+ MLB.rb
2
+ ======
3
+ MLB.rb is a Ruby library for retrieving current Major League Baseball players, managers, teams, divisions, and leagues.
4
+
5
+ Installation
6
+ ------------
7
+ $ [sudo] gem install mlb
8
+
9
+ Documentation
10
+ -------------
11
+ <http://rdoc.info/gems/mlb>
12
+
13
+ Usage Examples
14
+ -----
15
+ $ irb
16
+ >> require 'mlb'
17
+ >> MLB::Team.all.first.name # => "Arizona Diamondbacks"
18
+ >> MLB::Team.all.first.league # => "National League"
19
+ >> MLB::Team.all.first.division # => "National League West"
20
+ >> MLB::Team.all.first.manager # => "Bob Melvin"
21
+ >> MLB::Team.all.first.wins # => 82
22
+ >> MLB::Team.all.first.losses # => 80
23
+ >> MLB::Team.all.first.founded # => 1998
24
+ >> MLB::Team.all.first.mascot # => nil
25
+ >> MLB::Team.all.first.ballpark # => "Chase Field"
26
+ >> MLB::Team.all.first.logo_url # => "http://img.freebase.com/api/trans/image_thumb/wikipedia/images/en_id/13104064"
27
+ >> MLB::Team.all.first.players.first.name # => "Alex Romero"
28
+ >> MLB::Team.all.first.players.first.number # => 28
29
+ >> MLB::Team.all.first.players.first.position # => "Right fielder"
30
+
31
+ Contributing
32
+ ------------
33
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
34
+
35
+ Here are some ways *you* can contribute:
36
+
37
+ * by using alpha, beta, and prerelease versions
38
+ * by reporting bugs
39
+ * by suggesting new features
40
+ * by writing or editing documentation
41
+ * by writing specifications
42
+ * by writing code (**no patch is too small**: fix typos, add comments, cleanup inconsistent whitespace)
43
+ * by refactoring code
44
+ * by closing [issues](http://github.com/sferik/mlb/issues)
45
+ * by reviewing patches
46
+ * financially
47
+
48
+ All contributors will be added to the credits and will receive the respect and gratitude of the community.
49
+
50
+ Submitting an Issue
51
+ -------------------
52
+ We use the [GitHub issue tracker](http://github.com/sferik/mlb/issues) to track bugs and
53
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
54
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
55
+ bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
56
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
57
+ operating system. Ideally, a bug report should include a pull request with failing specs.
58
+
59
+ Submitting a Pull Request
60
+ -------------------------
61
+ 1. Fork the project.
62
+ 2. Create a topic branch.
63
+ 3. Implement your feature or bug fix.
64
+ 4. Add documentation for your feature or bug fix.
65
+ 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
66
+ 6. Add specs for your feature or bug fix.
67
+ 7. Run <tt>bundle exec rake spec:rcov</tt>. If your changes are not 100% covered, go back to step 6.
68
+ 8. Commit and push your changes.
69
+ 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
70
+
71
+ Credits
72
+ -------
73
+ Many thanks to:
74
+
75
+ * [Bundler](http://gembundler.com/)
76
+ * [Freebase](http://www.freebase.com/)
77
+ * [faraday](https://github.com/technoweenie/faraday/)
78
+ * [Markdown](http://daringfireball.net/projects/markdown/)
79
+ * [MultiJSON](https://github.com/intridea/multi_json/)
80
+ * [rcov](https://github.com/relevance/rcov/)
81
+ * [RSpec](http://relishapp.com/rspec/)
82
+ * [SQLite](http://www.sqlite.org/)
83
+ * [WebMock](https://github.com/bblimke/webmock/)
84
+ * [YARD](http://yardoc.org/)
data/Rakefile CHANGED
@@ -1,15 +1,30 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/rdoctask'
4
1
  require 'bundler'
5
-
6
2
  Bundler::GemHelper.install_tasks
7
3
 
8
- Rake::RDocTask.new do |rd|
9
- rd.main = 'README.rdoc'
10
- rd.rdoc_dir = 'doc'
11
- rd.rdoc_files.include('README.rdoc', 'LICENSE', 'lib/**/*.rb')
12
- rd.title = 'MLB.rb'
13
- rd.options << '--inline-source'
14
- rd.options << '--all'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ namespace :spec do
8
+ desc "Run all examples using rcov"
9
+ RSpec::Core::RakeTask.new(:rcov => :cleanup_rcov_files) do |task|
10
+ task.rcov = true
11
+ task.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features,specs" --text-report --sort coverage]
12
+ end
13
+ end
14
+
15
+ task :cleanup_rcov_files do
16
+ rm_rf 'coverage'
17
+ end
18
+
19
+ task :default => ["spec:rcov"]
20
+
21
+ namespace :doc do
22
+ require 'yard'
23
+ YARD::Rake::YardocTask.new do |task|
24
+ task.files = ['LICENSE.mkd', 'lib/**/*.rb']
25
+ task.options = [
26
+ '--output-dir', 'doc/yard',
27
+ '--markup', 'markdown',
28
+ ]
29
+ end
15
30
  end
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
data/db/mlb.sqlite3 CHANGED
Binary file
data/lib/mlb.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module MLB
2
- autoload :Team, 'mlb/team'
3
- autoload :Player, 'mlb/player'
2
+ autoload :Connection, 'mlb/connection'
3
+ autoload :Request, 'mlb/request'
4
+ autoload :Team, 'mlb/team'
5
+ autoload :Player, 'mlb/player'
4
6
  end
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+
3
+ module MLB
4
+ # @private
5
+ class Request
6
+ # Perform an HTTP GET request
7
+ def self.get(path, options={})
8
+ response = connection.get do |request|
9
+ request.url(path, options)
10
+ end
11
+ response.body
12
+ end
13
+
14
+ private
15
+
16
+ def self.connection
17
+ Faraday::Connection.new(:url => 'http://api.freebase.com') do |connection|
18
+ connection.use Faraday::Response::Yajl
19
+ connection.adapter Faraday.default_adapter
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/mlb/team.rb CHANGED
@@ -1,15 +1,10 @@
1
- require 'httparty'
2
- require 'json'
3
-
4
1
  module MLB
5
2
  class Team
6
- include HTTParty
7
- format :json
8
- base_uri 'http://www.freebase.com/api'
9
3
  attr_accessor :name, :league, :division, :manager, :wins, :losses, :founded, :mascot, :ballpark, :logo_url, :players
10
4
 
11
5
  # Returns an array of Team objects
12
6
  #
7
+ # @example
13
8
  # MLB::Team.all.first.name # => "Arizona Diamondbacks"
14
9
  # MLB::Team.all.first.league # => "National League"
15
10
  # MLB::Team.all.first.division # => "National League West"
@@ -35,9 +30,7 @@ module MLB
35
30
 
36
31
  private
37
32
 
38
- # Attempt to fetch the result from the Freebase API
39
- # unless there is a connection error, in which case
40
- # query a static SQLite3 database.
33
+ # Attempt to fetch the result from the Freebase API unless there is a connection error, in which case query a static SQLite3 database
41
34
  def self.run
42
35
  begin
43
36
  run_team_mql
@@ -47,9 +40,7 @@ module MLB
47
40
  end
48
41
 
49
42
  def self.run_team_mql
50
- query = team_mql_query
51
- results = get('/service/mqlread?', :query => {:query => query.to_json})
52
- raise(Exception, "#{results['status']} (Transaction: #{results['transaction_id']})") unless results['code'] == '/api/status/ok'
43
+ results = Request.get('/api/service/mqlread', :query => team_mql_query)
53
44
 
54
45
  teams = []
55
46
  results['result'].each do |result|
@@ -128,51 +119,49 @@ module MLB
128
119
 
129
120
  # Returns the MQL query for teams, as a Ruby hash
130
121
  def self.team_mql_query
131
- {
132
- :query => [
133
- {
134
- 'name' => nil,
135
- 'league' => {
136
- 'name' => nil,
137
- },
138
- 'division' => {
139
- 'name' => nil,
140
- },
141
- 'current_manager' => {
142
- 'name' => nil,
143
- },
144
- 'team_stats' => [{
145
- 'wins' => nil,
146
- 'losses' => nil,
147
- 'season' => nil,
148
- 'limit' => 1,
149
- 'sort' => '-season',
150
- }],
151
- 'current_roster' => [{
152
- 'player' => nil,
153
- 'position' => nil,
154
- 'number' => nil,
155
- 'sort' => 'player',
156
- }],
157
- '/sports/sports_team/founded' => [{
158
- 'value' => nil,
159
- }],
160
- '/sports/sports_team/team_mascot' => [{
161
- }],
162
- '/sports/sports_team/arena_stadium' => [{
163
- 'name' => nil,
164
- }],
165
- '/common/topic/image' => [{
166
- 'id' => nil,
167
- 'timestamp' => nil,
168
- 'sort' => '-timestamp',
169
- 'limit' => 1,
170
- }],
171
- 'sort' => 'name',
172
- 'type' => '/baseball/baseball_team',
173
- }
174
- ]
175
- }
122
+ query = <<-eos
123
+ [{
124
+ "name": null,
125
+ "league": {
126
+ "name": null
127
+ },
128
+ "division": {
129
+ "name": null
130
+ },
131
+ "current_manager": {
132
+ "name": null
133
+ },
134
+ "team_stats": [{
135
+ "wins": null,
136
+ "losses": null,
137
+ "season": null,
138
+ "limit": 1,
139
+ "sort": "-season"
140
+ }],
141
+ "current_roster": [{
142
+ "player": null,
143
+ "position": null,
144
+ "number": null,
145
+ "sort": "player"
146
+ }],
147
+ "/sports/sports_team/founded": [{
148
+ "value": null
149
+ }],
150
+ "/sports/sports_team/team_mascot": [{}],
151
+ "/sports/sports_team/arena_stadium": [{
152
+ "name": null
153
+ }],
154
+ "/common/topic/image": [{
155
+ "id": null,
156
+ "timestamp": null,
157
+ "sort": "-timestamp",
158
+ "limit": 1
159
+ }],
160
+ "sort": "name",
161
+ "type": "/baseball/baseball_team"
162
+ }]
163
+ eos
164
+ '{"query":' + query.gsub!("\n", '').gsub!(' ', '') + '}'
176
165
  end
177
166
 
178
167
  def self.team_sql_query
data/lib/mlb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MLB
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.0"
3
3
  end
data/mlb.gemspec CHANGED
@@ -2,19 +2,25 @@
2
2
  require File.expand_path("../lib/mlb/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.add_runtime_dependency(%q<httparty>, ["~> 0.6"])
6
- s.add_runtime_dependency(%q<json>, ["~> 1.4"])
7
- s.add_runtime_dependency(%q<sqlite3-ruby>, ["~> 1.3"])
5
+ s.add_development_dependency("bundler", "~> 1.0")
6
+ s.add_development_dependency("rake", "~> 0.8")
7
+ s.add_development_dependency("rcov", "~> 0.9")
8
+ s.add_development_dependency("rspec", "~> 2.0")
9
+ s.add_development_dependency("webmock", "~> 1.5")
10
+ s.add_development_dependency("yard", "~> 0.6")
11
+ s.add_development_dependency("ZenTest", "~> 4.4")
12
+ s.add_runtime_dependency("faraday", "~> 0.5.2")
13
+ s.add_runtime_dependency("yajl-ruby", "~> 0.7.8")
14
+ s.add_runtime_dependency("sqlite3-ruby", "~> 1.3.2")
8
15
  s.authors = ["Erik Michaels-Ober"]
9
16
  s.description = %q{MLB.rb is a Ruby library for retrieving current Major League Baseball players, managers, teams, divisions, and leagues.}
10
17
  s.email = ["sferik@gmail.com"]
11
- s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
12
18
  s.files = `git ls-files`.split("\n")
13
19
  s.homepage = "http://rubygems.org/gems/mlb"
14
20
  s.name = "mlb"
15
21
  s.rdoc_options = ["--charset=UTF-8"]
16
22
  s.require_paths = ["lib"]
17
- s.required_rubygems_version = ">= 1.3.6"
23
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
18
24
  s.summary = %q{MLB.rb is a Ruby library for retrieving current Major League Baseball players, managers, teams, divisions, and leagues.}
19
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
26
  s.version = MLB::VERSION