bleacher_api 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ coverage
4
+ pkg
5
+ tmp
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) Bleacher Report 2010
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,344 @@
1
+ BleacherApi
2
+ ===========
3
+
4
+ A Ruby interface to the Bleacher Report API.
5
+
6
+ Requirements
7
+ ------------
8
+
9
+ <pre>
10
+ gem install bleacher_api
11
+ </pre>
12
+
13
+ Table of Contents
14
+ -----------------
15
+
16
+ * [GET /api/article/article.json](#article_article)
17
+ * [POST /api/authenticate/login.json](#authenticate_login)
18
+ * [GET /api/front/lead_articles.json](#front_lead_articles)
19
+ * [GET /api/geolocation/teams.json](#geolocation_teams)
20
+ * [GET /api/related/channel.json](#related_channel)
21
+ * [GET /api/related/channel_next.json](#related_channel_next)
22
+ * [GET /api/stream/first.json](#stream_first)
23
+ * [GET /api/user/user.json](#user_user)
24
+
25
+ <a name="article_article"></a>
26
+
27
+ GET /api/article/article.json
28
+ -----------------------------
29
+
30
+ ### Parameters
31
+
32
+ * id - Article ID (required)
33
+ * article - When given any value, action includes article body in JSON output
34
+ * article[entry_id] - Changes article body to a quick hit or live blog entry
35
+ * comments[page] - When given a page number, action includes comments in JSON output
36
+ * related_content - When given any value, action includes related content in JSON output
37
+
38
+ ### Returns
39
+
40
+ An object with any of the following keys: article, comments, related_content.
41
+
42
+ The article value is an object with the keys body and object.
43
+
44
+ ### Ruby Example
45
+
46
+ <pre>
47
+ BleacherApi::Article.article(595888, :article => true, :comments => { :page => 1 }, :related_content => true)
48
+ </pre>
49
+
50
+ ### HTTP Example
51
+
52
+ <pre>
53
+ http://bleacherreport.com/api/article/article.json?id=595888&article=1&comments[page]=1&related_content=1
54
+ </pre>
55
+
56
+ <a name="authenticate_login"></a>
57
+
58
+ POST /api/authenticate/login.json
59
+ ---------------------------------
60
+
61
+ ### Parameters
62
+
63
+ * user[email]
64
+ * user[password]
65
+
66
+ ### Returns
67
+
68
+ Output similar to the <a href="#user_user">User API</a>.
69
+
70
+ ### Ruby Example
71
+
72
+ <pre>
73
+ BleacherApi::Authenticate.login('email', 'password')
74
+ </pre>
75
+
76
+ ### HTTP Example
77
+
78
+ <pre>
79
+ http://bleacherreport.com/api/authenticate/login.json?user[email]=your@email.com&user[password]=your_password
80
+ </pre>
81
+
82
+ Please note that any request with a password should be sent as a POST, despite this example using GET.
83
+
84
+ <a name="front_lead_articles"></a>
85
+
86
+ GET /api/front/lead_articles.json
87
+ ---------------------------------
88
+
89
+ ### Parameters
90
+
91
+ * limit - Optional
92
+
93
+ ### Returns
94
+
95
+ An array of article objects with the following keys: permalink, primary\_image\_650x440, and title.
96
+
97
+ The array of articles represents the articles currently on the lead module of the front page.
98
+
99
+ ### Ruby Example
100
+
101
+ <pre>
102
+ BleacherApi::Front.lead_articles(:limit => 2)
103
+ </pre>
104
+
105
+ ### HTTP Example
106
+
107
+ <pre>
108
+ http://bleacherreport.com/api/front/lead_articles.json?limit=2
109
+ </pre>
110
+
111
+ <a name="geolocation_teams"></a>
112
+
113
+ GET /api/geolocation/teams.json
114
+ -------------------------------
115
+
116
+ ### Parameters
117
+
118
+ * city
119
+ * state
120
+ * country
121
+ * dma - Designated Market Area code
122
+ * ip - IP Address (defaults to IP of requesting machine, only used if city, state, country, and dma are empty)
123
+ * limit - Limit number of results (defaults to 5)
124
+
125
+ All parameters are optional.
126
+
127
+ ### Returns
128
+
129
+ A hash of team information, similar to the team information in the <a href="#user_user">User API</a>:
130
+
131
+ <pre>
132
+ {
133
+ "Dallas Mavericks": {
134
+ "uniqueName": "dallas-mavericks",
135
+ "logo": "dallas_mavericks.png",
136
+ "displayName": "Dallas Mavericks",
137
+ "shortName": "Mavericks"
138
+ },
139
+ "Dallas Cowboys": {
140
+ "uniqueName": "dallas-cowboys",
141
+ "logo": "dallas_cowboys.png",
142
+ "displayName": "Dallas Cowboys",
143
+ "shortName": "Cowboys"
144
+ }
145
+ }
146
+ </pre>
147
+
148
+ ### Ruby Examples
149
+
150
+ <pre>
151
+ BleacherApi::Geolocation.teams(
152
+ :city => 'Dallas',
153
+ :dma => 623,
154
+ :state => 'Texas',
155
+ :country => 'US',
156
+ :limit => 10
157
+ )
158
+ </pre>
159
+
160
+ <pre>
161
+ BleacherApi::Geolocation.teams(
162
+ :ip => '64.55.149.162'
163
+ )
164
+ </pre>
165
+
166
+ <pre>
167
+ BleacherApi::Geolocation.teams(
168
+ :lat => '37.787082',
169
+ :long => '-122.400929'
170
+ )
171
+ </pre>
172
+
173
+ ### HTTP Example
174
+
175
+ <pre>
176
+ http://bleacherreport.com/api/geolocation/teams.json?city=Dallas&dma=623&state=Texas&country=USA&limit=10
177
+ </pre>
178
+
179
+ <pre>
180
+ http://bleacherreport.com/api/geolocation/teams.json?ip=64.55.149.162
181
+ </pre>
182
+
183
+ <pre>
184
+ http://bleacherreport.com/api/geolocation/teams.json?lat=37.787082&long=-122.400929
185
+ </pre>
186
+
187
+ <a name="related_channel"></a>
188
+
189
+ GET /api/related/channel.json
190
+ -----------------------------
191
+
192
+ ### Parameters
193
+
194
+ * article\_id - Article ID, must be present if no tag\_id specified
195
+ * tag\_id - Tag ID, must be present if no article\_id specified
196
+ * page - Optional
197
+
198
+ ### Returns
199
+
200
+ An array of article objects with the following keys: permalink, channel\_primary\_image, and title.
201
+
202
+ ### Ruby Example
203
+
204
+ <pre>
205
+ BleacherApi::Related.channel(:article_id => 595888, :page => 2)
206
+ </pre>
207
+
208
+ ### HTTP Example
209
+
210
+ <pre>
211
+ http://bleacherreport.com/api/related/channel.json?article_id=595888&page=2
212
+ </pre>
213
+
214
+ <a name="related_channel_next"></a>
215
+
216
+ GET /api/related/channel_next.json
217
+ ----------------------------------
218
+
219
+ ### Parameters
220
+
221
+ * article\_id - Article ID, must be present if no tag\_id specified
222
+ * tag\_id - Tag ID, must be present if no article\_id specified
223
+ * limit - Limit number of results, defaults to 1
224
+
225
+ ### Returns
226
+
227
+ An array of article objects with the following keys: permalink, channel\_primary\_image\_150x100, and dynamic_hook.
228
+
229
+ These article objects represent the next items in the channel (after the passed `article_id`).
230
+
231
+ ### Ruby Example
232
+
233
+ <pre>
234
+ BleacherApi::Related.channel_next(:article_id => 595888, :tag_id => 19, :limit => 2)
235
+ </pre>
236
+
237
+ ### HTTP Example
238
+
239
+ <pre>
240
+ http://bleacherreport.com/api/related/channel_next.json?article_id=696286&tag_id=19&limit=2
241
+ </pre>
242
+
243
+ <a name="stream_first"></a>
244
+
245
+ GET /api/stream/first.json
246
+ --------------------------
247
+
248
+ ### Parameters
249
+
250
+ * tags - comma-delimited list of tag permalinks
251
+
252
+ ### Returns
253
+
254
+ An object whose keys are the permalinks passed in via the <code>tags</code> parameter.
255
+
256
+ Each value of that object is another object with the following keys:
257
+
258
+ * title
259
+ * published_at
260
+ * image
261
+ * label
262
+
263
+ This object represents the first item in that team's stream.
264
+
265
+ ### Ruby Example
266
+
267
+ <pre>
268
+ BleacherApi::Stream.first('san-francisco-49ers')
269
+ </pre>
270
+
271
+ ### HTTP Example
272
+
273
+ <pre>
274
+ http://bleacherreport.com/api/stream/first.json?tags=san-francisco-49ers,dallas-cowboys
275
+ </pre>
276
+
277
+ <a name="user_user"></a>
278
+
279
+ GET /api/user/user.json
280
+ -----------------------
281
+
282
+ ### Parameters
283
+
284
+ * token - Token obtained from <code>/api/authenticate/login</code>
285
+
286
+ ### Returns
287
+
288
+ A user object with the following keys:
289
+
290
+ * id
291
+ * email
292
+ * first\_name
293
+ * last\_name
294
+ * permalink
295
+ * token
296
+ * api
297
+
298
+ The <code>api</code> value contains extra information especially for the API. Example output:
299
+
300
+ <pre>
301
+ {
302
+ "teams": {
303
+ "Dallas Mavericks": {
304
+ "uniqueName": "dallas-mavericks",
305
+ "logo": "dallas_mavericks.png",
306
+ "displayName": "Dallas Mavericks",
307
+ "shortName": "Mavericks"
308
+ },
309
+ "Dallas Cowboys": {
310
+ "uniqueName": "dallas-cowboys",
311
+ "logo": "dallas_cowboys.png",
312
+ "displayName": "Dallas Cowboys",
313
+ "shortName": "Cowboys"
314
+ }
315
+ }
316
+ }
317
+ </pre>
318
+
319
+ ### Ruby Example
320
+
321
+ <pre>
322
+ BleacherApi::User.user('token')
323
+ </pre>
324
+
325
+ ### HTTP Example
326
+
327
+ <pre>
328
+ http://bleacherreport.com/api/user/user.json?token=TOKEN_OBTAINED_FROM_LOGIN_GOES_HERE
329
+ </pre>
330
+
331
+ Running Specs
332
+ -------------
333
+
334
+ Here is an example of the options available when running the specs:
335
+
336
+ <pre>
337
+ LOGIN=user@user.com PASSWORD=password URL=http://localhost ONLY=geolocation spec spec
338
+ </pre>
339
+
340
+ <code>LOGIN</code> and <code>PASSWORD</code> are required.
341
+
342
+ <code>URL</code> defaults to "http://bleacherreport.com".
343
+
344
+ <code>ONLY</code> is optional, and allows you to only run a specific group of specs.
data/Rakefile ADDED
@@ -0,0 +1,94 @@
1
+ require File.dirname(__FILE__) + '/lib/bleacher_api/gems'
2
+
3
+ BleacherApi::Gems.activate %w(rake rspec)
4
+
5
+ require 'rake'
6
+
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue Exception => e
10
+ end
11
+
12
+ def gemspec
13
+ @gemspec ||= begin
14
+ file = File.expand_path('../bleacher_api.gemspec', __FILE__)
15
+ eval(File.read(file), binding, file)
16
+ end
17
+ end
18
+
19
+ if defined?(Spec::Rake::SpecTask)
20
+ desc "Run specs"
21
+ Spec::Rake::SpecTask.new do |t|
22
+ t.spec_files = FileList['spec/**/*_spec.rb']
23
+ t.spec_opts = %w(-fs --color)
24
+ t.warning = true
25
+ end
26
+ task :spec
27
+ task :default => :spec
28
+ end
29
+
30
+ desc "Build gem(s)"
31
+ task :gem do
32
+ old_gemset = ENV['GEMSET']
33
+ root = File.expand_path('../', __FILE__)
34
+ pkg = "#{root}/pkg"
35
+ system "rm -Rf #{pkg}"
36
+ BleacherApi::Gems.gemset_names.each do |gemset|
37
+ ENV['GEMSET'] = gemset.to_s
38
+ system "cd #{root} && gem build bleacher_api.gemspec"
39
+ system "mkdir -p #{pkg} && mv *.gem pkg"
40
+ end
41
+ ENV['GEMSET'] = old_gemset
42
+ end
43
+
44
+ namespace :gem do
45
+ desc "Install gem(s)"
46
+ task :install do
47
+ Rake::Task['gem'].invoke
48
+ Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
49
+ system "gem install #{pkg} --no-ri --no-rdoc"
50
+ end
51
+ end
52
+
53
+ desc "Push gem(s)"
54
+ task :push do
55
+ Rake::Task['gem'].invoke
56
+ Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
57
+ system "gem push #{pkg}"
58
+ end
59
+ end
60
+ end
61
+
62
+ namespace :gems do
63
+ desc "Install gem dependencies (DEV=0 DOCS=0 GEMSPEC=default SUDO=0)"
64
+ task :install do
65
+ dev = ENV['DEV'] == '1'
66
+ docs = ENV['DOCS'] == '1' ? '' : '--no-ri --no-rdoc'
67
+ gemset = ENV['GEMSET']
68
+ sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
69
+
70
+ BleacherApi::Gems.gemset = gemset if gemset
71
+
72
+ if dev
73
+ gems = BleacherApi::Gems.gemspec.development_dependencies
74
+ else
75
+ gems = BleacherApi::Gems.gemspec.dependencies
76
+ end
77
+
78
+ gems.each do |name|
79
+ name = name.to_s
80
+ version = BleacherApi::Gems.versions[name.to_sym]
81
+ if Gem.source_index.find_name(name, version).empty?
82
+ version = version ? "-v #{version}" : ''
83
+ system "#{sudo} gem install #{name} #{version} #{docs}"
84
+ else
85
+ puts "already installed: #{name} #{version}"
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ desc "Validate the gemspec"
92
+ task :gemspec do
93
+ gemspec.validate
94
+ end
data/bin/bleacher_api ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/bleacher_api")
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ root = File.expand_path('../', __FILE__)
3
+ lib = "#{root}/lib"
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require 'bleacher_api/gems'
7
+ BleacherApi::Gems.gemset ||= ENV['GEMSET'] || :default
8
+
9
+ Gem::Specification.new do |s|
10
+ BleacherApi::Gems.gemspec.hash.each do |key, value|
11
+ if key == 'name' && BleacherApi::Gems.gemset != :default
12
+ s.name = "#{value}-#{BleacherApi::Gems.gemset}"
13
+ elsif key == 'summary' && BleacherApi::Gems.gemset == :solo
14
+ s.summary = value + " (no dependencies)"
15
+ elsif !%w(dependencies development_dependencies).include?(key)
16
+ s.send "#{key}=", value
17
+ end
18
+ end
19
+
20
+ BleacherApi::Gems.dependencies.each do |g|
21
+ s.add_dependency g.to_s, BleacherApi::Gems.versions[g]
22
+ end
23
+
24
+ BleacherApi::Gems.development_dependencies.each do |g|
25
+ s.add_development_dependency g.to_s, BleacherApi::Gems.versions[g]
26
+ end
27
+
28
+ s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
29
+ s.files = `cd #{root} && git ls-files`.split("\n")
30
+ s.require_paths = %w(lib)
31
+ s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
32
+ end
@@ -0,0 +1,4 @@
1
+ bleacher_api:
2
+ httparty: =0.5.2
3
+ rake: >=0.8.7
4
+ rspec: ~>1.0
@@ -0,0 +1,13 @@
1
+ name: bleacher_api
2
+ version: 0.1.0
3
+ authors:
4
+ - Bleacher Report
5
+ email: wwelsh@bleacherreport.com
6
+ homepage: http://bleacherreport.com
7
+ summary: A Ruby Interface to the Bleacher Report API
8
+ description: A Ruby Interface to the Bleacher Report API
9
+ dependencies:
10
+ - httparty
11
+ development_dependencies:
12
+ - rake
13
+ - rspec
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/bleacher_api/gems'
2
+
3
+ BleacherApi::Gems.activate %w(httparty)
4
+
5
+ require 'httparty'
6
+
7
+ $:.unshift File.dirname(__FILE__)
8
+
9
+ require 'bleacher_api/config'
10
+
11
+ class BleacherApi
12
+ include HTTParty
13
+
14
+ class <<self
15
+ def call(type, path, data=nil)
16
+ base_uri BleacherApi::Config.url
17
+ data, old_data = {}, data
18
+ data[type == :get ? :query : :body] = old_data
19
+ output = send(type, "/api/#{path}.json", data)
20
+ if output.headers['status'].include?('200')
21
+ output
22
+ else
23
+ false
24
+ end
25
+ end
26
+ end
27
+
28
+ class Authenticate
29
+ class <<self
30
+ def login(email, password)
31
+ result = BleacherApi.call(:post, 'authenticate/login', {
32
+ 'user[email]' => email,
33
+ 'user[password]' => password
34
+ })
35
+ if result
36
+ BleacherApi::Config.token result['token']
37
+ end
38
+ result
39
+ end
40
+ end
41
+ end
42
+
43
+ class Front
44
+ class <<self
45
+ def lead_articles(options)
46
+ BleacherApi.call(:get, 'front/lead_articles', options)
47
+ end
48
+ end
49
+ end
50
+
51
+ class Geolocation
52
+ class <<self
53
+ def teams(options)
54
+ BleacherApi.call(:get, 'geolocation/teams', options)
55
+ end
56
+ end
57
+ end
58
+
59
+ class Related
60
+ class <<self
61
+ def channel(options)
62
+ BleacherApi.call(:get, 'related/channel', options)
63
+ end
64
+
65
+ def channel_next(options)
66
+ BleacherApi.call(:get, 'related/channel_next', options)
67
+ end
68
+ end
69
+ end
70
+
71
+ class Stream
72
+ class <<self
73
+ def first(*tags)
74
+ BleacherApi.call(:get, 'stream/first', {
75
+ :tags => tags.join(',')
76
+ })
77
+ end
78
+ end
79
+ end
80
+
81
+ class User
82
+ class <<self
83
+ def user(token=BleacherApi::Config.token)
84
+ BleacherApi.call(:get, 'user/user', {
85
+ :token => token
86
+ })
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,16 @@
1
+ class BleacherApi
2
+ module Config
3
+ class <<self
4
+
5
+ def url(url=nil)
6
+ @url = url unless url.nil?
7
+ @url || 'http://bleacherreport.com'
8
+ end
9
+
10
+ def token(token=nil)
11
+ @token = token unless token.nil?
12
+ @token
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,159 @@
1
+ unless defined?(BleacherApi::Gems)
2
+
3
+ require 'yaml'
4
+
5
+ class BleacherApi
6
+ module Gems
7
+ class <<self
8
+
9
+ attr_accessor :config
10
+ attr_reader :gemset, :gemsets, :versions
11
+
12
+ class SimpleStruct
13
+ attr_reader :hash
14
+
15
+ def initialize(hash)
16
+ @hash = hash
17
+ @hash.each do |key, value|
18
+ self.class.send(:define_method, key) { @hash[key] }
19
+ self.class.send(:define_method, "#{key}=") { |v| @hash[key] = v }
20
+ end
21
+ end
22
+ end
23
+
24
+ Gems.config = SimpleStruct.new(
25
+ :gemsets => [ "#{File.expand_path('../../../', __FILE__)}/config/gemsets.yml" ],
26
+ :gemspec => "#{File.expand_path('../../../', __FILE__)}/config/gemspec.yml",
27
+ :warn => true
28
+ )
29
+
30
+ def activate(*gems)
31
+ begin
32
+ require 'rubygems' unless defined?(::Gem)
33
+ rescue LoadError
34
+ puts "rubygems library could not be required" if @config.warn
35
+ end
36
+
37
+ self.gemset ||= gemset_from_loaded_specs
38
+
39
+ gems.flatten.collect { |g| g.to_sym }.each do |name|
40
+ version = @versions[name]
41
+ vendor = File.expand_path("../../../vendor/#{name}/lib", __FILE__)
42
+ warning = "#{name} #{"(#{version})" if version} failed to activate"
43
+ if File.exists?(vendor)
44
+ $:.unshift vendor
45
+ elsif defined?(gem)
46
+ begin
47
+ gem name.to_s, version
48
+ rescue Exception => e
49
+ puts warning if @config.warn
50
+ end
51
+ else
52
+ puts warning if @config.warn
53
+ end
54
+ end
55
+ end
56
+
57
+ def dependencies
58
+ dependency_filter(@gemspec.dependencies, @gemset)
59
+ end
60
+
61
+ def development_dependencies
62
+ dependency_filter(@gemspec.development_dependencies, @gemset)
63
+ end
64
+
65
+ def gemset=(gemset)
66
+ if gemset
67
+ @gemset = gemset.to_sym
68
+
69
+ @gemsets = @config.gemsets.reverse.collect { |config|
70
+ if config.is_a?(::String)
71
+ YAML::load(File.read(config)) rescue {}
72
+ elsif config.is_a?(::Hash)
73
+ config
74
+ end
75
+ }.inject({}) do |hash, config|
76
+ deep_merge(hash, symbolize_keys(config))
77
+ end
78
+
79
+ @versions = (@gemsets[gemspec.name.to_sym] || {}).inject({}) do |hash, (key, value)|
80
+ if !value.is_a?(::Hash) && value
81
+ hash[key] = value
82
+ elsif key == @gemset
83
+ (value || {}).each { |k, v| hash[k] = v }
84
+ end
85
+ hash
86
+ end
87
+ else
88
+ @gemset = nil
89
+ @gemsets = nil
90
+ @versions = nil
91
+ end
92
+ end
93
+
94
+ def gemset_names
95
+ (
96
+ [ :default ] +
97
+ @gemsets[gemspec.name.to_sym].inject([]) { |array, (key, value)|
98
+ array.push(key) if value.is_a?(::Hash) || value.nil?
99
+ array
100
+ }
101
+ ).uniq
102
+ end
103
+
104
+ def gemspec(reload=false)
105
+ if @gemspec && !reload
106
+ @gemspec
107
+ else
108
+ data = YAML::load(File.read(@config.gemspec)) rescue {}
109
+ @gemspec = SimpleStruct.new(data)
110
+ end
111
+ end
112
+
113
+ private
114
+
115
+ def deep_merge(first, second)
116
+ merger = lambda do |key, v1, v2|
117
+ Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
118
+ end
119
+ first.merge(second, &merger)
120
+ end
121
+
122
+ def dependency_filter(dependencies, match)
123
+ (dependencies || []).inject([]) { |array, value|
124
+ if value.is_a?(::Hash)
125
+ array += value[match.to_s] if value[match.to_s]
126
+ else
127
+ array << value
128
+ end
129
+ array
130
+ }.uniq.collect(&:to_sym)
131
+ end
132
+
133
+ def gemset_from_loaded_specs
134
+ if defined?(Gem)
135
+ Gem.loaded_specs.each do |name, spec|
136
+ if name == gemspec.name
137
+ return :default
138
+ elsif name[0..gemspec.name.length] == "#{gemspec.name}-"
139
+ return name[gemspec.name.length+1..-1].to_sym
140
+ end
141
+ end
142
+ :default
143
+ else
144
+ :none
145
+ end
146
+ end
147
+
148
+ def symbolize_keys(hash)
149
+ return {} unless hash.is_a?(::Hash)
150
+ hash.inject({}) do |options, (key, value)|
151
+ value = symbolize_keys(value) if value.is_a?(::Hash)
152
+ options[(key.to_sym rescue key) || key] = value
153
+ options
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,250 @@
1
+ require 'spec_helper'
2
+
3
+ describe BleacherApi::Gems do
4
+
5
+ before(:each) do
6
+ @old_config = BleacherApi::Gems.config
7
+
8
+ BleacherApi::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
9
+ BleacherApi::Gems.config.gemsets = [
10
+ "#{$root}/spec/fixtures/gemsets.yml"
11
+ ]
12
+ BleacherApi::Gems.config.warn = true
13
+
14
+ BleacherApi::Gems.gemspec true
15
+ BleacherApi::Gems.gemset = nil
16
+ end
17
+
18
+ after(:each) do
19
+ BleacherApi::Gems.config = @old_config
20
+ end
21
+
22
+ describe :activate do
23
+ it "should activate gems" do
24
+ BleacherApi::Gems.stub!(:gem)
25
+ BleacherApi::Gems.should_receive(:gem).with('rspec', '=1.3.1')
26
+ BleacherApi::Gems.should_receive(:gem).with('rake', '=0.8.7')
27
+ BleacherApi::Gems.activate :rspec, 'rake'
28
+ end
29
+ end
30
+
31
+ describe :gemset= do
32
+ before(:each) do
33
+ BleacherApi::Gems.config.gemsets = [
34
+ {
35
+ :name => {
36
+ :rake => '>0.8.6',
37
+ :default => {
38
+ :externals => '=1.0.2'
39
+ }
40
+ }
41
+ },
42
+ "#{$root}/spec/fixtures/gemsets.yml"
43
+ ]
44
+ end
45
+
46
+ describe :default do
47
+ before(:each) do
48
+ BleacherApi::Gems.gemset = :default
49
+ end
50
+
51
+ it "should set @gemset" do
52
+ BleacherApi::Gems.gemset.should == :default
53
+ end
54
+
55
+ it "should set @gemsets" do
56
+ BleacherApi::Gems.gemsets.should == {
57
+ :name => {
58
+ :rake => ">0.8.6",
59
+ :default => {
60
+ :externals => '=1.0.2',
61
+ :mysql => "=2.8.1",
62
+ :rspec => "=1.3.1"
63
+ },
64
+ :rspec2 => {
65
+ :mysql2 => "=0.2.6",
66
+ :rspec => "=2.3.0"
67
+ },
68
+ :solo => nil
69
+ }
70
+ }
71
+ end
72
+
73
+ it "should set Gems.versions" do
74
+ BleacherApi::Gems.versions.should == {
75
+ :externals => "=1.0.2",
76
+ :mysql => "=2.8.1",
77
+ :rake => ">0.8.6",
78
+ :rspec => "=1.3.1"
79
+ }
80
+ end
81
+
82
+ it "should return proper values for Gems.dependencies" do
83
+ BleacherApi::Gems.dependencies.should == [ :rake, :mysql ]
84
+ BleacherApi::Gems.development_dependencies.should == []
85
+ end
86
+
87
+ it "should return proper values for Gems.gemset_names" do
88
+ BleacherApi::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
89
+ end
90
+ end
91
+
92
+ describe :rspec2 do
93
+ before(:each) do
94
+ BleacherApi::Gems.gemset = "rspec2"
95
+ end
96
+
97
+ it "should set @gemset" do
98
+ BleacherApi::Gems.gemset.should == :rspec2
99
+ end
100
+
101
+ it "should set @gemsets" do
102
+ BleacherApi::Gems.gemsets.should == {
103
+ :name => {
104
+ :rake => ">0.8.6",
105
+ :default => {
106
+ :externals => '=1.0.2',
107
+ :mysql => "=2.8.1",
108
+ :rspec => "=1.3.1"
109
+ },
110
+ :rspec2 => {
111
+ :mysql2=>"=0.2.6",
112
+ :rspec => "=2.3.0"
113
+ },
114
+ :solo => nil
115
+ }
116
+ }
117
+ end
118
+
119
+ it "should set Gems.versions" do
120
+ BleacherApi::Gems.versions.should == {
121
+ :mysql2 => "=0.2.6",
122
+ :rake => ">0.8.6",
123
+ :rspec => "=2.3.0"
124
+ }
125
+ end
126
+
127
+ it "should return proper values for Gems.dependencies" do
128
+ BleacherApi::Gems.dependencies.should == [ :rake, :mysql2 ]
129
+ BleacherApi::Gems.development_dependencies.should == []
130
+ end
131
+
132
+ it "should return proper values for Gems.gemset_names" do
133
+ BleacherApi::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
134
+ end
135
+ end
136
+
137
+ describe :solo do
138
+ before(:each) do
139
+ BleacherApi::Gems.gemset = :solo
140
+ end
141
+
142
+ it "should set @gemset" do
143
+ BleacherApi::Gems.gemset.should == :solo
144
+ end
145
+
146
+ it "should set @gemsets" do
147
+ BleacherApi::Gems.gemsets.should == {
148
+ :name => {
149
+ :rake => ">0.8.6",
150
+ :default => {
151
+ :externals => '=1.0.2',
152
+ :mysql => "=2.8.1",
153
+ :rspec => "=1.3.1"
154
+ },
155
+ :rspec2 => {
156
+ :mysql2=>"=0.2.6",
157
+ :rspec => "=2.3.0"
158
+ },
159
+ :solo => nil
160
+ }
161
+ }
162
+ end
163
+
164
+ it "should set Gems.versions" do
165
+ BleacherApi::Gems.versions.should == {:rake=>">0.8.6"}
166
+ end
167
+
168
+ it "should return proper values for Gems.dependencies" do
169
+ BleacherApi::Gems.dependencies.should == [:rake]
170
+ BleacherApi::Gems.development_dependencies.should == []
171
+ end
172
+
173
+ it "should return proper values for Gems.gemset_names" do
174
+ BleacherApi::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
175
+ end
176
+ end
177
+
178
+ describe :nil do
179
+ before(:each) do
180
+ BleacherApi::Gems.gemset = nil
181
+ end
182
+
183
+ it "should set everything to nil" do
184
+ BleacherApi::Gems.gemset.should == nil
185
+ BleacherApi::Gems.gemsets.should == nil
186
+ BleacherApi::Gems.versions.should == nil
187
+ end
188
+ end
189
+ end
190
+
191
+ describe :gemset_from_loaded_specs do
192
+ before(:each) do
193
+ Gem.stub!(:loaded_specs)
194
+ end
195
+
196
+ it "should return the correct gemset for name gem" do
197
+ Gem.should_receive(:loaded_specs).and_return({ "name" => nil })
198
+ BleacherApi::Gems.send(:gemset_from_loaded_specs).should == :default
199
+ end
200
+
201
+ it "should return the correct gemset for name-rspec gem" do
202
+ Gem.should_receive(:loaded_specs).and_return({ "name-rspec2" => nil })
203
+ BleacherApi::Gems.send(:gemset_from_loaded_specs).should == :rspec2
204
+ end
205
+ end
206
+
207
+ describe :reload_gemspec do
208
+ it "should populate @gemspec" do
209
+ BleacherApi::Gems.gemspec.hash.should == {
210
+ "name" => "name",
211
+ "version" => "0.1.0",
212
+ "authors" => ["Author"],
213
+ "email" => "email@email.com",
214
+ "homepage" => "http://github.com/author/name",
215
+ "summary" => "Summary",
216
+ "description" => "Description",
217
+ "dependencies" => [
218
+ "rake",
219
+ { "default" => [ "mysql" ] },
220
+ { "rspec2" => [ "mysql2" ] }
221
+ ],
222
+ "development_dependencies" => nil
223
+ }
224
+ end
225
+
226
+ it "should create methods from keys of @gemspec" do
227
+ BleacherApi::Gems.gemspec.name.should == "name"
228
+ BleacherApi::Gems.gemspec.version.should == "0.1.0"
229
+ BleacherApi::Gems.gemspec.authors.should == ["Author"]
230
+ BleacherApi::Gems.gemspec.email.should == "email@email.com"
231
+ BleacherApi::Gems.gemspec.homepage.should == "http://github.com/author/name"
232
+ BleacherApi::Gems.gemspec.summary.should == "Summary"
233
+ BleacherApi::Gems.gemspec.description.should == "Description"
234
+ BleacherApi::Gems.gemspec.dependencies.should == [
235
+ "rake",
236
+ { "default" => ["mysql"] },
237
+ { "rspec2" => [ "mysql2" ] }
238
+ ]
239
+ BleacherApi::Gems.gemspec.development_dependencies.should == nil
240
+ end
241
+
242
+ it "should produce a valid gemspec" do
243
+ require 'rubygems/user_interaction'
244
+ BleacherApi::Gems.gemset = :default
245
+ gemspec = File.expand_path("../../../bleacher_api.gemspec", __FILE__)
246
+ gemspec = eval(File.read(gemspec), binding, gemspec)
247
+ gemspec.validate.should == true
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe BleacherApi do
4
+
5
+ before(:all) do
6
+ @user_keys = %w(id email first_name last_name permalink token api)
7
+ end
8
+
9
+ if only?(:Authenticate)
10
+ describe :Authenticate do
11
+ describe 'success' do
12
+ before(:all) do
13
+ @response = BleacherApi::Authenticate.login(ENV['LOGIN'], ENV['PASSWORD'])
14
+ end
15
+
16
+ it "should return a hash with valid keys" do
17
+ @response.keys.length.should == @user_keys.length
18
+ (@response.keys - @user_keys).should == []
19
+ end
20
+
21
+ it "should set Config.token" do
22
+ BleacherApi::Config.token.should == @response['token']
23
+ end
24
+ end
25
+
26
+ describe 'failure' do
27
+ before(:all) do
28
+ @response = BleacherApi::Authenticate.login('fail', 'fail')
29
+ end
30
+
31
+ it "should return false" do
32
+ @response.should == false
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ if only?(:Geolocation)
39
+ describe :Geolocation do
40
+
41
+ before(:all) do
42
+ @keys = [
43
+ "Dallas Mavericks",
44
+ "Texas Tech Football",
45
+ "Dallas Cowboys",
46
+ "Texas Rangers",
47
+ "TCU Football"
48
+ ]
49
+ @child_keys = [ "shortName", "displayName", "logo", "uniqueName" ]
50
+ end
51
+
52
+ describe :city do
53
+ before(:all) do
54
+ @response = BleacherApi::Geolocation.teams(:city => 'Dallas')
55
+ end
56
+
57
+ it "should return a hash with the proper keys" do
58
+ (@response.keys - @keys).should == []
59
+ end
60
+
61
+ it "should return a hash of hashes with the proper keys" do
62
+ @keys.each do |key|
63
+ (@response[key].keys - @child_keys).should == []
64
+ end
65
+ end
66
+ end
67
+
68
+ describe 'lat/long' do
69
+ before(:all) do
70
+ @response = BleacherApi::Geolocation.teams(:lat => "32.778155", :long => "-96.795404")
71
+ end
72
+
73
+ it "should return a hash with the proper keys" do
74
+ (@response.keys - @keys).should == []
75
+ end
76
+
77
+ it "should return a hash of hashes with the proper keys" do
78
+ @keys.each do |key|
79
+ (@response[key].keys - @child_keys).should == []
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ if only?(:Stream)
87
+ describe :Stream do
88
+ before(:all) do
89
+ @response = BleacherApi::Stream.first('san-francisco-49ers')
90
+ @keys = %w(label title published_at image)
91
+ end
92
+
93
+ it "should return hash with valid keys" do
94
+ @response.keys.should == [ 'san-francisco-49ers' ]
95
+ @response['san-francisco-49ers'].keys.should == @keys
96
+ end
97
+ end
98
+ end
99
+
100
+ if only?(:User)
101
+ describe :User do
102
+ describe 'success' do
103
+ before(:all) do
104
+ BleacherApi::Authenticate.login(ENV['LOGIN'], ENV['PASSWORD'])
105
+ @response = BleacherApi::User.user
106
+ end
107
+
108
+ it "should return a hash with valid keys" do
109
+ @response.keys.length.should == @user_keys.length
110
+ (@response.keys - @user_keys).should == []
111
+ end
112
+ end
113
+
114
+ describe 'failure' do
115
+ before(:all) do
116
+ @response = BleacherApi::User.user('fail')
117
+ end
118
+
119
+ it "should return false" do
120
+ @response.should == false
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,9 @@
1
+ name:
2
+ rake: =0.8.7
3
+ default:
4
+ mysql: =2.8.1
5
+ rspec: =1.3.1
6
+ rspec2:
7
+ mysql2: =0.2.6
8
+ rspec: =2.3.0
9
+ solo: null
@@ -0,0 +1,15 @@
1
+ name: name
2
+ version: 0.1.0
3
+ authors:
4
+ - Author
5
+ email: email@email.com
6
+ homepage: http://github.com/author/name
7
+ summary: Summary
8
+ description: Description
9
+ dependencies:
10
+ - rake
11
+ - default:
12
+ - mysql
13
+ - rspec2:
14
+ - mysql2
15
+ development_dependencies: null
@@ -0,0 +1,17 @@
1
+ require 'pp'
2
+
3
+ $root = File.expand_path('../../', __FILE__)
4
+ require "#{$root}/lib/bleacher_api/gems"
5
+
6
+ BleacherApi::Gems.activate :rspec
7
+
8
+ require "#{$root}/lib/bleacher_api"
9
+
10
+ BleacherApi::Config.url ENV['URL']
11
+
12
+ Spec::Runner.configure do |config|
13
+ end
14
+
15
+ def only?(type)
16
+ ENV['ONLY'].nil? || ENV['ONLY'].downcase == type.to_s.downcase
17
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bleacher_api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Bleacher Report
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-25 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 5
33
+ - 2
34
+ version: 0.5.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 49
46
+ segments:
47
+ - 0
48
+ - 8
49
+ - 7
50
+ version: 0.8.7
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 0
65
+ version: "1.0"
66
+ type: :development
67
+ version_requirements: *id003
68
+ description: A Ruby Interface to the Bleacher Report API
69
+ email: wwelsh@bleacherreport.com
70
+ executables:
71
+ - bleacher_api
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - .gitignore
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - bin/bleacher_api
82
+ - bleacher_api.gemspec
83
+ - config/gemsets.yml
84
+ - config/gemspec.yml
85
+ - lib/bleacher_api.rb
86
+ - lib/bleacher_api/config.rb
87
+ - lib/bleacher_api/gems.rb
88
+ - spec/bleacher_api/gems_spec.rb
89
+ - spec/bleacher_api_spec.rb
90
+ - spec/fixtures/gemsets.yml
91
+ - spec/fixtures/gemspec.yml
92
+ - spec/spec_helper.rb
93
+ has_rdoc: true
94
+ homepage: http://bleacherreport.com
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options: []
99
+
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.4.2
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: A Ruby Interface to the Bleacher Report API
127
+ test_files:
128
+ - spec/bleacher_api/gems_spec.rb
129
+ - spec/bleacher_api_spec.rb
130
+ - spec/fixtures/gemsets.yml
131
+ - spec/fixtures/gemspec.yml
132
+ - spec/spec_helper.rb