shift_stats 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 +7 -0
- data/lib/shift_stats.rb +87 -0
- data/lib/shift_stats/configuration.rb +9 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d54b73bde10fcdede215185ab5fcde3539c45b9
|
4
|
+
data.tar.gz: a87adf80f880b5fecb71984484f991851f7263c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33034a682b21a06910a5fe7f8fc3e5b4d09576d31ebd6dbb69a89709a1ba3aee9e07d6261aecdbae6cb0c97a034d6bafc4700fec87a1364240dcbaf5f44c760e
|
7
|
+
data.tar.gz: ed945d743212bd125dba623691fbbbd5054c109aa028979a3a626cdca2b7c55adb62cd2e7dc7309891340dd3c0f0266adb0065dc0f0545ef58c14a2a8729843c
|
data/lib/shift_stats.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
require 'json'
|
3
|
+
require 'shift_stats/configuration'
|
4
|
+
|
5
|
+
class ShiftStats
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.reset
|
15
|
+
@configuration = Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@url_base = 'http://api.shiftstats.com/'
|
24
|
+
@ticket_hash = nil
|
25
|
+
|
26
|
+
@client = HTTPClient.new
|
27
|
+
@client.transparent_gzip_decompression = true
|
28
|
+
|
29
|
+
response = @client.get(url('login'), query: login_query, header: basic_headers)
|
30
|
+
response_json = JSON.parse(response.body) if response
|
31
|
+
if response_json && response_json['ticket'] && response_json['ticket']['hash']
|
32
|
+
@ticket_hash = response_json['ticket']['hash']
|
33
|
+
else
|
34
|
+
if response && response.body
|
35
|
+
raise response.body
|
36
|
+
else
|
37
|
+
raise "Unknown error. Make sure you have an internet connection and your API key is correct."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def team_search(sport, name)
|
43
|
+
JSON.parse(@client.get(url('teams'), query: {name: name, not_ended: true, sport: sport.downcase}, header: headers).body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def team_schedule(team_id)
|
47
|
+
JSON.parse(@client.get(url("team/#{team_id}/games"), query: {future: true, today: true, past: true}, header: headers).body)
|
48
|
+
end
|
49
|
+
|
50
|
+
def team_players_list(team_id)
|
51
|
+
JSON.parse(@client.get(url("team/#{team_id}/players"), query: {status: 'active'}, header: headers).body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def division_games_list(division_id)
|
55
|
+
JSON.parse(@client.get(url("division/#{division_id}/games"), header: headers).body)
|
56
|
+
end
|
57
|
+
|
58
|
+
def season_divisions_list(season_id)
|
59
|
+
JSON.parse(@client.get(url("season/#{season_id}/divisions"), header: headers).body)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def url(sub)
|
64
|
+
return "#{@url_base}#{sub}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def login_query
|
68
|
+
{key: self.class.configuration.api_key}
|
69
|
+
end
|
70
|
+
|
71
|
+
def basic_headers
|
72
|
+
{
|
73
|
+
'Accept' => 'application/json',
|
74
|
+
'Content-Type' => 'application/json',
|
75
|
+
'X-Requested-With' => 'com.digitalshift.hockeyshift',
|
76
|
+
'Accept-Language' => 'en-US',
|
77
|
+
'Accept-Encoding' => 'gzip,deflate',
|
78
|
+
'Connection' => 'keep-alive',
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def headers
|
83
|
+
basic_headers.merge({
|
84
|
+
'Authorization' => "StatsAuth ticket=\"#{@ticket_hash}\""
|
85
|
+
})
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shift_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Pickett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Interfaces with Digital Shift APIs (HockeyShift, BasketballShift, etc.)
|
56
|
+
email: chris@parnic.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/shift_stats.rb
|
62
|
+
- lib/shift_stats/configuration.rb
|
63
|
+
homepage: http://rubygems.org/gems/shift_stats
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.6.11
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Shift stats API
|
87
|
+
test_files: []
|