srl-api 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4da23cb31feb7083ce77cb3afd79a93154f3b30
4
- data.tar.gz: e45f36d4d1fc5324913bdad7f0517387de00d83a
3
+ metadata.gz: 129f173ed7e75ec70eb66b7582d56135d59aa1ac
4
+ data.tar.gz: f4b0e43b26a8517314aea1d7d251592ebe01056f
5
5
  SHA512:
6
- metadata.gz: 47b4aa6679595154f2593e2b79c6590052473658efd2c623a9670d15541ef6dcdb7bfc052ac9a6e1ee456b3ba2c33eb77a5f74329bfb770671bfe17c3e88bc55
7
- data.tar.gz: c09a2ed104465fd14c8de71aef974545b7de6543cd94e058a785bb5e8b1af6cc14d3e8ae8d2e0b05529fa2f3fa58ab15a803be1055cb844736a5e261c2d9e29a
6
+ metadata.gz: f397545db33cf4277bb85431c6229d3e600d19741ef7dbdb4d83b930bd2e4695837fa42fe11bc44cc31f2fdd02e73d9f5ea36be2221172427fafbe526a74d9ae
7
+ data.tar.gz: 3f5e031e123c04e7d32b3273a15b8d050e35945ac866cefbc159f520a8e5ff5a3389ebcab001c14bef13e3b1f22237b2849e7e40b26229500d68117695f38412
data/README.md CHANGED
@@ -15,6 +15,7 @@ it to your program's Gemfile and running `bundle install`.
15
15
 
16
16
  `rdoc lib/` from the project root, or let RubyGems do it for you in $GEM_HOME.
17
17
 
18
+
18
19
  ## Usage
19
20
 
20
21
  Short version:
@@ -30,6 +31,15 @@ Client code should focus on the `SRL` module, with its relevant functions
30
31
  being found in `lib/srl/api.rb`.
31
32
 
32
33
 
34
+ ## OS / Ruby Support
35
+
36
+ While the code probably runs on Ruby 2.1+, I have not yet tested it on
37
+ anything lower than 2.3.0.
38
+
39
+ The library itself should work fine on MS Windows, though the examples
40
+ will not.
41
+
42
+
33
43
  ## Maintainer
34
44
 
35
- Brian Edmonds "Artea" <brian@bedmonds.net>
45
+ Brian Edmonds "Artea" <[brian@bedmonds.net](mailto:brian@bedmonds.net)>
data/lib/srl.rb CHANGED
@@ -2,7 +2,7 @@ require_relative 'srl/api'
2
2
 
3
3
  module SRL
4
4
  # The current version of srl-api.
5
- RELEASE = '0.3.0'.freeze
5
+ RELEASE = '0.4.0'.freeze
6
6
 
7
7
  # Return the current release version as a dotted string.
8
8
  def self.release
data/lib/srl/api.rb CHANGED
@@ -1,8 +1,18 @@
1
- require 'net/http'
2
1
  require 'json'
2
+ require 'net/http'
3
+ require 'time'
4
+
5
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..'))
6
+
7
+ require 'srl/utils'
3
8
 
4
- require_relative 'typedefs'
5
- require_relative 'utils'
9
+ require 'srl/unmarshalable'
10
+
11
+ require 'srl/game'
12
+ require 'srl/past_race'
13
+ require 'srl/player'
14
+ require 'srl/race'
15
+ require 'srl/result_set'
6
16
 
7
17
  module SRL
8
18
  class << self
@@ -50,24 +60,25 @@ module SRL
50
60
  end
51
61
 
52
62
  # Return an array of PastRace objects for completed races.
63
+ #
53
64
  # call-seq: current_races -> array
54
65
  def completed_races(args = {})
55
- res = query('pastraces', args)
66
+ res = query('pastraces', rewrite_args(args))
56
67
  ResultSet.new(
57
68
  SRL::Utils.collection(res.fetch('pastraces'), PastRace),
58
69
  count: res.fetch('count'),
59
70
  page: args.fetch(:page, 1),
60
- page_size: args.fetch(:page_size, 25)
71
+ page_size: args.fetch(:pageSize, 25)
61
72
  )
62
73
  end
63
74
  alias past_races completed_races
64
75
 
65
76
  private
66
77
 
67
- # SpeedRunsLive API URL.
78
+ # SpeedRunsLive API URL. :nodoc:
68
79
  API = 'http://api.speedrunslive.com/'.freeze
69
80
 
70
- # Return a hash with the results of a query to the SRL API.
81
+ # Return a hash with the results of a query to the SRL API. :nodoc:
71
82
  def query(url, params = {})
72
83
  url = URI([API, url].join) # *hiss* "URI" has been wrong for years!
73
84
  url.query = URI.encode_www_form(params) unless params.empty?
@@ -78,6 +89,11 @@ module SRL
78
89
  JSON.parse(res.body)
79
90
  end
80
91
 
92
+ # Alias camelCase argument names to snake_case. :nodoc:
93
+ def rewrite_args(args)
94
+ { pageSize: args.fetch(:page_size, 25) }.merge(args)
95
+ end
96
+
81
97
  end
82
98
  # Raised when an HTTP request to the SRL API server fails,
83
99
  # whether due to a malformed request or the server being down.
data/lib/srl/game.rb ADDED
@@ -0,0 +1,118 @@
1
+ module SRL
2
+ # Summary information about a game run on SRL.
3
+ class Game
4
+ include Unmarshalable
5
+
6
+ # This game's ID as per the SRL data.
7
+ attr_reader :oid
8
+ alias game_id oid
9
+
10
+ # This game's complete name.
11
+ attr_reader :name
12
+
13
+ # This game's abbreviation, as used by RaceBot.
14
+ attr_reader :abbrev
15
+ alias abbreviation abbrev
16
+ alias short_name abbrev
17
+
18
+ # This game's popularity rating, according to SRL data.
19
+ attr_reader :popularity
20
+
21
+ # This game's position in the popularity contest,
22
+ # according to SRL data.
23
+ attr_reader :popularityrank
24
+ alias popularity_rank popularityrank
25
+
26
+ # The amount of ranked players on this game's leaderboard.
27
+ attr_reader :leadersCount
28
+ alias leaders_count leadersCount
29
+ alias num_leaders leadersCount
30
+
31
+ # This game's leaderboard, as an array of Players.
32
+ #
33
+ # While generally sorted by rank, this method does not
34
+ # guarantee the order of the players return.
35
+ #
36
+ # If you absolutely need them sorted, use the `leaders_by_rank`
37
+ # method or call `sort_by(&:rank)` on this value.
38
+ attr_reader :leaders
39
+ def leaders=(arr)
40
+ @leaders = SRL::Utils.collection(arr, Runner)
41
+ end
42
+
43
+ # Statistics about this game. Things like the number of races,
44
+ # number of players, total time played and raced.
45
+ #
46
+ # [SEE] SRL::Statistics
47
+ attr_accessor :stats
48
+ def stats=(val)
49
+ @statistics =
50
+ val.is_a?(Statistics) ? val
51
+ : Statistics.from_hash(val)
52
+ end
53
+ alias statistics stats
54
+
55
+ # An array of players on this game's leaderboard, sorted by their
56
+ # rank.
57
+ #
58
+ #
59
+ def leaders_by_rank(dir = :asc)
60
+ raise ArgumentError unless %i(asc desc).include?(dir)
61
+
62
+ dir == :asc ? leaders.sort_by(&:rank)
63
+ : leaders.sort_by(&:rank).reverse
64
+ end
65
+
66
+ # Name, rating and rank of people that run a game on SRL.
67
+ #
68
+ # [NOTE] This structure is used exclusively by game leaderboards.
69
+ class Runner
70
+ include Unmarshalable
71
+
72
+ # This player's name on the SRL website.
73
+ attr_reader :name
74
+
75
+ # This player's TrueSkill rating for a particular game.
76
+ attr_reader :trueskill
77
+ alias rating trueskill
78
+
79
+ # This player's position on the leaderboards for a specific game.
80
+ attr_reader :rank
81
+ alias position rank
82
+ end
83
+
84
+ # Summary information about runs of a particular game.
85
+ class Statistics
86
+ include Unmarshalable
87
+
88
+ # Number of races that a particular game has had.
89
+ attr_reader :totalRaces
90
+ alias total_races totalRaces
91
+
92
+ # Number of players that have participated in a race of a
93
+ # given game.
94
+ attr_reader :totalPlayers
95
+ alias total_players totalPlayers
96
+
97
+ # The ID of the race with the highest number of entrants.
98
+ attr_reader :largestRace
99
+ alias largest_race_id largestRace
100
+
101
+ # Number of entrants in the largest race of the game associated
102
+ # with these Statistics.
103
+ attr_reader :largestRaceSize
104
+ alias largest_race_player_count largestRaceSize
105
+ alias largest_race_size largestRaceSize
106
+
107
+ # Number of seconds that this game has been raced.
108
+ # A sum of the worst time of each race.
109
+ attr_reader :totalRaceTime
110
+ alias total_race_time totalRaceTime
111
+
112
+ # Number of seconds that this game has been played for.
113
+ # A sum of all the times in all races.
114
+ attr_reader :totalTimePlayed
115
+ alias total_time_played totalTimePlayed
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,58 @@
1
+ module SRL
2
+ # A completed and recorded race.
3
+ class PastRace
4
+ include Unmarshalable
5
+
6
+ attr_reader :game
7
+ def game=(game)
8
+ @game = game.is_a?(Game) ? game : Game.from_hash(game)
9
+ end
10
+
11
+ attr_reader :date
12
+ def date=(val)
13
+ @date = Time.at(val.to_i).utc.to_datetime
14
+ end
15
+
16
+ attr_reader :goal
17
+
18
+ attr_reader :results
19
+ def results=(arr)
20
+ @results = SRL::Utils.collection(arr, Result)
21
+ end
22
+
23
+ # Result of an individual racer's time and rating adjustments.
24
+ class Result
25
+ include Unmarshalable
26
+
27
+ # ID of the race this result entry is associated with.
28
+ #
29
+ # [NOTE] Not to be confused with the SRL Channel ID.
30
+ attr_reader :race
31
+ alias race_id race
32
+
33
+ # Which place did this runner finish in?
34
+ attr_reader :place
35
+ alias position place
36
+
37
+ # The runner's name
38
+ attr_reader :player
39
+ alias name player
40
+
41
+ # Number of seconds the run lasted.
42
+ attr_reader :time
43
+
44
+ # Optional comment entered by the runner.
45
+ attr_reader :message
46
+ alias comment message
47
+
48
+ attr_reader :oldtrueskill
49
+ alias old_rating oldtrueskill
50
+
51
+ attr_reader :newtrueskill
52
+ alias new_rating newtrueskill
53
+
54
+ attr_reader :trueskillchange
55
+ alias rating_adjustment trueskillchange
56
+ end
57
+ end
58
+ end
data/lib/srl/player.rb ADDED
@@ -0,0 +1,44 @@
1
+ module SRL
2
+ # A registered user of SpeedRunsLive.com
3
+ class Player
4
+ include Unmarshalable
5
+
6
+ attr_reader :oid
7
+ alias player_id oid
8
+
9
+ # This player's registered name on SpeedRunsLive.
10
+ # [NOTE] This might not be the same name that he has registered on IRC.
11
+ attr_reader :name
12
+
13
+ # --
14
+ # Stream information for the player
15
+ # ++
16
+ # This player's profile name on a streaming service.
17
+ attr_reader :channel
18
+
19
+ # Streaming platform used by this player. For example: Twitch.
20
+ attr_reader :api
21
+ def api=(val)
22
+ @api = val.intern
23
+ end
24
+
25
+ # This player's YouTube channel.
26
+ attr_reader :youtube
27
+
28
+ # This player's Twitter name.
29
+ attr_reader :twitter
30
+
31
+ # URL to this player's stream.
32
+ #
33
+ # [FIXME] Add support for non-twitch streams.
34
+ def stream
35
+ api == :twitch ? "https://twitch.tv/#{channel}/"
36
+ : 'Unsupported'
37
+ end
38
+
39
+ # Does this player exist?
40
+ def exists?
41
+ player_id != 0
42
+ end
43
+ end
44
+ end
data/lib/srl/race.rb ADDED
@@ -0,0 +1,83 @@
1
+ module SRL
2
+ # A race that has not yet been recorded or closed.
3
+ class Race
4
+ include Unmarshalable
5
+
6
+ STATES = [
7
+ :open,
8
+ :unknown,
9
+ :in_progress,
10
+ :complete
11
+ ].freeze
12
+
13
+ # The IRC channel suffix for this race.
14
+ attr_reader :oid
15
+ alias channel oid
16
+
17
+ # The state of this race. Entry Open / In Progress / Completed
18
+ # [FIXME] Switch to enum-like behaviour with symbols.
19
+ attr_reader :state
20
+
21
+ def status
22
+ STATES[state - 1]
23
+ rescue
24
+ :unknown
25
+ end
26
+
27
+ # The game associate with this race.
28
+ attr_reader :game
29
+ def game=(game)
30
+ @game = game.is_a?(Game) ? game
31
+ : Game.from_hash(game)
32
+ end
33
+
34
+ # The players enlisted in this race as an array of Entrants.
35
+ attr_reader :entrants
36
+ def entrants=(arr)
37
+ # Account for the api returning a hash with the entrants' name
38
+ # as key instead of an array, despite repeating the entrants name
39
+ # in `displayname`.
40
+ arr = arr.is_a?(Hash) ? arr.values : arr
41
+ @entrants = SRL::Utils.collection(arr, Entrant)
42
+ end
43
+
44
+ # A participant in an active race.
45
+ class Entrant
46
+ include Unmarshalable
47
+
48
+ # This entrant's player name.
49
+ attr_reader :displayname
50
+ alias name displayname
51
+
52
+ # This entrant's Twitch account name.
53
+ attr_reader :twitch
54
+
55
+ # The position that this entrant finished this race in.
56
+ attr_reader :place
57
+ alias position place
58
+
59
+ # The comment entered by this entrant for this race,
60
+ # if applicable.
61
+ attr_reader :message
62
+ alias comment message
63
+
64
+ # The number of seconds that this entrant took to complete
65
+ # the race goal.
66
+ #
67
+ # = Notes
68
+ # A time of -1 indicates a forfeit.
69
+ attr_reader :time
70
+
71
+ # Did this entrant forfeit the race?
72
+ def forfeit?
73
+ time == -1
74
+ end
75
+
76
+ # The state of this entrant in the race.
77
+ # Is he ready, finished, neither?
78
+ #
79
+ # [FIXME] Switch to an enum-like implementation with symbols.
80
+ attr_reader :statetext
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,42 @@
1
+ module SRL
2
+ # Wrapper around various calls to paginated data, such as past races.
3
+ # Contains pagination information, and information on all records,
4
+ # on top of the current page's records.
5
+ class ResultSet
6
+ # Records for this result set.
7
+ # [NOTE]
8
+ # Always an array, though the type of object contained in the array
9
+ # can vary depending on the query that spawned it.
10
+ attr_reader :results
11
+ alias data results
12
+ alias records results
13
+ alias items results
14
+
15
+ # The page of this result set.
16
+ attr_reader :page
17
+
18
+ attr_reader :page_size
19
+ alias per_page page_size
20
+
21
+ # Total number of records matching the query for this result set.
22
+ attr_reader :count
23
+ alias total_records count
24
+ alias num_records count
25
+
26
+ def initialize(results, params = {})
27
+ @results = results
28
+ @page = params.fetch(:page)
29
+ @page_size = params.fetch(:page_size)
30
+ @count = params.fetch(:count)
31
+ end
32
+
33
+ def num_pages
34
+ (count.to_f / page_size.to_f).ceil
35
+ end
36
+ alias pages num_pages
37
+
38
+ def last_page?
39
+ page == num_pages
40
+ end
41
+ end
42
+ end
data/test/run.rb ADDED
@@ -0,0 +1,16 @@
1
+ gem 'simplecov'
2
+ gem 'minitest'
3
+ require 'simplecov'
4
+ SimpleCov.command_name('run')
5
+ SimpleCov.start
6
+
7
+ require 'minitest/autorun'
8
+ require 'minitest/hooks/default'
9
+
10
+ if Gem::Specification.find_all_by_name('minitest-color').any?
11
+ require 'minitest/color'
12
+ end
13
+
14
+ Dir["test/run/**/*_test.rb"].each do |f|
15
+ require File.expand_path(f)
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'srl'
2
+
3
+ class PlayerProfileTests < Minitest::Test
4
+ def test_player_profile
5
+ assert_equal 'https://twitch.tv/Artea_SRL/',
6
+ SRL.player('Artea').stream
7
+ end
8
+
9
+ def test_bad_player_name_dies
10
+ # * or at least until someone sees this and registers the name.
11
+ assert_raises(NameError) { SRL.player('ihatetunafishanddeadbeef') }
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'srl'
2
+
3
+ class QueryTests < Minitest::Test
4
+ def test_leaderboard
5
+ assert SRL.leaderboard('alttphacks')
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srl-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian 'Artea' Edmonds
@@ -9,7 +9,49 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-09-13 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: 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: simplecov
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'
13
55
  description: |
14
56
  Library to query the SpeedRunsLive.com API and deal with the results
15
57
  in plain old Ruby.
@@ -23,10 +65,16 @@ files:
23
65
  - README.md
24
66
  - lib/srl.rb
25
67
  - lib/srl/api.rb
26
- - lib/srl/typedefs.rb
68
+ - lib/srl/game.rb
69
+ - lib/srl/past_race.rb
70
+ - lib/srl/player.rb
71
+ - lib/srl/race.rb
72
+ - lib/srl/result_set.rb
27
73
  - lib/srl/unmarshalable.rb
28
74
  - lib/srl/utils.rb
29
- - test/wee.rb
75
+ - test/run.rb
76
+ - test/run/player_profile_test.rb
77
+ - test/run/query_test.rb
30
78
  homepage: https://github.com/bedmonds/srl-api/
31
79
  licenses:
32
80
  - MIT
@@ -54,4 +102,6 @@ signing_key:
54
102
  specification_version: 4
55
103
  summary: Ruby Client for the SpeedRunsLive.com API
56
104
  test_files:
57
- - test/wee.rb
105
+ - test/run.rb
106
+ - test/run/player_profile_test.rb
107
+ - test/run/query_test.rb
data/lib/srl/typedefs.rb DELETED
@@ -1,337 +0,0 @@
1
- require 'time'
2
-
3
- require_relative 'unmarshalable'
4
-
5
- module SRL
6
- class Game
7
- include Unmarshalable
8
-
9
- # This game's ID as per the SRL data.
10
- attr_reader :oid
11
- alias game_id oid
12
-
13
- # This game's complete name.
14
- attr_reader :name
15
-
16
- # This game's abbreviation, as used by RaceBot.
17
- attr_reader :abbrev
18
- alias abbreviation abbrev
19
- alias short_name abbrev
20
-
21
- # This game's popularity rating, according to SRL data.
22
- attr_reader :popularity
23
-
24
- # This game's position in the popularity contest,
25
- # according to SRL data.
26
- attr_reader :popularityrank
27
- alias popularity_rank popularityrank
28
-
29
- # The amount of ranked players on this game's leaderboard.
30
- attr_reader :leadersCount
31
- alias leaders_count leadersCount
32
- alias num_leaders leadersCount
33
-
34
- # This game's leaderboard, as an array of Players.
35
- #
36
- # While generally sorted by rank, this method does not
37
- # guarantee the order of the players return.
38
- #
39
- # If you absolutely need them sorted, use the `leaders_by_rank`
40
- # method or call `sort_by(&:rank)` on this value.
41
- attr_reader :leaders
42
- def leaders=(arr)
43
- @leaders = SRL::Utils.collection(arr, Runner)
44
- end
45
-
46
- # Statistics about this game. Things like the number of races,
47
- # number of players, total time played and raced.
48
- #
49
- # [SEE] SRL::Statistics
50
- attr_accessor :stats
51
- def stats=(val)
52
- @statistics =
53
- val.is_a?(Statistics) ? val
54
- : Statistics.from_hash(val)
55
- end
56
- alias statistics stats
57
-
58
- # An array of players on this game's leaderboard, sorted by their
59
- # rank.
60
- #
61
- #
62
- def leaders_by_rank(dir = :asc)
63
- raise ArgumentError unless %i(asc desc).include?(dir)
64
-
65
- dir == :asc ? leaders.sort_by(&:rank)
66
- : leaders.sort_by(&:rank).reverse
67
- end
68
-
69
- class Runner
70
- include Unmarshalable
71
-
72
- # This player's name on the SRL website.
73
- attr_reader :name
74
-
75
- # This player's TrueSkill rating for a particular game.
76
- attr_reader :trueskill
77
- alias rating trueskill
78
-
79
- # This player's position on the leaderboards for a specific game.
80
- attr_reader :rank
81
- alias position rank
82
- end
83
- end
84
-
85
- class Race
86
- include Unmarshalable
87
-
88
- STATES = [
89
- :open,
90
- :unknown,
91
- :in_progress,
92
- :complete
93
- ].freeze
94
-
95
- # The IRC channel suffix for this race.
96
- attr_reader :oid
97
- alias channel oid
98
-
99
- # The state of this race. Entry Open / In Progress / Completed
100
- # [FIXME] Switch to enum-like behaviour with symbols.
101
- attr_reader :state
102
-
103
- def status
104
- STATES[state - 1]
105
- rescue
106
- :unknown
107
- end
108
-
109
- # The game associate with this race.
110
- attr_reader :game
111
- def game=(game)
112
- @game = game.is_a?(Game) ? game
113
- : Game.from_hash(game)
114
- end
115
-
116
- # The players enlisted in this race as an array of Entrants.
117
- attr_reader :entrants
118
- def entrants=(arr)
119
- # Account for the api returning a hash with the entrants' name
120
- # as key instead of an array, despite repeating the entrants name
121
- # in `displayname`.
122
- arr = arr.is_a?(Hash) ? arr.values : arr
123
- @entrants = SRL::Utils.collection(arr, Entrant)
124
- end
125
-
126
- class Entrant
127
- include Unmarshalable
128
-
129
- # This entrant's player name.
130
- attr_reader :displayname
131
- alias name displayname
132
-
133
- # This entrant's Twitch account name.
134
- attr_reader :twitch
135
-
136
- # The position that this entrant finished this race in.
137
- attr_reader :place
138
- alias position place
139
-
140
- # The comment entered by this entrant for this race,
141
- # if applicable.
142
- attr_reader :message
143
- alias comment message
144
-
145
- # The number of seconds that this entrant took to complete
146
- # the race goal.
147
- #
148
- # = Notes
149
- # A time of -1 indicates a forfeit.
150
- attr_reader :time
151
-
152
- # Did this entrant forfeit the race?
153
- def forfeit?
154
- time == -1
155
- end
156
-
157
- # The state of this entrant in the race.
158
- # Is he ready, finished, neither?
159
- #
160
- # [FIXME] Switch to an enum-like implementation with symbols.
161
- attr_reader :statetext
162
- end
163
- end
164
-
165
- class PastRace
166
- include Unmarshalable
167
-
168
- attr_reader :game
169
- def game=(game)
170
- @game = game.is_a?(Game) ? game : Game.from_hash(game)
171
- end
172
-
173
- attr_reader :date
174
- def date=(val)
175
- @date = Time.at(val.to_i).utc.to_datetime
176
- end
177
-
178
- attr_reader :goal
179
-
180
- attr_reader :results
181
- def results=(arr)
182
- @results = SRL::Utils.collection(arr, Result)
183
- end
184
-
185
- # Result of an individual racer's time and rating adjustments.
186
- class Result
187
- include Unmarshalable
188
-
189
- # ID of the race this result entry is associated with.
190
- #
191
- # [NOTE] Not to be confused with the SRL Channel ID.
192
- attr_reader :race
193
- alias race_id race
194
-
195
- # Which place did this runner finish in?
196
- attr_reader :place
197
- alias position place
198
-
199
- # The runner's name
200
- attr_reader :player
201
- alias name player
202
-
203
- # Number of seconds the run lasted.
204
- attr_reader :time
205
-
206
- # Optional comment entered by the runner.
207
- attr_reader :message
208
- alias comment message
209
-
210
- attr_reader :oldtrueskill
211
- alias old_rating oldtrueskill
212
-
213
- attr_reader :newtrueskill
214
- alias new_rating newtrueskill
215
-
216
- attr_reader :trueskillchange
217
- alias rating_adjustment trueskillchange
218
- end
219
- end
220
-
221
- class Statistics
222
- include Unmarshalable
223
-
224
- # Number of races that a particular game has had.
225
- attr_reader :totalRaces
226
- alias total_races totalRaces
227
-
228
- # Number of players that have participated in a race of a
229
- # given game.
230
- attr_reader :totalPlayers
231
- alias total_players totalPlayers
232
-
233
- # The ID of the race with the highest number of entrants.
234
- attr_reader :largestRace
235
- alias largest_race_id largestRace
236
-
237
- # Number of entrants in the largest race of the game associated
238
- # with these Statistics.
239
- attr_reader :largestRaceSize
240
- alias largest_race_player_count largestRaceSize
241
- alias largest_race_size largestRaceSize
242
-
243
- # Number of seconds that this game has been raced.
244
- # A sum of the worst time of each race.
245
- attr_reader :totalRaceTime
246
- alias total_race_time totalRaceTime
247
-
248
- # Number of seconds that this game has been played for.
249
- # A sum of all the times in all races.
250
- attr_reader :totalTimePlayed
251
- alias total_time_played totalTimePlayed
252
- end
253
-
254
- # A registered user of SpeedRunsLive.com
255
- class Player
256
- include Unmarshalable
257
-
258
- attr_reader :oid
259
- alias player_id oid
260
-
261
- # This player's registered name on SpeedRunsLive.
262
- # [NOTE] This might not be the same name that he has registered on IRC.
263
- attr_reader :name
264
-
265
- # --
266
- # Stream information for the player
267
- # ++
268
- # This player's profile name on a streaming service.
269
- attr_reader :channel
270
-
271
- # Streaming platform used by this player. For example: Twitch.
272
- attr_reader :api
273
- def api=(val)
274
- @api = val.intern
275
- end
276
-
277
- # This player's YouTube channel.
278
- attr_reader :youtube
279
-
280
- # This player's Twitter name.
281
- attr_reader :twitter
282
-
283
- # URL to this player's stream.
284
- #
285
- # [FIXME] Add support for non-twitch streams.
286
- def stream
287
- api == :twitch ? "https://twitch.tv/#{channel}/"
288
- : 'Unsupported'
289
- end
290
-
291
- # Does this player exist?
292
- def exists?
293
- player_id != 0
294
- end
295
- end
296
-
297
- # Wrapper around various calls to paginated data, such as past races.
298
- # Contains pagination information, and information on all records,
299
- # on top of the current page's records.
300
- class ResultSet
301
- # Records for this result set.
302
- # [NOTE]
303
- # Always an array, though the type of object contained in the array
304
- # can vary depending on the query that spawned it.
305
- attr_reader :results
306
- alias data results
307
- alias records results
308
- alias items results
309
-
310
- # The page of this result set.
311
- attr_reader :page
312
-
313
- attr_reader :page_size
314
- alias per_page page_size
315
-
316
- # Total number of records matching the query for this result set.
317
- attr_reader :count
318
- alias total_records count
319
- alias num_records count
320
-
321
- def initialize(results, params = {})
322
- @results = results
323
- @page = params.fetch(:page)
324
- @page_size = params.fetch(:page_size)
325
- @count = params.fetch(:count)
326
- end
327
-
328
- def num_pages
329
- (count.to_f / page_size.to_f).ceil
330
- end
331
- alias pages num_pages
332
-
333
- def last_page?
334
- page == num_pages
335
- end
336
- end
337
- end
data/test/wee.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'srl'
2
-
3
- puts SRL.past_races(player: 'Artea', game: 'ffhacks').records.size