probasketball 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d3434db575f76a39c9ce93f464778c576282923d
4
+ data.tar.gz: cd301eb08f02dcc20fd4060ad6412b88c4d366b7
5
+ SHA512:
6
+ metadata.gz: 3313f91371077c435d8a99cf667410b1ab422a478f26ff3bce6deb62b66b63172c3916702ec982e8d3414b1d68af270f26761f7a41ae76ec3d82476d0c76af26
7
+ data.tar.gz: a3766d0011b500e42f0e70684c53228816700af27de2ac5ebbcae9b4145cc2749cec632d4ed2dcc59d733551340134d9cd6596b99f1c82ced6989da517047252
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 seanchambo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # probasketball-ruby
2
+ An easy to use gem that exposes the ProBasketball API
@@ -0,0 +1,72 @@
1
+ class Probasketball
2
+ def self.connect(api_key, options = {})
3
+ self.new(api_key, options)
4
+ end
5
+
6
+ def initialize(api_key, options)
7
+ @api_key = api_key
8
+ @options = options
9
+ @api = Probasketball::Api.new(@api_key, @options)
10
+ end
11
+
12
+ def teams
13
+ @teams ||= Probasketball::Collections::Teams.new(api)
14
+ end
15
+
16
+ def players
17
+ @players ||= Probasketball::Collections::Players.new(api)
18
+ end
19
+
20
+ def games
21
+ @games ||= Probasketball::Collections::Games.new(api)
22
+ end
23
+
24
+ def shots
25
+ @shots ||= Probasketball::Collections::Shots.new(api)
26
+ end
27
+
28
+ def advanced_stats
29
+ @advanced_stats ||= Probasketball::Collections::AdvancedStats.new(api)
30
+ end
31
+
32
+ def misc_stats
33
+ @misc_stats ||= Probasketball::Collections::MiscStats.new(api)
34
+ end
35
+
36
+ def boxscores
37
+ @boxscores ||= Probasketball::Collections::Boxscores.new(api)
38
+ end
39
+
40
+ def four_factors
41
+ @four_factors ||= Probasketball::Collections::FourFactors.new(api)
42
+ end
43
+
44
+ def sportsvu_data
45
+ @sportsvu_data ||= Probasketball::Collections::SportsvuData.new(api)
46
+ end
47
+
48
+ def usages
49
+ @usages ||= Probasketball::Collections::Usages.new(api)
50
+ end
51
+
52
+ private
53
+
54
+ def api
55
+ @api
56
+ end
57
+
58
+ class ApiError < StandardError
59
+ end
60
+ end
61
+
62
+ require 'probasketball/api'
63
+ require 'probasketball/collections/games'
64
+ require 'probasketball/collections/players'
65
+ require 'probasketball/collections/teams'
66
+ require 'probasketball/collections/shots'
67
+ require 'probasketball/collections/advanced_stats'
68
+ require 'probasketball/collections/four_factors'
69
+ require 'probasketball/collections/misc_stats'
70
+ require 'probasketball/collections/sportsvu_data'
71
+ require 'probasketball/collections/usages'
72
+ require 'probasketball/collections/boxscores'
@@ -0,0 +1,52 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ class Probasketball::Api
5
+ def initialize(api_key, options = {})
6
+ @api_key = api_key
7
+ @options = options
8
+ end
9
+
10
+ BASE_URLS = {
11
+ :v1 => 'https://probasketballapi.com/',
12
+ :v2 => 'http://api.probasketballapi.com/'
13
+ }
14
+
15
+ def post(url, params = {})
16
+ response = RestClient.post build_url(url), build_params(params), headers
17
+ Response::Success.new(JSON.parse(response), response.code)
18
+ rescue RestClient::ExceptionWithResponse => e
19
+ Response::Error.new(e.message)
20
+ rescue JSON::ParserError => e
21
+ Response::Error.new(response.body)
22
+ end
23
+
24
+ private
25
+
26
+ def headers
27
+ { accept: :json, content_type: :json }
28
+ end
29
+
30
+ def build_params(params)
31
+ params.merge(api_key: api_key).to_json
32
+ end
33
+
34
+ def build_url(url)
35
+ puts base_url + url
36
+ base_url + url
37
+ end
38
+
39
+ def api_key
40
+ @api_key
41
+ end
42
+
43
+ def version
44
+ @options.fetch(:version, :v2)
45
+ end
46
+
47
+ def base_url
48
+ BASE_URLS.fetch(version)
49
+ end
50
+ end
51
+
52
+ require 'probasketball/api/response'
@@ -0,0 +1,31 @@
1
+ module Probasketball::Api::Response
2
+ class Success
3
+ attr_reader :body, :status
4
+
5
+ def initialize(body, status = :ok)
6
+ @body = body
7
+ @status = status
8
+ end
9
+
10
+ def success?
11
+ true
12
+ end
13
+ end
14
+
15
+ class Error
16
+ attr_reader :status
17
+
18
+ def initialize(error, status = :unprocessable_entity)
19
+ @error = error
20
+ @status = status
21
+ end
22
+
23
+ def body
24
+ { error: @error }
25
+ end
26
+
27
+ def success?
28
+ false
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ module Probasketball::Collections
2
+ class BaseCollection
3
+ def initialize(api, url)
4
+ @api = api
5
+ @url = url
6
+ end
7
+
8
+ def fetchAll
9
+ call!
10
+ end
11
+
12
+ def fetch(options = {})
13
+ call!(options)
14
+ end
15
+
16
+ def find(options)
17
+ !call(options).first
18
+ end
19
+
20
+ private
21
+
22
+ def call!(options = {})
23
+ response = @api.post(@url, options)
24
+ return response.body if response.success?
25
+ fail Probasketball::ApiError, response.body[:error]
26
+ end
27
+ end
28
+
29
+ class MultipleBaseCollection
30
+ def initialize(api, base_url)
31
+ @api = api
32
+ @base_url = base_url
33
+ end
34
+
35
+ def players
36
+ @players ||= Players.new(@api, @base_url)
37
+ end
38
+
39
+ def teams
40
+ @teams ||= Teams.new(@api, @base_url)
41
+ end
42
+
43
+ class Players < Probasketball::Collections::BaseCollection
44
+ def initialize(api, base_url)
45
+ super(api, base_url + 'player')
46
+ end
47
+ end
48
+
49
+ class Teams < Probasketball::Collections::BaseCollection
50
+ def initialize(api, base_url)
51
+ super(api, base_url + 'team')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ require 'probasketball/collections'
2
+
3
+ module Probasketball::Collections
4
+ class AdvancedStats < Probasketball::Collections::MultipleBaseCollection
5
+ def initialize(api)
6
+ super(api, 'advanced/')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'probasketball/collections'
2
+
3
+ module Probasketball::Collections
4
+ class Boxscores < Probasketball::Collections::MultipleBaseCollection
5
+ def initialize(api)
6
+ super(api, 'boxscores/')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'probasketball/collections'
2
+
3
+ module Probasketball::Collections
4
+ class FourFactors < Probasketball::Collections::MultipleBaseCollection
5
+ def initialize(api)
6
+ super(api, 'four_factor/')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'probasketball/collections'
2
+
3
+ class Probasketball::Collections::Games < Probasketball::Collections::BaseCollection
4
+ def initialize(api)
5
+ super(api, 'game')
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'probasketball/collections'
2
+
3
+ module Probasketball::Collections
4
+ class MiscStats < Probasketball::Collections::MultipleBaseCollection
5
+ def initialize(api)
6
+ super(api, 'misc/')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'probasketball/collections'
2
+
3
+ class Probasketball::Collections::Players < Probasketball::Collections::BaseCollection
4
+ def initialize(api)
5
+ super(api, 'player')
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'probasketball/collections'
2
+
3
+ class Probasketball::Collections::Shots < Probasketball::Collections::BaseCollection
4
+ def initialize(api)
5
+ super(api, 'shots')
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'probasketball/collections'
2
+
3
+ module Probasketball::Collections
4
+ class SportsvuData < Probasketball::Collections::MultipleBaseCollection
5
+ def initialize(api)
6
+ super(api, 'sportsvu/')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'probasketball/collections'
2
+
3
+ class Probasketball::Collections::Teams < Probasketball::Collections::BaseCollection
4
+ def initialize(api)
5
+ super(api, 'team')
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'probasketball/collections'
2
+
3
+ module Probasketball::Collections
4
+ class Usages < Probasketball::Collections::MultipleBaseCollection
5
+ def initialize(api)
6
+ super(api, 'usage/')
7
+ end
8
+
9
+ def teams
10
+ []
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'probasketball'
3
+ spec.version = '0.0.1'
4
+ spec.date = '2017-03-09'
5
+ spec.summary = "Probasketball API"
6
+ spec.description = "API Class that allows you to get live NBA stats"
7
+ spec.authors = ["Sean Chamberlain"]
8
+ spec.email = 'seanlchamberlain@gmail.com'
9
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
10
+ spec.homepage = 'http://rubygemspec.org/gems/probasketball'
11
+ spec.license = 'MIT'
12
+
13
+ spec.add_runtime_dependency 'rest-client'
14
+ spec.add_runtime_dependency 'json'
15
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: probasketball
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Chamberlain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: API Class that allows you to get live NBA stats
42
+ email: seanlchamberlain@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - LICENSE
49
+ - README.md
50
+ - lib/probasketball.rb
51
+ - lib/probasketball/api.rb
52
+ - lib/probasketball/api/response.rb
53
+ - lib/probasketball/collections.rb
54
+ - lib/probasketball/collections/advanced_stats.rb
55
+ - lib/probasketball/collections/boxscores.rb
56
+ - lib/probasketball/collections/four_factors.rb
57
+ - lib/probasketball/collections/games.rb
58
+ - lib/probasketball/collections/misc_stats.rb
59
+ - lib/probasketball/collections/players.rb
60
+ - lib/probasketball/collections/shots.rb
61
+ - lib/probasketball/collections/sportsvu_data.rb
62
+ - lib/probasketball/collections/teams.rb
63
+ - lib/probasketball/collections/usages.rb
64
+ - probasketball.gemspec
65
+ homepage: http://rubygemspec.org/gems/probasketball
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Probasketball API
89
+ test_files: []