hqtrivia 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de79073cbcf341d2d04df99305e006ad41a1c4ff80a88178df4317f2db226cd5
4
+ data.tar.gz: a1809a12979e96b01b768abf1d2287456afb4897751a1a4a0b893b054a58b901
5
+ SHA512:
6
+ metadata.gz: 4c152b633594fdce2a4597e4b0deb443def346ef3b974ae7bb2c69863245f3b466a4451d5d6bd3d6ae00b2e7ebb2d8e6b9d7047d8e9a3f3b5a635a08cb1c9cc7
7
+ data.tar.gz: 0cc430e4d02f902c974636265c89b801514b83763b6e1126475269753182bd1997de613a4a0bfeeb23b32c17ad130719c5869de24541c092ba313c6f93181a1b
File without changes
@@ -0,0 +1,50 @@
1
+ # HQTriviaRB
2
+
3
+ A ruby library for HQ Trivia.
4
+
5
+ ## What is this for?
6
+
7
+ I mean, why not.
8
+
9
+ ## Usage
10
+
11
+ Put this near the top of your ruby whatever:
12
+
13
+ ```ruby
14
+ require 'hqtrivia'
15
+
16
+ HQ = HQTrivia.new("[your HQ api key]")
17
+ ```
18
+
19
+ Don't have a key? We have a class for that!
20
+
21
+ ```ruby
22
+ require 'hqtrivia'
23
+
24
+ e = HQTrivia::GenerateKey.new(country_code: code, phone_number: "[number]", method: "sms/call")
25
+ e.verify("code")
26
+ HQ = e.hq
27
+ ```
28
+
29
+ Now, when you need to run a method, run HQ.method.
30
+
31
+ Example for getting the authed user.
32
+
33
+ ```ruby
34
+ HQ.me.username
35
+ # => "Chewsterchew"
36
+ ```
37
+
38
+ ## Documentation
39
+
40
+ Stuck? Know Ruby? Check out the [documentation](https://rubydocs.chew.pro/docs/hqtrivia).
41
+
42
+ Still stuck? That Stucks! hey it! Check out our support channels
43
+
44
+ ### Support Channels
45
+
46
+ nonexistent. :!
47
+
48
+ ## But Ruby sucks
49
+
50
+ ***NO U***
@@ -0,0 +1,52 @@
1
+ # Require external gems
2
+ require 'json'
3
+ require 'rest-client'
4
+
5
+ # All HQTrivia functionality, whether extended or just here.
6
+ class HQTrivia
7
+ # Initialize a new HQTrivia Object, via a key.
8
+ # @param key [String] your API Key.
9
+ def initialize(key)
10
+ @key = key
11
+ end
12
+
13
+ # Get the key back. In case you left it at the door.
14
+ attr_reader :key
15
+
16
+ # Get a user by ID
17
+ # @return [User] the new user
18
+ def user(id)
19
+ User.new(id, @key)
20
+ end
21
+
22
+ # Get the authed user's profile
23
+ # @return [Me] the you
24
+ def me
25
+ Me.new(@key)
26
+ end
27
+
28
+ # Get a user's badges (by user ID)
29
+ # @return [Badges] the badges
30
+ def badges(id)
31
+ Badges.new(id, @key)
32
+ end
33
+
34
+ # @return [Schedule] the show schedule
35
+ def schedule
36
+ Schedule.new(@key)
37
+ end
38
+ end
39
+
40
+ # Require files.
41
+ require 'hqtrivia/badge'
42
+ require 'hqtrivia/badges'
43
+ require 'hqtrivia/user'
44
+ require 'hqtrivia/user/leaderboard'
45
+ require 'hqtrivia/user/streakinfo'
46
+ require 'hqtrivia/user/seasonxp'
47
+ require 'hqtrivia/me'
48
+ require 'hqtrivia/schedule'
49
+ require 'hqtrivia/schedule/announcement'
50
+ require 'hqtrivia/schedule/show'
51
+ require 'hqtrivia/errors'
52
+ require 'hqtrivia/generatekey'
@@ -0,0 +1,65 @@
1
+ # The Badge Class. A very specific badge.
2
+ class HQTrivia::Badge
3
+ # @!visibility private
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ # @return [Integer] the ID of this badge
9
+ def id
10
+ @data['achievementId']
11
+ end
12
+
13
+ # @return [String] the name of this badge (shown in the app)
14
+ def name
15
+ @data['name']
16
+ end
17
+
18
+ # @return [String] the description of this badge (shown in the app)
19
+ def description
20
+ @data['description']
21
+ end
22
+
23
+ # @return [String] the family of this badge
24
+ def family
25
+ @data['family']
26
+ end
27
+
28
+ # @return [Integer] the level of this badge
29
+ def level
30
+ @data['familyOrder'] + 1
31
+ end
32
+
33
+ # @return [String] the image for this badge
34
+ def image_url
35
+ @data['imageUrl']
36
+ end
37
+
38
+ # @return [Float] the progress towards the next level. 100 if achieved.
39
+ def progress
40
+ @data['progressPct']
41
+ end
42
+
43
+ # @return [true, false] the completion of this
44
+ def completed?
45
+ @data['completed']
46
+ end
47
+
48
+ # @return [Time] the time this progress was last updated
49
+ def last_updated
50
+ Time.at(@data['lastUpdated'] / 1000)
51
+ end
52
+
53
+ # @return [Time] the time this progress was last updated
54
+ def last_updated
55
+ Time.at(@data['lastUpdated'] / 1000)
56
+ end
57
+
58
+ # HQ API Returns 1/1/1970 if completed? is false. We'll return nil.
59
+ # @return [Time, nil] the time this was achieved
60
+ def earned
61
+ return nil unless completed?
62
+
63
+ Time.parse(@data['earnedAt'])
64
+ end
65
+ end
@@ -0,0 +1,114 @@
1
+ # The Badges Class. A User, but their badges.
2
+ class HQTrivia::Badges
3
+ # Initialize a new user. Get all their stats. Relax.
4
+ # @param id [Integer] the ID of the user.
5
+ # @param key [String] an API key, to get info.
6
+ # @raise [HQTrivia::Errors::InvalidKey] if the api key is invalid
7
+ # @raise [HQTrivia::Errors::InvalidUser] if the user id is invalid
8
+ def initialize(id, key)
9
+ @data = JSON.parse(RestClient.get("https://api-quiz.hype.space/achievements/v2/#{id}", Authorization: key))
10
+ rescue RestClient::NotFound
11
+ raise HQTrivia::Errors::InvalidUser, "This user doesn't exist!"
12
+ rescue RestClient::Unauthorized
13
+ raise HQTrivia::Errors::InvalidKey, "This API Key is invalid!"
14
+ end
15
+
16
+ # @see [User#badges_count]
17
+ # @return [Integer] the amount of badges this person has
18
+ def badges_count
19
+ @data['earnedAchievementCount']
20
+ end
21
+
22
+ # @return [Integer] the amount of achievement types
23
+ def types
24
+ @data['families'].count
25
+ end
26
+
27
+ # Get badge info for a specific level.
28
+ # @return [Badge] badge info for this badge
29
+ def business(level = 3)
30
+ data = @data['families'].find { |type| type['name'] == 'Business' }
31
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
32
+ HQTrivia::Badge.new(badge)
33
+ end
34
+
35
+ # Get badge info for a specific level.
36
+ # @return [Badge] badge info for this badge
37
+ def entertainment(level)
38
+ data = @data['families'].find { |type| type['name'] == 'Entertainment' }
39
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
40
+ HQTrivia::Badge.new(badge)
41
+ end
42
+
43
+ # Get badge info for a specific level.
44
+ # @return [Badge] badge info for this badge
45
+ def geography(level)
46
+ data = @data['families'].find { |type| type['name'] == 'Geography' }
47
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
48
+ HQTrivia::Badge.new(badge)
49
+ end
50
+
51
+ # Get badge info for a specific level.
52
+ # @return [Badge] badge info for this badge
53
+ def history(level)
54
+ data = @data['families'].find { |type| type['name'] == 'History' }
55
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
56
+ HQTrivia::Badge.new(badge)
57
+ end
58
+
59
+ # Get badge info for a specific level.
60
+ # @return [Badge] badge info for this badge
61
+ def literature(level)
62
+ data = @data['families'].find { |type| type['name'] == 'Literature' }
63
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
64
+ HQTrivia::Badge.new(badge)
65
+ end
66
+
67
+ # Get badge info for a specific level.
68
+ # @return [Badge] badge info for this badge
69
+ def movies(level)
70
+ data = @data['families'].find { |type| type['name'] == 'Movies' }
71
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
72
+ HQTrivia::Badge.new(badge)
73
+ end
74
+
75
+ # Get badge info for a specific level.
76
+ # @return [Badge] badge info for this badge
77
+ def music(level)
78
+ data = @data['families'].find { |type| type['name'] == 'Music' }
79
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
80
+ HQTrivia::Badge.new(badge)
81
+ end
82
+
83
+ # Get badge info for a specific level.
84
+ # @return [Badge] badge info for this badge
85
+ def nature(level)
86
+ data = @data['families'].find { |type| type['name'] == 'Nature' }
87
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
88
+ HQTrivia::Badge.new(badge)
89
+ end
90
+
91
+ # Get badge info for a specific level.
92
+ # @return [Badge] badge info for this badge
93
+ def science(level)
94
+ data = @data['families'].find { |type| type['name'] == 'Science' }
95
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
96
+ HQTrivia::Badge.new(badge)
97
+ end
98
+
99
+ # Get badge info for a specific level.
100
+ # @return [Badge] badge info for this badge
101
+ def sports(level)
102
+ data = @data['families'].find { |type| type['name'] == 'Sports' }
103
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
104
+ HQTrivia::Badge.new(badge)
105
+ end
106
+
107
+ # Get badge info for a specific level.
108
+ # @return [Badge] badge info for this badge
109
+ def tv(level)
110
+ data = @data['families'].find { |type| type['name'] == 'TV' }
111
+ badge = data['earnedAchievements'].find { |le| le['familyOrder'] == (level - 1) }
112
+ HQTrivia::Badge.new(badge)
113
+ end
114
+ end
@@ -0,0 +1,17 @@
1
+ # Errors are cool.
2
+ module HQTrivia::Errors
3
+ # Raised if a 404 error is returned
4
+ class InvalidUser < ArgumentError; end
5
+
6
+ # Raised if a 401 error is returned
7
+ class InvalidKey < ArgumentError; end
8
+
9
+ # Raised if a 400 error is returned during Phone Verification
10
+ class InvalidNumber < ArgumentError; end
11
+
12
+ # Raised if a 400 error is returned during Code Verification
13
+ class InvalidCode < ArgumentError; end
14
+
15
+ # Raised if a 429 error is returned during Code Verification
16
+ class TooQuick < ArgumentError; end
17
+ end
@@ -0,0 +1,51 @@
1
+ # Require the errors file
2
+ require_relative 'errors'
3
+
4
+ # The user themselves
5
+ class HQTrivia::GenerateKey
6
+ # Get that auth key!
7
+ # @param country_code [Integer] the country code of your number, blank for 1
8
+ # @param phone [String] the phone actual number
9
+ # @param method [String] the type of verification method
10
+ def initialize(country_code: 1, phone: nil, method: "sms")
11
+ data = {
12
+ "method" => method,
13
+ "phone" => "+#{country_code}#{phone}"
14
+ }
15
+ @data = JSON.parse(RestClient.post('https://api-quiz.hype.space/verifications', data, 'x-hq-client': 'iOS/1.4.15 b146', 'Content-Type': :json))
16
+
17
+ @auth = nil
18
+
19
+ @id = @data['verificationId']
20
+ @retry = Time.now + 20
21
+ @expires = Time.parse(@data['expires'])
22
+ @verified = false
23
+ rescue RestClient::BadRequest
24
+ raise HQTrivia::Errors::InvalidNumber, "That phone number is invalid."
25
+ rescue RestClient::TooManyRequests
26
+ raise HQTrivia::Errors::TooQuick, "You are verifying too fast."
27
+ end
28
+
29
+ # Verify your identity with the code
30
+ # @param code [Integer, String] the code!
31
+ def verify(code)
32
+ @auth = JSON.parse(RestClient.post("https://api-quiz.hype.space/verifications/#{@id}", {"code" => code.to_s}, 'Content-Type': :json))
33
+ @verified = true
34
+ rescue RestClient::BadRequest
35
+ raise HQTrivia::Errors::InvalidCode, "That verification code is incorrect."
36
+ end
37
+
38
+ # @return [String, nil] your API key (once you verify)
39
+ def key
40
+ return nil unless @verified
41
+
42
+ "Bearer #{@auth['auth']['authToken']}"
43
+ end
44
+
45
+ # @return [HQTrivia, nil] a HQTrivia instance, based on the key
46
+ def hq
47
+ return nil unless @verified
48
+
49
+ HQTrivia.new("Bearer #{@auth['auth']['authToken']}")
50
+ end
51
+ end
@@ -0,0 +1,78 @@
1
+ # The user themselves
2
+ class HQTrivia::Me < HQTrivia::User
3
+ # Get that user info!
4
+ # @param key [String] the key of the user
5
+ def initialize(key)
6
+ @key = key
7
+ @data = JSON.parse(RestClient.get('https://api-quiz.hype.space/users/me', Authorization: key, 'x-hq-client': 'iOS/1.4.15 b146'))
8
+ end
9
+
10
+ # @return [Array<String>] an array of this user's device tokens.
11
+ def device_tokens
12
+ @data['deviceTokens']
13
+ end
14
+
15
+ # This is most likely always true, you need one to sign up!
16
+ # @return [true, false] if this user has a phone number.
17
+ def phone?
18
+ @data['hasPhone']
19
+ end
20
+
21
+ # @return [String] your phone number
22
+ def phone_number
23
+ @data['phoneNumber']
24
+ end
25
+
26
+ # @return [Integer] how many lives you have
27
+ def lives
28
+ @data['lives']
29
+ end
30
+
31
+ # @return [true, false] if you have been referred by someone
32
+ def referred?
33
+ @data['referred']
34
+ end
35
+
36
+ # @return [Integer] the user id of the person who referred you.
37
+ def referring_user_id
38
+ @data['referringUserId']
39
+ end
40
+
41
+ # Your HQ Preferences
42
+ # @return [Hash<String, Boolean>] your preferences
43
+ def preferences
44
+ @data['preferences']
45
+ end
46
+
47
+ # @return [Array<Integer>] all of your friends. All. Of. Them. Max 50.
48
+ def friend_ids
49
+ @data['friendIds']
50
+ end
51
+
52
+ # Base64 for a number between 1-4, this dicates the country you're from.
53
+ # This doesn't matter anymore, everyone is forced to be American.
54
+ def stk
55
+ @data['stk']
56
+ end
57
+
58
+ # @return [StreakInfo] your streak info!
59
+ def streak_info
60
+ HQTrivia::User::StreakInfo.new(@data['streakInfo'])
61
+ end
62
+
63
+ # @return [Integer] how many erasers you have
64
+ def erasers
65
+ @data['erase1s']
66
+ end
67
+
68
+ # @return [Integer] how many super spins you have
69
+ def super_spins
70
+ @data['items']['superSpins']
71
+ end
72
+
73
+ # Your point multipliers. 2x, 3x, 4x.
74
+ # @return [Hash<Integer, Integer>] your multipliers.
75
+ def point_multiplier_count
76
+ @data['pointsMultiplierCounts']
77
+ end
78
+ end
@@ -0,0 +1,28 @@
1
+ # The user themselves
2
+ class HQTrivia::Schedule
3
+ # Get that user info!
4
+ # @param key [String] the key of the user
5
+ def initialize(key)
6
+ @key = key
7
+ @data = JSON.parse(RestClient.get('https://api-quiz.hype.space/shows/schedule', Authorization: key, 'x-hq-client': 'iOS/1.4.15 b146'))
8
+ end
9
+
10
+ # @return [Array<Show>] all upcoming shows
11
+ def shows
12
+ shows = []
13
+ @data['shows'].each { |show| shows.push(Show.new(show)) }
14
+ shows
15
+ end
16
+
17
+ # @return [Show] the next game
18
+ def next
19
+ Show.new(@data['shows'][0])
20
+ end
21
+
22
+ # @return [Array<Announcement>] all announcements (shown in the schedule tab)
23
+ def announcements
24
+ announcements = []
25
+ @data['tentpoles'].each { |announcement| announcements.push(Announcement.new(announcement)) }
26
+ announcements
27
+ end
28
+ end
@@ -0,0 +1,80 @@
1
+ # The Schedule Announcement Class. This is an announcement above the schedule
2
+ class HQTrivia::Schedule::Announcement
3
+ # @param data [JSON] the data.
4
+ # @!visibility private
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ # @return [String] the display name of this announcement
10
+ def display_name
11
+ @data['displayName']
12
+ end
13
+
14
+ # @return [String] the accent color
15
+ def accent_color
16
+ @data['accentColor']
17
+ end
18
+
19
+ # @return [String] the background color
20
+ def background_color
21
+ @data['backgroundColor']
22
+ end
23
+
24
+ # @return [String] the background image
25
+ def background_image
26
+ @data['backgroundImage']
27
+ end
28
+
29
+ # @return [String] the background video
30
+ def background_video
31
+ @data['backgroundVideo']
32
+ end
33
+
34
+ # @return [String] the color of the text
35
+ def text_color
36
+ @data['textColor']
37
+ end
38
+
39
+ # Basically the summary
40
+ # @return [String] how it works
41
+ def how_it_works
42
+ @data['howItWorks']
43
+ end
44
+
45
+ # Basically the description
46
+ # @return [String] fine print
47
+ def fine_print
48
+ @data['finePrint']
49
+ end
50
+
51
+ # @return [Integer] the prize (in cents)
52
+ def prize_cents
53
+ @data['prizeCents']
54
+ end
55
+
56
+ # @return [String] the prize currency
57
+ def prize_currency
58
+ @data['prizeCurrency']
59
+ end
60
+
61
+ # @return [String] the name of this announcement
62
+ def name
63
+ @data['name']
64
+ end
65
+
66
+ # @return [Time] the time of this announcement (countdowns to this)
67
+ def time
68
+ Time.parse(@data['time'])
69
+ end
70
+
71
+ # @return [true, false] if this announcement is active
72
+ def active?
73
+ @data['active']
74
+ end
75
+
76
+ # @return [String] the state of this announcement
77
+ def state
78
+ @data['state']
79
+ end
80
+ end
@@ -0,0 +1,151 @@
1
+ # The Schedule Show Class. This is a show on the schedule
2
+ class HQTrivia::Schedule::Show
3
+ # @param data [JSON] the data.
4
+ # @!visibility private
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ # This returns the show type.
10
+ # "hq" is general trivia.
11
+ # "hq-sports" is sports
12
+ # "hq-words" is words.
13
+ # @see words?
14
+ # @see general?
15
+ # @see sports?
16
+ # @see trivia?
17
+ # @return [String] the show type
18
+ def show_type
19
+ @data['showType']
20
+ end
21
+
22
+ # @return [Integer] the ID of this show
23
+ def id
24
+ @data['showId']
25
+ end
26
+
27
+ # This returns the game type.
28
+ # "trivia" is trivia (general/sports).
29
+ # "words" is words.
30
+ # @return [String] the type of this game
31
+ def game_type
32
+ @data['gameType']
33
+ end
34
+
35
+ # The "vertical" is a more specific game type.
36
+ # "general" is normal trivia game
37
+ # "sports" is a sports trivia game
38
+ # "words" is a words game.
39
+ # @return [String] the vertical of this game.
40
+ def vertical
41
+ @show['vertical']
42
+ end
43
+
44
+ # The opt is found in preferences.
45
+ # @see HQTrivia::Me#preferences
46
+ # @return [String] the opt.
47
+ def opt
48
+ @show['vertical']
49
+ end
50
+
51
+ # @return [Time] the start time of this game
52
+ def start_time
53
+ Time.parse(@data['startTime'])
54
+ end
55
+
56
+ # The title displayed in the app.
57
+ # @return [String] the title.
58
+ def title
59
+ @data['display']['title']
60
+ end
61
+
62
+ # The summary displayed in the app.
63
+ # @return [String] the show summary.
64
+ def summary
65
+ @data['display']['summary']
66
+ end
67
+
68
+ # The accent color displayed in the app.
69
+ # @return [String] the accent color.
70
+ def accent_color
71
+ @data['display']['accentColor']
72
+ end
73
+
74
+ # The description displayed in the app.
75
+ # @return [String] the description.
76
+ def description
77
+ @data['display']['description']
78
+ end
79
+
80
+ # The image displayed in the app.
81
+ # @return [String] the image.
82
+ def image
83
+ @data['display']['image']
84
+ end
85
+
86
+ # The logo displayed in the app.
87
+ # @return [String] the logo.
88
+ def logo
89
+ @data['display']['logo']
90
+ end
91
+
92
+ # The background image displayed in the app.
93
+ # @return [String] the background image.
94
+ def background_image
95
+ @data['display']['bgImage']
96
+ end
97
+
98
+ # The background video displayed in the app.
99
+ # @return [String] the background video.
100
+ def background_video
101
+ @data['display']['bgVideo']
102
+ end
103
+
104
+ # @return [Integer] the prize in cents.
105
+ def prize_cents
106
+ @data['prizeCents']
107
+ end
108
+
109
+ # @return [String] the prize.
110
+ def prize
111
+ "$#{(@data['prizeCents'] / 100).to_s.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1' + ",")}"
112
+ end
113
+
114
+ # @return [String] the currency the prize will be in
115
+ def currency
116
+ @data['currency']
117
+ end
118
+
119
+ # @return [String] the season this game will count towards
120
+ def season_name
121
+ @data['seasonName']
122
+ end
123
+
124
+ # @return [true, false] if this show is an HQ Words game
125
+ def words?
126
+ return true if vertical == 'words'
127
+
128
+ false
129
+ end
130
+
131
+ # @return [true, false] if this show is an HQ Trivia game (general or sports)
132
+ def trivia?
133
+ return true if game_type == 'trivia'
134
+
135
+ false
136
+ end
137
+
138
+ # @return [true, false] if this show is an HQ Sports game
139
+ def sports?
140
+ return true if vertical == 'sports'
141
+
142
+ false
143
+ end
144
+
145
+ # @return [true, false] if this show is an HQ Trivia (not sports) game
146
+ def general?
147
+ return true if vertical == 'general'
148
+
149
+ false
150
+ end
151
+ end
@@ -0,0 +1,93 @@
1
+ # The User Class. A User. Your typical, everyday user.
2
+ class HQTrivia::User
3
+ # Initialize a new user. Get all their stats. Relax.
4
+ # @param id [Integer] the ID of the user.
5
+ # @param key [String] an API key, to get info.
6
+ # @raise [HQTrivia::Errors::InvalidKey] if the api key is invalid
7
+ # @raise [HQTrivia::Errors::InvalidUser] if the user id is invalid
8
+ def initialize(id, key)
9
+ @key = key
10
+ @data = JSON.parse(RestClient.get("https://api-quiz.hype.space/users/#{id}", Authorization: key))
11
+ rescue RestClient::NotFound
12
+ raise HQTrivia::Errors::InvalidUser, "This user doesn't exist!"
13
+ rescue RestClient::Unauthorized
14
+ raise HQTrivia::Errors::InvalidKey, "This API Key is invalid!"
15
+ end
16
+
17
+ # @return [Integer] their id
18
+ def id
19
+ @data['userId']
20
+ end
21
+
22
+ # @return [String] their username
23
+ def username
24
+ @data['username']
25
+ end
26
+
27
+ # A user always has an avatar, whether HQ provided or not.
28
+ # @return [String] the user's Avatar URL.
29
+ def avatar_url
30
+ @data['avatarUrl']
31
+ end
32
+
33
+ # @return [Time] the creation date of this user
34
+ def created
35
+ Time.parse(@data['created'])
36
+ end
37
+
38
+ # This user's leaderboard, returned as a UserLeaderboard object
39
+ # @return [User::Leaderboard] the user's leaderboard standings
40
+ def leaderboard
41
+ HQTrivia::User::Leaderboard.new(@data['leaderboard'])
42
+ end
43
+
44
+ # @return [Integer] the user's high score.
45
+ def high_score
46
+ @data['highScore']
47
+ end
48
+
49
+ # @return [Integer] the amount of games this user has played
50
+ def games_played
51
+ @data['gamesPlayed']
52
+ end
53
+
54
+ # @return [Integer] the amount of games this user has won
55
+ def win_count
56
+ @data['winCount']
57
+ end
58
+
59
+ # @see [User#badges]
60
+ # @return [Integer] the amount of badges this person has
61
+ def badges_count
62
+ @data['achievementCount']
63
+ end
64
+
65
+ # @return [Badges] the badges for this user.
66
+ def badges
67
+ HQTrivia::Badges.new(id, @key)
68
+ end
69
+
70
+ # @return [User::SeasonXP] the season XP stats of this user
71
+ def season_xp
72
+ HQTrivia::User::SeasonXP.new(@data['seasonXp'])
73
+ end
74
+
75
+ # @return [true, false] whether this person has been blocked by the authed user
76
+ def blocked?
77
+ @data['blocked']
78
+ end
79
+
80
+ # @return [true, false] whether this person is blocking the authed user
81
+ def blocking?
82
+ @data['blocksMe']
83
+ end
84
+
85
+ # If this is true, you should consider HQTrivia#me.
86
+ # Otherwise, this is just a normal user.
87
+ # @return [true, false] whether the user is actually the owner of the key
88
+ def authed_user?
89
+ return true unless @data['hasPhone'].nil?
90
+
91
+ false
92
+ end
93
+ end
@@ -0,0 +1,71 @@
1
+ # The User Leaderboard Class. A user's stats.
2
+ class HQTrivia::User::Leaderboard
3
+ # @param data [JSON] the data.
4
+ # @!visibility private
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ # @return [String] the total earnings
10
+ def total
11
+ @data['total']
12
+ end
13
+
14
+ # @return [Integer] the total earnings, in cents.
15
+ def total_cents
16
+ @data['totalCents']
17
+ end
18
+
19
+ # @return [String] the amount of unclaimed money!
20
+ def unclaimed
21
+ @data['unclaimed']
22
+ end
23
+
24
+ # @return [Integer] the amount of wins on this week's leaderboard
25
+ def wins
26
+ @data['wins']
27
+ end
28
+
29
+ # @return [Integer, nil] the rank of this user this week, nil if no rank
30
+ def rank
31
+ return nil if @data['rank'] == 101 && @data['wins'] == 0
32
+
33
+ @data['rank']
34
+ end
35
+
36
+ # This is only based on HQ Trivia I believe, and sometimes isn't even accurate!
37
+ # @return [String] the all time total.
38
+ def alltime_total
39
+ @data['alltime']['total']
40
+ end
41
+
42
+ # This is only based on HQ Trivia I believe, and sometimes isn't even accurate!
43
+ # @return [String] the all time win count.
44
+ def alltime_wins
45
+ @data['alltime']['wins']
46
+ end
47
+
48
+ # This is only based on HQ Trivia I believe. Most likely accurate based on the information.
49
+ # @return [String] the all time ranking.
50
+ def alltime_rank
51
+ @data['alltime']['rank']
52
+ end
53
+
54
+ # This is only based on HQ Trivia I believe, and sometimes isn't even accurate!
55
+ # @return [String] the weekly total.
56
+ def weekly_total
57
+ @data['weekly']['total']
58
+ end
59
+
60
+ # This is only based on HQ Trivia I believe, and sometimes isn't even accurate!
61
+ # @return [String] the weekly win count.
62
+ def weekly_wins
63
+ @data['weekly']['wins']
64
+ end
65
+
66
+ # This is only based on HQ Trivia I believe. Most likely accurate based on the information.
67
+ # @return [String] the weekly ranking.
68
+ def weekly_rank
69
+ @data['weekly']['rank']
70
+ end
71
+ end
@@ -0,0 +1,68 @@
1
+ # The User SeasonXP Class. A user's season.
2
+ class HQTrivia::User::SeasonXP
3
+ # @param data [JSON] the data.
4
+ # @!visibility private
5
+ def initialize(data)
6
+ @data = data[0]
7
+ end
8
+
9
+ # @return [Integer] the user's current points
10
+ def current_points
11
+ @data['currentPoints']
12
+ end
13
+
14
+ # @return [Integer] the points this user needs to level up
15
+ def remaining_points
16
+ @data['remainingPoints']
17
+ end
18
+
19
+ # @return [String] the name of this season
20
+ def name
21
+ @data['name']
22
+ end
23
+
24
+ # @return [true, false] if this season is active.
25
+ def active?
26
+ @data['active']
27
+ end
28
+
29
+ # General is HQ Trivia, Sports is HQ Sports, Words is HQ Words
30
+ # @return [Array<String>] what game modes contribute towards the points
31
+ def participating_gamemodes
32
+ @data['verticals']
33
+ end
34
+
35
+ # @return [Integer] the current level this user is on.
36
+ def current_level
37
+ @data['currentLevel']['level']
38
+ end
39
+
40
+ # The range of the current level.
41
+ # This is returned as a range.
42
+ # Do current_level_range.min to find min
43
+ # Do current_level_range.max to find max
44
+ # @return [Range] the range of this level
45
+ def current_level_range
46
+ Range.new(@data['currentLevel']['minPoints'], @data['currentLevel']['maxPoints'])
47
+ end
48
+
49
+ # @return [Hash<String, String>] the display, as shown in the app.
50
+ def display
51
+ @data['display']
52
+ end
53
+
54
+ # @return [Integer] the amount of referrals
55
+ def referrals
56
+ @data['quotas']['currentReferrals']
57
+ end
58
+
59
+ # @return [Integer] the amount of shares to facebook
60
+ def shares_to_facebook
61
+ @data['quotas']['currentSharesToFacebook']
62
+ end
63
+
64
+ # @return [Integer] the amount of shares to Twitter
65
+ def shares_to_twitter
66
+ @data['quotas']['currentSharesToTwitter']
67
+ end
68
+ end
@@ -0,0 +1,43 @@
1
+ # The User StreakInfo Class. A user's streak information.
2
+ class HQTrivia::User::StreakInfo
3
+ # @param data [JSON] the data.
4
+ # @!visibility private
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ # @return [Integer] the ID of this streak's user.
10
+ def id
11
+ @data['userId']
12
+ end
13
+
14
+ # @return [Integer] the target goals (in consecutive days)
15
+ def target
16
+ @data['target']
17
+ end
18
+
19
+ # @return [Time] the date this streak started
20
+ def start_date
21
+ Time.parse(@data['startDate'])
22
+ end
23
+
24
+ # @return [Integer] the current streak duration
25
+ def current
26
+ @data['current']
27
+ end
28
+
29
+ # @return [Integer] the total streak duration
30
+ def total
31
+ @data['total']
32
+ end
33
+
34
+ # @return [Time] when this user last played
35
+ def last_played
36
+ Time.parse(@data['lastPlayed'])
37
+ end
38
+
39
+ # @return [true, false] if the user should be notified
40
+ def notify?
41
+ @data['notify']
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hqtrivia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chew
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0.rc1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0.rc1
41
+ description: An HQ Trivia (https://hqtrivia.com) API Wrapper in Ruby
42
+ email: chew@chew.pw
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".yardopts"
48
+ - README.md
49
+ - lib/hqtrivia.rb
50
+ - lib/hqtrivia/badge.rb
51
+ - lib/hqtrivia/badges.rb
52
+ - lib/hqtrivia/errors.rb
53
+ - lib/hqtrivia/generatekey.rb
54
+ - lib/hqtrivia/me.rb
55
+ - lib/hqtrivia/schedule.rb
56
+ - lib/hqtrivia/schedule/announcement.rb
57
+ - lib/hqtrivia/schedule/show.rb
58
+ - lib/hqtrivia/user.rb
59
+ - lib/hqtrivia/user/leaderboard.rb
60
+ - lib/hqtrivia/user/seasonxp.rb
61
+ - lib/hqtrivia/user/streakinfo.rb
62
+ homepage: https://github.com/Chew/HQTriviaRB
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ bug_tracker_uri: https://github.com/Chew/HQTriviaRB/issues
67
+ changelog_uri: https://github.com/Chew/HQTriviaRB/releases
68
+ homepage_uri: http://github.com/Chew/HQTriviaRB
69
+ source_code_uri: http://github.com/Chew/HQTriviaRB
70
+ wiki_uri: http://github.com/Chew/HQTriviaRB/wiki
71
+ documentation_uri: https://rubydocs.chew.pro/docs/hqtrivia
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.2.4
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.0.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: An HQ Trivia API Wrapper in Ruby
91
+ test_files: []