Class: Osu::Client
- Inherits:
-
Object
- Object
- Osu::Client
- Defined in:
- lib/osu/client.rb
Overview
Client interface that caches a token to make subsequent requests with
Instance Attribute Summary collapse
-
#key ⇒ String
readonly
Auth key.
Instance Method Summary collapse
-
#beatmap(id, author: nil, mode: nil, limit: nil) ⇒ Beatmap+
Beatmaps matching search criteria.
- #beatmap_score(id, user: nil, mode: nil, mods: nil, limit: nil) ⇒ Array<Score>
-
#beatmap_set(id) ⇒ Array<Beatmap>
Beatmaps belonging to this set.
-
#initialize(key) ⇒ Client
constructor
A new instance of Client.
- #user(name, mode = :standard, event_days: nil) ⇒ User
- #user_score(user, sort = :best, mode: nil, limit: nil) ⇒ Array<Score>
Constructor Details
#initialize(key) ⇒ Client
11 12 13 |
# File 'lib/osu/client.rb', line 11 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ String (readonly)
9 10 11 |
# File 'lib/osu/client.rb', line 9 def key @key end |
Instance Method Details
#beatmap(id, author: nil, mode: nil, limit: nil) ⇒ Beatmap+
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/osu/client.rb', line 30 def beatmap(id, author: nil, mode: nil, limit: nil) payload = API::Beatmap.new( id: id, author: , mode: mode, limit: limit ).execute(key) return if payload.empty? return Beatmap.new payload[0] if id && .nil? && mode.nil? && limit.nil? payload.map { |e| Beatmap.new e } end |
#beatmap_score(id, user: nil, mode: nil, mods: nil, limit: nil) ⇒ Array<Score>
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/osu/client.rb', line 59 def beatmap_score(id, user: nil, mode: nil, mods: nil, limit: nil) payload = API::BeatmapScore.new( id, user: user, mode: mode, mods: mods, limit: limit ).execute(key) return if payload.empty? payload.map do |e| e['beatmap_id'] = id Score.new(e) end end |
#beatmap_set(id) ⇒ Array<Beatmap>
46 47 48 49 50 51 |
# File 'lib/osu/client.rb', line 46 def beatmap_set(id) payload = API::Beatmap.new(set: id).execute(key) maps = payload.map { |e| Beatmap.new e } BeatmapSet.new(maps) unless payload.empty? end |
#user(name, mode = :standard, event_days: nil) ⇒ User
19 20 21 22 23 |
# File 'lib/osu/client.rb', line 19 def user(name, mode = :standard, event_days: nil) raise "Requested user for unknown mode '#{mode}'" unless API::MODE.include? mode payload = API::User.new(name, mode, event_days: event_days).execute(key) User.new(payload[0], mode) unless payload.empty? end |
#user_score(user, sort = :best, mode: nil, limit: nil) ⇒ Array<Score>
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/osu/client.rb', line 81 def user_score(user, sort = :best, mode: nil, limit: nil) payload = if sort == :best API::UserBestScore.new( user, mode, limit: limit ) elsif sort == :recent API::UserRecentScore.new( user, mode, limit: limit ) else raise 'Sort must be either :best or :recent!' end payload = payload.execute(key) return if payload.empty? payload.map do |e| e['username'] = user if user.is_a? String Score.new(e) end end |