mlb 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/LICENSE.md +1 -1
- data/README.md +10 -7
- data/lib/mlb/player.rb +3 -3
- data/lib/mlb/request.rb +4 -4
- data/lib/mlb/response/parse_json.rb +25 -0
- data/lib/mlb/team.rb +13 -13
- data/lib/mlb/version.rb +1 -1
- data/mlb.gemspec +2 -4
- data/spec/mlb_spec.rb +4 -4
- metadata +28 -37
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -48,14 +48,17 @@ Then, install the gem with the high security trust policy:
|
|
48
48
|
This library aims to support and is [tested against][travis] the following Ruby
|
49
49
|
implementations:
|
50
50
|
|
51
|
+
* Ruby 1.8.7
|
51
52
|
* Ruby 1.9.2
|
52
53
|
* Ruby 1.9.3
|
54
|
+
* Ruby 2.0.0
|
53
55
|
* [Rubinius][]
|
56
|
+
* [JRuby][]
|
54
57
|
|
55
58
|
[rubinius]: http://rubini.us/
|
59
|
+
[jruby]: http://jruby.org/
|
56
60
|
|
57
|
-
If something doesn't work on one of these interpreters, it
|
58
|
-
a bug.
|
61
|
+
If something doesn't work on one of these interpreters, it's a bug.
|
59
62
|
|
60
63
|
This library may inadvertently work (or seem to work) on other Ruby
|
61
64
|
implementations, however support will only be provided for the versions listed
|
@@ -64,9 +67,9 @@ above.
|
|
64
67
|
If you would like this library to support another Ruby version, you may
|
65
68
|
volunteer to be a maintainer. Being a maintainer entails making sure all tests
|
66
69
|
run and pass on that implementation. When something breaks on your
|
67
|
-
implementation, you will be
|
68
|
-
|
69
|
-
|
70
|
+
implementation, you will be responsible for providing patches in a timely
|
71
|
+
fashion. If critical issues for a particular implementation exist at the time
|
72
|
+
of a major release, support for that Ruby version may be dropped.
|
70
73
|
|
71
74
|
## Colophon
|
72
75
|
MLB was built with the following tools:
|
@@ -96,6 +99,6 @@ MLB was built with the following tools:
|
|
96
99
|
[yard]: http://yardoc.org/
|
97
100
|
|
98
101
|
## Copyright
|
99
|
-
Copyright (c) 2010 Erik Michaels-Ober. See [LICENSE][] for details.
|
102
|
+
Copyright (c) 2010-2013 Erik Michaels-Ober. See [LICENSE][] for details.
|
100
103
|
|
101
|
-
[license]:
|
104
|
+
[license]: LICENSE.md
|
data/lib/mlb/player.rb
CHANGED
@@ -15,9 +15,9 @@ module MLB
|
|
15
15
|
def self.all_from_roster(players)
|
16
16
|
players.map do |player|
|
17
17
|
new(
|
18
|
-
name
|
19
|
-
number
|
20
|
-
position
|
18
|
+
:name => player['player'],
|
19
|
+
:number => player['number'],
|
20
|
+
:position => player['position']
|
21
21
|
)
|
22
22
|
end
|
23
23
|
end
|
data/lib/mlb/request.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'mlb/response/parse_json'
|
3
3
|
|
4
4
|
module MLB
|
5
5
|
# @private
|
@@ -15,9 +15,9 @@ module MLB
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def self.connection(raw=false)
|
18
|
-
Faraday.new(url
|
19
|
-
|
20
|
-
|
18
|
+
Faraday.new(:url => 'http://api.freebase.com') do |builder|
|
19
|
+
builder.use MLB::Response::ParseJson unless raw
|
20
|
+
builder.adapter Faraday.default_adapter
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module MLB
|
5
|
+
module Response
|
6
|
+
class ParseJson < Faraday::Response::Middleware
|
7
|
+
|
8
|
+
def parse(body)
|
9
|
+
case body
|
10
|
+
when /\A^\s*$\z/, nil
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
MultiJson.decode(body)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_complete(env)
|
18
|
+
if respond_to?(:parse)
|
19
|
+
env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/mlb/team.rb
CHANGED
@@ -45,12 +45,12 @@ module MLB
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.results_from_freebase(raw=false)
|
48
|
-
options = {query
|
48
|
+
options = {:query => mql_query}
|
49
49
|
Request.get('/api/service/mqlread', options, raw)
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.results_from_cache
|
53
|
-
MultiJson.
|
53
|
+
MultiJson.decode(file_from_cache("teams.json").read)
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.file_from_cache(file_name)
|
@@ -72,17 +72,17 @@ module MLB
|
|
72
72
|
players = result['current_roster']
|
73
73
|
|
74
74
|
teams << new(
|
75
|
-
name
|
76
|
-
league
|
77
|
-
division
|
78
|
-
manager
|
79
|
-
wins
|
80
|
-
losses
|
81
|
-
founded
|
82
|
-
mascot
|
83
|
-
ballpark
|
84
|
-
logo_url
|
85
|
-
players
|
75
|
+
:name => result['name'],
|
76
|
+
:league => (league ? league['name'] : nil),
|
77
|
+
:division => (division ? division['name'] : nil),
|
78
|
+
:manager => (manager ? manager['name'] : nil),
|
79
|
+
:wins => (stats ? stats['wins'].to_i : nil),
|
80
|
+
:losses => (stats ? stats['losses'].to_i : nil),
|
81
|
+
:founded => (founded ? founded['value'].to_i : nil),
|
82
|
+
:mascot => (mascot ? mascot['name'] : nil),
|
83
|
+
:ballpark => (ballpark ? ballpark['name'] : nil),
|
84
|
+
:logo_url => (logo_suffix ? logo_prefix + logo_suffix['id'] : nil),
|
85
|
+
:players => (players ? Player.all_from_roster(players) : [])
|
86
86
|
)
|
87
87
|
end
|
88
88
|
teams
|
data/lib/mlb/version.rb
CHANGED
data/mlb.gemspec
CHANGED
@@ -4,9 +4,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'mlb/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.add_dependency 'faraday', '~> 0.8'
|
8
|
-
spec.add_dependency '
|
9
|
-
spec.add_dependency 'multi_json', '~> 1.3'
|
7
|
+
spec.add_dependency 'faraday', ['~> 0.8', '< 0.10']
|
8
|
+
spec.add_dependency 'multi_json', '~> 1.0'
|
10
9
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
11
10
|
spec.author = "Erik Michaels-Ober"
|
12
11
|
spec.cert_chain = ['certs/sferik.pem']
|
@@ -20,7 +19,6 @@ Gem::Specification.new do |spec|
|
|
20
19
|
spec.name = 'mlb'
|
21
20
|
spec.require_paths = ['lib']
|
22
21
|
spec.required_rubygems_version = '>= 1.3.6'
|
23
|
-
spec.required_ruby_version = '>= 1.9.2'
|
24
22
|
spec.signing_key = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
|
25
23
|
spec.summary = spec.description
|
26
24
|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/spec/mlb_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
describe MLB::Team, ".all" do
|
4
4
|
context "with connection" do
|
5
5
|
before do
|
6
|
-
stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(query
|
6
|
+
stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query}).to_return(:body => fixture("teams.json"))
|
7
7
|
end
|
8
8
|
|
9
9
|
after do
|
@@ -12,7 +12,7 @@ describe MLB::Team, ".all" do
|
|
12
12
|
|
13
13
|
it "requests the correct resource" do
|
14
14
|
MLB::Team.all
|
15
|
-
expect(a_request(:get, 'http://api.freebase.com/api/service/mqlread').with(query
|
15
|
+
expect(a_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query})).to have_been_made
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns the correct results" do
|
@@ -23,7 +23,7 @@ describe MLB::Team, ".all" do
|
|
23
23
|
|
24
24
|
context "with timeout" do
|
25
25
|
before do
|
26
|
-
stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(query
|
26
|
+
stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query}).to_timeout
|
27
27
|
end
|
28
28
|
|
29
29
|
after do
|
@@ -38,7 +38,7 @@ describe MLB::Team, ".all" do
|
|
38
38
|
|
39
39
|
context "without connection" do
|
40
40
|
before do
|
41
|
-
stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(query
|
41
|
+
stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query}).to_raise(SocketError)
|
42
42
|
end
|
43
43
|
|
44
44
|
after do
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mlb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.6.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Erik Michaels-Ober
|
@@ -36,72 +36,62 @@ cert_chain:
|
|
36
36
|
U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
|
37
37
|
cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
|
38
38
|
cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
39
|
-
date: 2013-02-
|
39
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
prerelease: false
|
43
|
-
version_requirements: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.8'
|
48
|
-
none: false
|
49
|
-
type: :runtime
|
50
42
|
name: faraday
|
51
43
|
requirement: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
52
45
|
requirements:
|
53
46
|
- - ~>
|
54
47
|
- !ruby/object:Gem::Version
|
55
48
|
version: '0.8'
|
56
|
-
|
57
|
-
- !ruby/object:Gem::
|
49
|
+
- - <
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0.10'
|
52
|
+
type: :runtime
|
58
53
|
prerelease: false
|
59
54
|
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - ~>
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '0.8'
|
64
55
|
none: false
|
65
|
-
type: :runtime
|
66
|
-
name: faraday_middleware
|
67
|
-
requirement: !ruby/object:Gem::Requirement
|
68
56
|
requirements:
|
69
57
|
- - ~>
|
70
58
|
- !ruby/object:Gem::Version
|
71
59
|
version: '0.8'
|
72
|
-
|
73
|
-
- !ruby/object:Gem::Dependency
|
74
|
-
prerelease: false
|
75
|
-
version_requirements: !ruby/object:Gem::Requirement
|
76
|
-
requirements:
|
77
|
-
- - ~>
|
60
|
+
- - <
|
78
61
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
80
|
-
|
81
|
-
type: :runtime
|
62
|
+
version: '0.10'
|
63
|
+
- !ruby/object:Gem::Dependency
|
82
64
|
name: multi_json
|
83
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
84
67
|
requirements:
|
85
68
|
- - ~>
|
86
69
|
- !ruby/object:Gem::Version
|
87
|
-
version: '1.
|
88
|
-
|
89
|
-
- !ruby/object:Gem::Dependency
|
70
|
+
version: '1.0'
|
71
|
+
type: :runtime
|
90
72
|
prerelease: false
|
91
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
92
75
|
requirements:
|
93
76
|
- - ~>
|
94
77
|
- !ruby/object:Gem::Version
|
95
78
|
version: '1.0'
|
96
|
-
|
97
|
-
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
98
80
|
name: bundler
|
99
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
100
83
|
requirements:
|
101
84
|
- - ~>
|
102
85
|
- !ruby/object:Gem::Version
|
103
86
|
version: '1.0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
90
|
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '1.0'
|
105
95
|
description: MLB.rb is a Ruby library for retrieving current Major League Baseball
|
106
96
|
players, managers, teams, divisions, and leagues.
|
107
97
|
email: sferik@gmail.com
|
@@ -117,6 +107,7 @@ files:
|
|
117
107
|
- mlb.gemspec
|
118
108
|
- lib/mlb/player.rb
|
119
109
|
- lib/mlb/request.rb
|
110
|
+
- lib/mlb/response/parse_json.rb
|
120
111
|
- lib/mlb/team.rb
|
121
112
|
- lib/mlb/version.rb
|
122
113
|
- lib/mlb.rb
|
@@ -130,20 +121,20 @@ rdoc_options: []
|
|
130
121
|
require_paths:
|
131
122
|
- lib
|
132
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
133
125
|
requirements:
|
134
126
|
- - ! '>='
|
135
127
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
137
|
-
none: false
|
128
|
+
version: '0'
|
138
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
139
131
|
requirements:
|
140
132
|
- - ! '>='
|
141
133
|
- !ruby/object:Gem::Version
|
142
134
|
version: 1.3.6
|
143
|
-
none: false
|
144
135
|
requirements: []
|
145
136
|
rubyforge_project:
|
146
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.23
|
147
138
|
signing_key:
|
148
139
|
specification_version: 3
|
149
140
|
summary: MLB.rb is a Ruby library for retrieving current Major League Baseball players,
|
metadata.gz.sig
CHANGED
Binary file
|