triviacrack 0.3.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/publish.yml +1 -1
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +52 -54
- data/lib/triviacrack/api/common.rb +12 -13
- data/lib/triviacrack/api/game.rb +4 -3
- data/lib/triviacrack/api/login.rb +2 -1
- data/lib/triviacrack/api/profile.rb +2 -2
- data/lib/triviacrack/api/question.rb +44 -2
- data/lib/triviacrack/api/user.rb +2 -4
- data/lib/triviacrack/parsers/game_parser.rb +6 -0
- data/lib/triviacrack/version.rb +1 -1
- data/spec/api/game_spec.rb +3 -3
- data/spec/api/login_spec.rb +2 -2
- data/spec/api/profile_spec.rb +2 -2
- data/spec/api/question_spec.rb +46 -4
- data/spec/api/user_spec.rb +2 -2
- data/spec/data/game_duel.json +336 -0
- data/spec/parsers/category_statistics_parser_spec.rb +3 -3
- data/spec/parsers/game_parser_spec.rb +34 -8
- data/spec/parsers/game_statistics_parser_spec.rb +4 -4
- data/spec/parsers/profile_parser_spec.rb +2 -2
- data/spec/parsers/question_parser_spec.rb +2 -2
- data/spec/parsers/session_parser_spec.rb +1 -1
- data/spec/parsers/user_parser_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -0
- data/triviacrack.gemspec +7 -7
- metadata +24 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bac625736e1fdbe91e229596d95e3af90c22ea6b7b2de6373717994301bfe3b9
|
4
|
+
data.tar.gz: 37afe95e8d8aa72297e85236c00af489bc6a8502c9f8b3d079062ed7157fec02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5f407ab7c8f5ca194efe7bdea42f90943b5f41c80fc5e2485f8d891afc076bbca76a0b016b75c9da96d598e436371ee8db7763b3771fd21942052e76825ba0e
|
7
|
+
data.tar.gz: 28d4d34fb76d0fdaaa9c81b00fdf53bc7422406e701cf343275b0a81aebe0faabdb516dcdd1186309fba94bedfe33328111a70e03842c6f5acd17ea5af400fb9
|
data/.github/workflows/ci.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,78 +1,76 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
triviacrack (0.
|
5
|
-
|
4
|
+
triviacrack (0.6.0)
|
5
|
+
faraday (~> 1.7.2)
|
6
|
+
json (~> 2.5.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
docile (1.4.0)
|
13
|
+
faraday (1.7.2)
|
14
|
+
faraday-em_http (~> 1.0)
|
15
|
+
faraday-em_synchrony (~> 1.0)
|
16
|
+
faraday-excon (~> 1.1)
|
17
|
+
faraday-httpclient (~> 1.0.1)
|
18
|
+
faraday-net_http (~> 1.0)
|
19
|
+
faraday-net_http_persistent (~> 1.1)
|
20
|
+
faraday-patron (~> 1.0)
|
21
|
+
faraday-rack (~> 1.0)
|
22
|
+
multipart-post (>= 1.2, < 3)
|
23
|
+
ruby2_keywords (>= 0.0.4)
|
24
|
+
faraday-em_http (1.0.0)
|
25
|
+
faraday-em_synchrony (1.0.0)
|
26
|
+
faraday-excon (1.1.0)
|
27
|
+
faraday-httpclient (1.0.1)
|
28
|
+
faraday-net_http (1.0.1)
|
29
|
+
faraday-net_http_persistent (1.2.0)
|
30
|
+
faraday-patron (1.0.0)
|
31
|
+
faraday-rack (1.0.0)
|
32
|
+
fuubar (2.5.1)
|
17
33
|
rspec-core (~> 3.0)
|
18
34
|
ruby-progressbar (~> 1.4)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
rest-client (2.1.0)
|
30
|
-
http-accept (>= 1.7.0, < 2.0)
|
31
|
-
http-cookie (>= 1.0.2, < 2.0)
|
32
|
-
mime-types (>= 1.16, < 4.0)
|
33
|
-
netrc (~> 0.8)
|
34
|
-
rspec (3.9.0)
|
35
|
-
rspec-core (~> 3.9.0)
|
36
|
-
rspec-expectations (~> 3.9.0)
|
37
|
-
rspec-mocks (~> 3.9.0)
|
38
|
-
rspec-core (3.9.1)
|
39
|
-
rspec-support (~> 3.9.1)
|
40
|
-
rspec-expectations (3.9.0)
|
35
|
+
json (2.5.1)
|
36
|
+
multipart-post (2.1.1)
|
37
|
+
rake (13.0.6)
|
38
|
+
rspec (3.10.0)
|
39
|
+
rspec-core (~> 3.10.0)
|
40
|
+
rspec-expectations (~> 3.10.0)
|
41
|
+
rspec-mocks (~> 3.10.0)
|
42
|
+
rspec-core (3.10.1)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-expectations (3.10.1)
|
41
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
46
|
+
rspec-support (~> 3.10.0)
|
43
47
|
rspec-its (1.3.0)
|
44
48
|
rspec-core (>= 3.0.0)
|
45
49
|
rspec-expectations (>= 3.0.0)
|
46
|
-
rspec-mocks (3.
|
50
|
+
rspec-mocks (3.10.2)
|
47
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-support (3.
|
50
|
-
ruby-progressbar (1.
|
51
|
-
|
52
|
+
rspec-support (~> 3.10.0)
|
53
|
+
rspec-support (3.10.2)
|
54
|
+
ruby-progressbar (1.11.0)
|
55
|
+
ruby2_keywords (0.0.5)
|
56
|
+
simplecov (0.21.2)
|
52
57
|
docile (~> 1.1)
|
53
|
-
|
54
|
-
|
55
|
-
simplecov-html (0.
|
56
|
-
|
57
|
-
unf_ext
|
58
|
-
unf_ext (0.0.7.6)
|
59
|
-
unirest-2x (1.1.3)
|
60
|
-
addressable (~> 2.4)
|
61
|
-
json (~> 2.0)
|
62
|
-
rest-client (~> 2.0)
|
58
|
+
simplecov-html (~> 0.11)
|
59
|
+
simplecov_json_formatter (~> 0.1)
|
60
|
+
simplecov-html (0.12.3)
|
61
|
+
simplecov_json_formatter (0.1.3)
|
63
62
|
|
64
63
|
PLATFORMS
|
65
64
|
ruby
|
66
65
|
|
67
66
|
DEPENDENCIES
|
68
|
-
bundler (~> 2.
|
69
|
-
fuubar (~> 2.5.
|
70
|
-
|
71
|
-
|
72
|
-
rspec (~> 3.9.0)
|
67
|
+
bundler (~> 2.2.27)
|
68
|
+
fuubar (~> 2.5.1)
|
69
|
+
rake (~> 13.0.6)
|
70
|
+
rspec (~> 3.10.0)
|
73
71
|
rspec-its (~> 1.3.0)
|
74
|
-
simplecov (~> 0.
|
72
|
+
simplecov (~> 0.21.2)
|
75
73
|
triviacrack!
|
76
74
|
|
77
75
|
BUNDLED WITH
|
78
|
-
2.
|
76
|
+
2.2.27
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require "
|
1
|
+
require "json"
|
2
|
+
require "faraday"
|
2
3
|
|
3
4
|
require "triviacrack/errors/request_error"
|
4
5
|
|
@@ -13,11 +14,10 @@ module TriviaCrack
|
|
13
14
|
# url - The URL of the TriviaCrack API resource.
|
14
15
|
# parameters - The parameters to send with the request.
|
15
16
|
#
|
16
|
-
# Returns a
|
17
|
+
# Returns a Faraday Response object with the server's response.
|
17
18
|
# Raises TriviaCrack:Errors::RequestError if the request fails.
|
18
19
|
def get(url, parameters: nil)
|
19
|
-
response =
|
20
|
-
headers: default_headers
|
20
|
+
response = Faraday.get "#{API_HOST}#{url}", parameters, default_headers
|
21
21
|
|
22
22
|
check_response url, response
|
23
23
|
end
|
@@ -28,11 +28,10 @@ module TriviaCrack
|
|
28
28
|
# url - The URL of the TriviaCrack API resource.
|
29
29
|
# parameters - The parameters to send with the request.
|
30
30
|
#
|
31
|
-
# Returns a
|
31
|
+
# Returns a Faraday Response object with the server's response.
|
32
32
|
# Raises TriviaCrack:Errors::RequestError if the request fails.
|
33
33
|
def post(url, parameters: nil)
|
34
|
-
response =
|
35
|
-
headers: default_headers
|
34
|
+
response = Faraday.post "#{API_HOST}#{url}", parameters, default_headers
|
36
35
|
|
37
36
|
check_response url, response
|
38
37
|
end
|
@@ -59,17 +58,17 @@ module TriviaCrack
|
|
59
58
|
# Internal: Checks the response's code to see if the request was
|
60
59
|
# successful
|
61
60
|
#
|
62
|
-
# response -
|
61
|
+
# response - Faraday response returned by the API.
|
63
62
|
#
|
64
|
-
# Returns the response
|
63
|
+
# Returns the response body parsed from JSON
|
65
64
|
# Raises TriviaCrack:Errors::RequestError if the request failed.
|
66
65
|
def check_response(url, response)
|
67
|
-
if not response.
|
68
|
-
raise TriviaCrack::Errors::RequestError.new(response.
|
69
|
-
"Request to #{API_HOST}#{url} failed with code #{response.
|
66
|
+
if not response.status.between? 200, 299
|
67
|
+
raise TriviaCrack::Errors::RequestError.new(response.status, url, response.body),
|
68
|
+
"Request to #{API_HOST}#{url} failed with code #{response.status}."
|
70
69
|
end
|
71
70
|
|
72
|
-
response
|
71
|
+
JSON.parse(response.body)
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
data/lib/triviacrack/api/game.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "json"
|
1
2
|
require "triviacrack/api/common"
|
2
3
|
require "triviacrack/parsers/game_parser"
|
3
4
|
|
@@ -21,7 +22,7 @@ module TriviaCrack
|
|
21
22
|
def get_games
|
22
23
|
response = get "/api/users/#{@session.user_id}/dashboard"
|
23
24
|
|
24
|
-
games_data = response
|
25
|
+
games_data = response["list"]
|
25
26
|
|
26
27
|
games = []
|
27
28
|
if games_data
|
@@ -48,7 +49,7 @@ module TriviaCrack
|
|
48
49
|
def get_game(game_id)
|
49
50
|
response = get "/api/users/#{@session.user_id}/games/#{game_id}"
|
50
51
|
|
51
|
-
TriviaCrack::Parsers::GameParser.parse response
|
52
|
+
TriviaCrack::Parsers::GameParser.parse response
|
52
53
|
end
|
53
54
|
|
54
55
|
# Public: Uses the Trivia Crack API to start a new game for the current
|
@@ -64,7 +65,7 @@ module TriviaCrack
|
|
64
65
|
response = post "/api/users/#{@session.user_id}/games",
|
65
66
|
parameters: { language: "EN" }.to_json
|
66
67
|
|
67
|
-
TriviaCrack::Parsers::GameParser.parse response
|
68
|
+
TriviaCrack::Parsers::GameParser.parse response
|
68
69
|
end
|
69
70
|
|
70
71
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "json"
|
1
2
|
require "triviacrack/api/common"
|
2
3
|
require "triviacrack/parsers/session_parser"
|
3
4
|
|
@@ -27,7 +28,7 @@ module TriviaCrack
|
|
27
28
|
language: "en"
|
28
29
|
}.to_json
|
29
30
|
|
30
|
-
@session = TriviaCrack::Parsers::SessionParser.parse response
|
31
|
+
@session = TriviaCrack::Parsers::SessionParser.parse response
|
31
32
|
end
|
32
33
|
|
33
34
|
end
|
@@ -21,7 +21,7 @@ module TriviaCrack
|
|
21
21
|
def get_profile(user_id)
|
22
22
|
response = get "/api/users/#{@session.user_id}/profiles/#{user_id}"
|
23
23
|
|
24
|
-
TriviaCrack::Parsers::ProfileParser.parse response
|
24
|
+
TriviaCrack::Parsers::ProfileParser.parse response
|
25
25
|
end
|
26
26
|
|
27
27
|
# Public: Uses the Trivia Crack API to get the profile of current user.
|
@@ -36,7 +36,7 @@ module TriviaCrack
|
|
36
36
|
response =
|
37
37
|
get "/api/users/#{@session.user_id}/profiles/#{@session.user_id}"
|
38
38
|
|
39
|
-
TriviaCrack::Parsers::ProfileParser.parse response
|
39
|
+
TriviaCrack::Parsers::ProfileParser.parse response
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "json"
|
1
2
|
require "triviacrack/api/common"
|
2
3
|
require "triviacrack/parsers/game_parser"
|
3
4
|
|
@@ -11,7 +12,7 @@ module TriviaCrack
|
|
11
12
|
|
12
13
|
# Public: Uses the Trivia Crack API to answer the given question.
|
13
14
|
#
|
14
|
-
#
|
15
|
+
# game_id - The ID of the TriviaCrack::Game.
|
15
16
|
# question - The TriviaCrack::Question.
|
16
17
|
# answer - The index of the answer to be submitted.
|
17
18
|
#
|
@@ -33,11 +34,52 @@ module TriviaCrack
|
|
33
34
|
}]
|
34
35
|
}.to_json
|
35
36
|
|
36
|
-
game = TriviaCrack::Parsers::GameParser.parse response
|
37
|
+
game = TriviaCrack::Parsers::GameParser.parse response
|
37
38
|
|
38
39
|
[game, answer == question.correct_answer]
|
39
40
|
end
|
40
41
|
|
42
|
+
# Public: Uses the Trivia Crack API to answer duel questions for the game.
|
43
|
+
#
|
44
|
+
# game_id - The ID of the TriviaCrack::Game.
|
45
|
+
# questions - The array of TriviaCrack::Question to answer
|
46
|
+
# answer_map - Hash of question ID / answer indices.
|
47
|
+
#
|
48
|
+
# Examples
|
49
|
+
#
|
50
|
+
# answers = {}
|
51
|
+
# for question in game.questions do
|
52
|
+
# answers[question.id] = <some answer index> // 0, 1, 2 or 3
|
53
|
+
# end
|
54
|
+
# answer_questions game.id, game.questions, answers
|
55
|
+
#
|
56
|
+
# Returns the update TriviaCrack::Game object, as well as a map
|
57
|
+
# with an entry for each question ID and a boolean indicating if
|
58
|
+
# the question was answered successfully.
|
59
|
+
# Raises TriviaCrack::Errors::RequestError if the request fails
|
60
|
+
def answer_questions(game_id, questions, answer_map)
|
61
|
+
answers = []
|
62
|
+
correct_answers = {}
|
63
|
+
|
64
|
+
for question in questions do
|
65
|
+
answer = {
|
66
|
+
id: question.id,
|
67
|
+
answer: answer_map[question.id],
|
68
|
+
category: question.category.upcase
|
69
|
+
}
|
70
|
+
answers << answer
|
71
|
+
correct_answers[question.id] = answer_map[question.id] == question.correct_answer
|
72
|
+
end
|
73
|
+
|
74
|
+
response =
|
75
|
+
post "/api/users/#{@session.user_id}/games/#{game_id}/answers",
|
76
|
+
parameters: { type: questions.first.type.upcase, answers: answers }.to_json
|
77
|
+
|
78
|
+
game = TriviaCrack::Parsers::GameParser.parse response
|
79
|
+
|
80
|
+
[game, correct_answers]
|
81
|
+
end
|
82
|
+
|
41
83
|
end
|
42
84
|
end
|
43
85
|
end
|
data/lib/triviacrack/api/user.rb
CHANGED
@@ -26,9 +26,7 @@ module TriviaCrack
|
|
26
26
|
username = username[1..-1]
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
body = response.body
|
29
|
+
body = get "/api/search?username=#{username}"
|
32
30
|
|
33
31
|
user_id = false
|
34
32
|
body["list"].each do |user|
|
@@ -48,7 +46,7 @@ module TriviaCrack
|
|
48
46
|
def get_user
|
49
47
|
response = get "/api/users/#{@session.user_id}"
|
50
48
|
|
51
|
-
TriviaCrack::Parsers::UserParser.parse response
|
49
|
+
TriviaCrack::Parsers::UserParser.parse response
|
52
50
|
end
|
53
51
|
|
54
52
|
end
|
@@ -31,6 +31,12 @@ module TriviaCrack
|
|
31
31
|
question = TriviaCrack::Parsers::QuestionParser.parse q_data
|
32
32
|
questions << question
|
33
33
|
end
|
34
|
+
if raw_data["spins_data"]["spins"][0]["type"] == "DUEL"
|
35
|
+
q_data = raw_data["spins_data"]["spins"][0]["tie_break_question"]
|
36
|
+
q_data["type"] = raw_data["spins_data"]["spins"][0]["type"]
|
37
|
+
question = TriviaCrack::Parsers::QuestionParser.parse q_data
|
38
|
+
questions << question
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
if raw_data["available_crowns"]
|
data/lib/triviacrack/version.rb
CHANGED
data/spec/api/game_spec.rb
CHANGED
@@ -5,10 +5,10 @@ describe TriviaCrack::API::Game do
|
|
5
5
|
let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
|
6
6
|
let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Game }).new session }
|
7
7
|
|
8
|
-
let(:response) { double(
|
8
|
+
let(:response) { double(status: code, body: raw_data) }
|
9
9
|
|
10
|
-
before { allow(
|
11
|
-
before { allow(
|
10
|
+
before { allow(Faraday).to receive(:get) { response } }
|
11
|
+
before { allow(Faraday).to receive(:post) { response } }
|
12
12
|
|
13
13
|
describe "#get_games" do
|
14
14
|
|
data/spec/api/login_spec.rb
CHANGED
@@ -4,9 +4,9 @@ describe TriviaCrack::API::Login do
|
|
4
4
|
|
5
5
|
let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Login }).new }
|
6
6
|
|
7
|
-
let(:response) { double(
|
7
|
+
let(:response) { double(status: code, body: raw_data) }
|
8
8
|
|
9
|
-
before { allow(
|
9
|
+
before { allow(Faraday).to receive(:post) { response } }
|
10
10
|
|
11
11
|
describe "#login" do
|
12
12
|
|
data/spec/api/profile_spec.rb
CHANGED
@@ -5,9 +5,9 @@ describe TriviaCrack::API::Profile do
|
|
5
5
|
let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
|
6
6
|
let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Profile }).new session }
|
7
7
|
|
8
|
-
let(:response) { double(
|
8
|
+
let(:response) { double(status: code, body: raw_data) }
|
9
9
|
|
10
|
-
before { allow(
|
10
|
+
before { allow(Faraday).to receive(:get) { response } }
|
11
11
|
|
12
12
|
describe "#get_profile" do
|
13
13
|
let(:user_id) { 111 }
|
data/spec/api/question_spec.rb
CHANGED
@@ -5,9 +5,9 @@ describe TriviaCrack::API::Question do
|
|
5
5
|
let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
|
6
6
|
let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Question }).new session }
|
7
7
|
|
8
|
-
let(:response) { double(
|
8
|
+
let(:response) { double(status: code, body: raw_data) }
|
9
9
|
|
10
|
-
before { allow(
|
10
|
+
before { allow(Faraday).to receive(:post) { response } }
|
11
11
|
|
12
12
|
describe "#answer_question" do
|
13
13
|
|
@@ -17,7 +17,7 @@ describe TriviaCrack::API::Question do
|
|
17
17
|
let(:question) { double(id: 1, correct_answer: 1, type: "NORMAL", category: "SPORTS") }
|
18
18
|
let(:game_id) { 22 }
|
19
19
|
|
20
|
-
context 'given that the question was
|
20
|
+
context 'given that the question was answered correctly' do
|
21
21
|
let(:code) { 200 }
|
22
22
|
let(:answer) { 1 }
|
23
23
|
|
@@ -26,7 +26,7 @@ describe TriviaCrack::API::Question do
|
|
26
26
|
it { expect(subject[1]).to be true }
|
27
27
|
end
|
28
28
|
|
29
|
-
context 'given that the question was
|
29
|
+
context 'given that the question was answered incorrectly' do
|
30
30
|
let(:code) { 200 }
|
31
31
|
let(:answer) { 0 }
|
32
32
|
|
@@ -46,4 +46,46 @@ describe TriviaCrack::API::Question do
|
|
46
46
|
.and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")) }
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
describe "#answer_questions" do
|
51
|
+
|
52
|
+
subject { client.answer_questions game_id, questions, answers }
|
53
|
+
|
54
|
+
let(:raw_data) { SpecData.get "answer.json" }
|
55
|
+
let(:question_one) { double(id: 1, correct_answer: 1, type: "DUEL", category: "SPORTS") }
|
56
|
+
let(:question_two) { double(id: 2, correct_answer: 2, type: "DUEL", category: "ART") }
|
57
|
+
let(:questions) { [question_one, question_two] }
|
58
|
+
let(:game_id) { 22 }
|
59
|
+
|
60
|
+
context 'given that the questions were answered correctly' do
|
61
|
+
let(:code) { 200 }
|
62
|
+
let(:answers) { {1 => 1, 2 => 2} }
|
63
|
+
|
64
|
+
it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
|
65
|
+
it { expect(subject[0]).to be_a TriviaCrack::Game }
|
66
|
+
it { expect(subject[1][1]).to be true }
|
67
|
+
it { expect(subject[1][2]).to be true }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'given that a question was answered incorrectly' do
|
71
|
+
let(:code) { 200 }
|
72
|
+
let(:answers) { {1 => 1, 2 => 3} }
|
73
|
+
|
74
|
+
it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
|
75
|
+
it { expect(subject[0]).to be_a TriviaCrack::Game }
|
76
|
+
it { expect(subject[1][1]).to be true }
|
77
|
+
it { expect(subject[1][2]).to be false }
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'given that the request fails' do
|
81
|
+
let(:code) { 400 }
|
82
|
+
let(:answers) { {1 => 1, 2 => 2} }
|
83
|
+
|
84
|
+
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
85
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
86
|
+
.and having_attributes(code: code)) }
|
87
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
88
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")) }
|
89
|
+
end
|
90
|
+
end
|
49
91
|
end
|
data/spec/api/user_spec.rb
CHANGED
@@ -5,9 +5,9 @@ describe TriviaCrack::API::User do
|
|
5
5
|
let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
|
6
6
|
let(:client) { (Class.new(APIStub) { include TriviaCrack::API::User }).new session }
|
7
7
|
|
8
|
-
let(:response) { double(
|
8
|
+
let(:response) { double(status: code, body: raw_data) }
|
9
9
|
|
10
|
-
before { allow(
|
10
|
+
before { allow(Faraday).to receive(:get) { response } }
|
11
11
|
|
12
12
|
describe "#get_user_id" do
|
13
13
|
let(:username) { "example.2" }
|
@@ -0,0 +1,336 @@
|
|
1
|
+
{
|
2
|
+
"id": 1119,
|
3
|
+
"safeOpponentSelectionType": "RANDOM",
|
4
|
+
"spins_data": {
|
5
|
+
"spins": [
|
6
|
+
{
|
7
|
+
"type": "DUEL",
|
8
|
+
"second_chance_available": false,
|
9
|
+
"questions": [
|
10
|
+
{
|
11
|
+
"question": {
|
12
|
+
"id": 17881223,
|
13
|
+
"category": "HISTORY",
|
14
|
+
"text": "The Suffrage movement pertained to what?",
|
15
|
+
"answers": [
|
16
|
+
"Prohibition",
|
17
|
+
"Racial Equality",
|
18
|
+
"Women's Rights",
|
19
|
+
"Right To Unionize"
|
20
|
+
],
|
21
|
+
"correct_answer": 2,
|
22
|
+
"media_type": "NORMAL",
|
23
|
+
"author": {
|
24
|
+
"id": 82565321,
|
25
|
+
"name": "anniesparkles",
|
26
|
+
"username": "anniesparkles",
|
27
|
+
"fb_show_picture": false,
|
28
|
+
"fb_show_name": false,
|
29
|
+
"gender": "UNSPECIFIED"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"question": {
|
35
|
+
"id": 53333638,
|
36
|
+
"category": "GEOGRAPHY",
|
37
|
+
"text": "Where is Slovakia?",
|
38
|
+
"answers": [
|
39
|
+
"Oceania",
|
40
|
+
"Africa",
|
41
|
+
"Europe",
|
42
|
+
"Asia"
|
43
|
+
],
|
44
|
+
"correct_answer": 2,
|
45
|
+
"media_type": "NORMAL",
|
46
|
+
"author": {
|
47
|
+
"id": 204000197,
|
48
|
+
"name": "martingres",
|
49
|
+
"username": "martingres",
|
50
|
+
"fb_show_picture": false,
|
51
|
+
"fb_show_name": false,
|
52
|
+
"gender": "UNSPECIFIED"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"question": {
|
58
|
+
"id": 62181053,
|
59
|
+
"category": "ARTS",
|
60
|
+
"text": "Who has painted the Sistine Chapel?",
|
61
|
+
"answers": [
|
62
|
+
"Michelangelo",
|
63
|
+
"Van Gogh",
|
64
|
+
"Picasso",
|
65
|
+
"Mezzosin"
|
66
|
+
],
|
67
|
+
"correct_answer": 0,
|
68
|
+
"media_type": "NORMAL",
|
69
|
+
"author": {
|
70
|
+
"id": 223909199,
|
71
|
+
"facebook_id": "843171349124950",
|
72
|
+
"name": "Kristina Marie Poulsen",
|
73
|
+
"username": "kp89facebook",
|
74
|
+
"facebook_name": "Kristina Marie Poulsen",
|
75
|
+
"fb_show_picture": true,
|
76
|
+
"fb_show_name": true,
|
77
|
+
"gender": "female"
|
78
|
+
},
|
79
|
+
"translator": {
|
80
|
+
"id": 252287897,
|
81
|
+
"name": "ragingraids",
|
82
|
+
"username": "ragingraids",
|
83
|
+
"fb_show_picture": false,
|
84
|
+
"fb_show_name": false,
|
85
|
+
"gender": "UNSPECIFIED"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"question": {
|
91
|
+
"id": 51360542,
|
92
|
+
"category": "SPORTS",
|
93
|
+
"text": "What two Allstars have the number of 23?",
|
94
|
+
"answers": [
|
95
|
+
"Steph Curry And Blake Griffen",
|
96
|
+
"Lebron James And Michael Jordan",
|
97
|
+
"Chris Paul And Jr Smith",
|
98
|
+
"Clay Thompson And Kevin Love"
|
99
|
+
],
|
100
|
+
"correct_answer": 1,
|
101
|
+
"media_type": "NORMAL",
|
102
|
+
"author": {
|
103
|
+
"id": 200488852,
|
104
|
+
"name": "mitchelldonegan06",
|
105
|
+
"username": "mitchelldonegan06",
|
106
|
+
"fb_show_picture": false,
|
107
|
+
"fb_show_name": false,
|
108
|
+
"gender": "UNSPECIFIED"
|
109
|
+
}
|
110
|
+
}
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"question": {
|
114
|
+
"id": 11817577,
|
115
|
+
"category": "ENTERTAINMENT",
|
116
|
+
"text": "Which pop star calls her fans \"Monsters\"?",
|
117
|
+
"answers": [
|
118
|
+
"Madonna",
|
119
|
+
"Lady Gaga",
|
120
|
+
"Britney Spears",
|
121
|
+
"Christina Aguilera"
|
122
|
+
],
|
123
|
+
"correct_answer": 1,
|
124
|
+
"media_type": "NORMAL",
|
125
|
+
"author": {
|
126
|
+
"id": 51771646,
|
127
|
+
"facebook_id": "",
|
128
|
+
"name": "linda.tsacalides",
|
129
|
+
"username": "linda.tsacalides",
|
130
|
+
"facebook_name": "UNSPECIFIED",
|
131
|
+
"fb_show_picture": false,
|
132
|
+
"fb_show_name": false,
|
133
|
+
"gender": "female"
|
134
|
+
}
|
135
|
+
}
|
136
|
+
},
|
137
|
+
{
|
138
|
+
"question": {
|
139
|
+
"id": 54733278,
|
140
|
+
"category": "SCIENCE",
|
141
|
+
"text": "Which is NOT a blood type?",
|
142
|
+
"answers": [
|
143
|
+
"Ab",
|
144
|
+
"Oa",
|
145
|
+
"O",
|
146
|
+
"B"
|
147
|
+
],
|
148
|
+
"correct_answer": 1,
|
149
|
+
"media_type": "NORMAL",
|
150
|
+
"author": {
|
151
|
+
"id": 114837290,
|
152
|
+
"name": "rocat26",
|
153
|
+
"username": "rocat26",
|
154
|
+
"fb_show_picture": false,
|
155
|
+
"fb_show_name": false,
|
156
|
+
"gender": "female"
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
],
|
161
|
+
"tie_break_question": {
|
162
|
+
"id": 51774,
|
163
|
+
"category": "HISTORY",
|
164
|
+
"text": "Which historical figure is famous for being short?",
|
165
|
+
"answers": [
|
166
|
+
"Napoleon",
|
167
|
+
"Stalin",
|
168
|
+
"Bismark",
|
169
|
+
"Julius Caesar"
|
170
|
+
],
|
171
|
+
"correct_answer": 0,
|
172
|
+
"media_type": "NORMAL",
|
173
|
+
"author": {
|
174
|
+
"id": 23831917,
|
175
|
+
"facebook_id": "100006890463075",
|
176
|
+
"name": "Igor Gardella Trifunovic",
|
177
|
+
"username": "kider.jo",
|
178
|
+
"facebook_name": "Igor Gardella Trifunovic",
|
179
|
+
"fb_show_picture": true,
|
180
|
+
"fb_show_name": true,
|
181
|
+
"gender": "UNSPECIFIED"
|
182
|
+
},
|
183
|
+
"translator": {
|
184
|
+
"id": 100940141,
|
185
|
+
"facebook_id": "100002352524111",
|
186
|
+
"name": "Abigail Morgan",
|
187
|
+
"username": "almangel21",
|
188
|
+
"facebook_name": "Abigail Morgan",
|
189
|
+
"fb_show_picture": true,
|
190
|
+
"fb_show_name": true,
|
191
|
+
"gender": "female"
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
195
|
+
]
|
196
|
+
},
|
197
|
+
"available_crowns": [
|
198
|
+
"SCIENCE",
|
199
|
+
"HISTORY",
|
200
|
+
"ENTERTAINMENT",
|
201
|
+
"SPORTS"
|
202
|
+
],
|
203
|
+
"my_player_number": 1,
|
204
|
+
"player_one": {
|
205
|
+
"charges": 3,
|
206
|
+
"crowns": [
|
207
|
+
"GEOGRAPHY",
|
208
|
+
"ARTS"
|
209
|
+
]
|
210
|
+
},
|
211
|
+
"player_two": {
|
212
|
+
"charges": 0,
|
213
|
+
"crowns": [
|
214
|
+
"SCIENCE"
|
215
|
+
]
|
216
|
+
},
|
217
|
+
"round_number": 2,
|
218
|
+
"crown_events": [
|
219
|
+
{
|
220
|
+
"timestamp": 1583628928756,
|
221
|
+
"userId": 123,
|
222
|
+
"category": "SCIENCE",
|
223
|
+
"won": true
|
224
|
+
}
|
225
|
+
],
|
226
|
+
"sub_status": "P1_PLAYING_TURN",
|
227
|
+
"previous_sub_status": "P1_PLAYING_TURN",
|
228
|
+
"statistics": {
|
229
|
+
"player_one_statistics": {
|
230
|
+
"category_questions": [
|
231
|
+
{
|
232
|
+
"category": "HISTORY",
|
233
|
+
"correct": 1,
|
234
|
+
"incorrect": 0,
|
235
|
+
"worst": false
|
236
|
+
},
|
237
|
+
{
|
238
|
+
"category": "SCIENCE",
|
239
|
+
"correct": 2,
|
240
|
+
"incorrect": 0,
|
241
|
+
"worst": false
|
242
|
+
},
|
243
|
+
{
|
244
|
+
"category": "ARTS",
|
245
|
+
"correct": 3,
|
246
|
+
"incorrect": 0,
|
247
|
+
"worst": false
|
248
|
+
},
|
249
|
+
{
|
250
|
+
"category": "ENTERTAINMENT",
|
251
|
+
"correct": 0,
|
252
|
+
"incorrect": 1,
|
253
|
+
"worst": true,
|
254
|
+
"performance": 0
|
255
|
+
},
|
256
|
+
{
|
257
|
+
"category": "SPORTS",
|
258
|
+
"correct": 2,
|
259
|
+
"incorrect": 0,
|
260
|
+
"worst": false
|
261
|
+
},
|
262
|
+
{
|
263
|
+
"category": "GEOGRAPHY",
|
264
|
+
"correct": 1,
|
265
|
+
"incorrect": 0,
|
266
|
+
"worst": false
|
267
|
+
}
|
268
|
+
],
|
269
|
+
"correct_answers": 9,
|
270
|
+
"incorrect_answers": 1,
|
271
|
+
"challenges_won": 0,
|
272
|
+
"questions_answered": 10,
|
273
|
+
"crowns_won": 2
|
274
|
+
},
|
275
|
+
"player_two_statistics": {
|
276
|
+
"category_questions": [
|
277
|
+
{
|
278
|
+
"category": "HISTORY",
|
279
|
+
"correct": 0,
|
280
|
+
"incorrect": 1,
|
281
|
+
"worst": false
|
282
|
+
},
|
283
|
+
{
|
284
|
+
"category": "SCIENCE",
|
285
|
+
"correct": 1,
|
286
|
+
"incorrect": 0,
|
287
|
+
"worst": false
|
288
|
+
}
|
289
|
+
],
|
290
|
+
"correct_answers": 1,
|
291
|
+
"incorrect_answers": 1,
|
292
|
+
"challenges_won": 0,
|
293
|
+
"questions_answered": 2,
|
294
|
+
"crowns_won": 1
|
295
|
+
}
|
296
|
+
},
|
297
|
+
"is_random": true,
|
298
|
+
"unread_messages": 0,
|
299
|
+
"last_turn": "03/07/2020 19:56:48 EST",
|
300
|
+
"status_version": 13,
|
301
|
+
"my_level_data": {
|
302
|
+
"level": 16,
|
303
|
+
"points": 152,
|
304
|
+
"goal_points": 168,
|
305
|
+
"progress": 11,
|
306
|
+
"level_up": true
|
307
|
+
},
|
308
|
+
"opponent_selection_type": "RANDOM",
|
309
|
+
"nudge_available": false,
|
310
|
+
"opponent": {
|
311
|
+
"id": 321,
|
312
|
+
"alerts_count": 0,
|
313
|
+
"username": "aaa",
|
314
|
+
"facebook_id": "123",
|
315
|
+
"facebookId": {
|
316
|
+
"value": "",
|
317
|
+
"defined": false
|
318
|
+
},
|
319
|
+
"facebook_name": "a b",
|
320
|
+
"fb_show_picture": true,
|
321
|
+
"fb_show_name": true,
|
322
|
+
"allow_og_posts": true,
|
323
|
+
"photo_url": "",
|
324
|
+
"level_data": {
|
325
|
+
"level": 6
|
326
|
+
},
|
327
|
+
"is_friend": false,
|
328
|
+
"league_name": "APPRENTICE_1"
|
329
|
+
},
|
330
|
+
"game_status": "ACTIVE",
|
331
|
+
"language": "EN",
|
332
|
+
"created": "03/07/2020 19:30:03 EST",
|
333
|
+
"type": "NORMAL",
|
334
|
+
"my_turn": true,
|
335
|
+
"expiration_date": "03/09/2020 07:56:48 EST"
|
336
|
+
}
|
@@ -9,7 +9,7 @@ describe TriviaCrack::Parsers::CategoryStatisticsParser do
|
|
9
9
|
let(:category_data) { raw_data["statistics"]["player_one_statistics"]["category_questions"] }
|
10
10
|
|
11
11
|
context 'when given data from the games API' do
|
12
|
-
let(:raw_data) { SpecData.
|
12
|
+
let(:raw_data) { SpecData.get_json "game.json" }
|
13
13
|
|
14
14
|
it { is_expected.to be_a TriviaCrack::CategoryStatistics }
|
15
15
|
its(:category) { is_expected.to be :geography }
|
@@ -19,7 +19,7 @@ describe TriviaCrack::Parsers::CategoryStatisticsParser do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when given data from the dashboard API' do
|
22
|
-
let(:raw_data) { SpecData.
|
22
|
+
let(:raw_data) { SpecData.get_json("dashboard.json")["list"][3] }
|
23
23
|
|
24
24
|
it { is_expected.to be_a TriviaCrack::CategoryStatistics }
|
25
25
|
its(:category) { is_expected.to eq :arts }
|
@@ -29,7 +29,7 @@ describe TriviaCrack::Parsers::CategoryStatisticsParser do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when given data from the answers API' do
|
32
|
-
let(:raw_data) { SpecData.
|
32
|
+
let(:raw_data) { SpecData.get_json "answer.json" }
|
33
33
|
|
34
34
|
it { is_expected.to be_a TriviaCrack::CategoryStatistics }
|
35
35
|
its(:category) { is_expected.to eq :sports }
|
@@ -6,13 +6,13 @@ describe TriviaCrack::Parsers::GameParser do
|
|
6
6
|
|
7
7
|
subject { TriviaCrack::Parsers::GameParser.parse raw_data }
|
8
8
|
|
9
|
-
let(:game_data) { SpecData.
|
10
|
-
let(:dashboard_data) { SpecData.
|
11
|
-
let(:answer_data) { SpecData.
|
12
|
-
let(:new_game_data) { SpecData.
|
9
|
+
let(:game_data) { SpecData.get_json "game.json" }
|
10
|
+
let(:dashboard_data) { SpecData.get_json "dashboard.json" }
|
11
|
+
let(:answer_data) { SpecData.get_json "answer.json" }
|
12
|
+
let(:new_game_data) { SpecData.get_json "new_game.json" }
|
13
13
|
|
14
14
|
context 'when given data from the games API' do
|
15
|
-
let(:raw_data) { SpecData.
|
15
|
+
let(:raw_data) { SpecData.get_json "game.json" }
|
16
16
|
|
17
17
|
it { is_expected.to be_a TriviaCrack::Game }
|
18
18
|
its(:id) { is_expected.to be 1111 }
|
@@ -37,7 +37,7 @@ describe TriviaCrack::Parsers::GameParser do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'when given data from the dashboard API' do
|
40
|
-
let(:raw_data) { SpecData.
|
40
|
+
let(:raw_data) { SpecData.get_json("dashboard.json")["list"][3] }
|
41
41
|
|
42
42
|
it { is_expected.to be_a TriviaCrack::Game }
|
43
43
|
its(:id) { is_expected.to be 1115 }
|
@@ -62,7 +62,7 @@ describe TriviaCrack::Parsers::GameParser do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when given data from the answers API' do
|
65
|
-
let(:raw_data) { SpecData.
|
65
|
+
let(:raw_data) { SpecData.get_json "answer.json" }
|
66
66
|
|
67
67
|
it { is_expected.to be_a TriviaCrack::Game }
|
68
68
|
its(:id) { is_expected.to be 1111 }
|
@@ -87,7 +87,7 @@ describe TriviaCrack::Parsers::GameParser do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
context 'when given data from the new game API' do
|
90
|
-
let(:raw_data) { SpecData.
|
90
|
+
let(:raw_data) { SpecData.get_json "new_game.json" }
|
91
91
|
|
92
92
|
it { is_expected.to be_a TriviaCrack::Game }
|
93
93
|
its(:id) { is_expected.to be 2222 }
|
@@ -110,5 +110,31 @@ describe TriviaCrack::Parsers::GameParser do
|
|
110
110
|
its(:my_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
|
111
111
|
its(:opponent_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
|
112
112
|
end
|
113
|
+
|
114
|
+
context 'when given data from the games API and the game is a duel' do
|
115
|
+
let(:raw_data) { SpecData.get_json "game_duel.json" }
|
116
|
+
|
117
|
+
it { is_expected.to be_a TriviaCrack::Game }
|
118
|
+
its(:id) { is_expected.to be 1119 }
|
119
|
+
its(:opponent) { is_expected.to be_a TriviaCrack::User }
|
120
|
+
its('opponent.id') { is_expected.to be 321 }
|
121
|
+
its(:game_status) { is_expected.to be :active }
|
122
|
+
its(:language) { is_expected.to be :en }
|
123
|
+
its(:created) { is_expected.to be_a Time }
|
124
|
+
its(:last_turn) { is_expected.to be_a Time }
|
125
|
+
its(:type) { is_expected.to be :normal }
|
126
|
+
its(:expiration_date) { is_expected.to be_a Time }
|
127
|
+
its(:my_turn) { is_expected.to be true }
|
128
|
+
its(:round_number) { is_expected.to be 2 }
|
129
|
+
its(:is_random) { is_expected.to be true }
|
130
|
+
its(:unread_messages) { is_expected.to be 0 }
|
131
|
+
its(:status_version) { is_expected.to be 13 }
|
132
|
+
its(:available_crowns) { is_expected.to contain_exactly(:entertainment, :science, :history, :sports) }
|
133
|
+
its('questions.size') { is_expected.to eq(7) }
|
134
|
+
its('questions.first') { is_expected.to be_a TriviaCrack::Question }
|
135
|
+
its('questions.first.id') { is_expected.to be 17881223 }
|
136
|
+
its(:my_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
|
137
|
+
its(:opponent_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
|
138
|
+
end
|
113
139
|
end
|
114
140
|
end
|
@@ -10,7 +10,7 @@ describe TriviaCrack::Parsers::GameStatisticsParser do
|
|
10
10
|
before { statistics_data["crowns"] = raw_data["player_one"]["crowns"] }
|
11
11
|
|
12
12
|
context 'when given data from the games API' do
|
13
|
-
let(:raw_data) { SpecData.
|
13
|
+
let(:raw_data) { SpecData.get_json "game.json" }
|
14
14
|
|
15
15
|
it { is_expected.to be_a TriviaCrack::GameStatistics }
|
16
16
|
its(:correct_answers) { is_expected.to be 12 }
|
@@ -21,7 +21,7 @@ describe TriviaCrack::Parsers::GameStatisticsParser do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when given data from the dashboard API' do
|
24
|
-
let(:raw_data) { SpecData.
|
24
|
+
let(:raw_data) { SpecData.get_json("dashboard.json")["list"][3] }
|
25
25
|
|
26
26
|
it { is_expected.to be_a TriviaCrack::GameStatistics }
|
27
27
|
its(:correct_answers) { is_expected.to be 13 }
|
@@ -32,7 +32,7 @@ describe TriviaCrack::Parsers::GameStatisticsParser do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'when given data from the answer API' do
|
35
|
-
let(:raw_data) { SpecData.
|
35
|
+
let(:raw_data) { SpecData.get_json "answer.json" }
|
36
36
|
|
37
37
|
it { is_expected.to be_a TriviaCrack::GameStatistics }
|
38
38
|
its(:correct_answers) { is_expected.to be 13 }
|
@@ -43,7 +43,7 @@ describe TriviaCrack::Parsers::GameStatisticsParser do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'when given data from the new game API' do
|
46
|
-
let(:raw_data) { SpecData.
|
46
|
+
let(:raw_data) { SpecData.get_json "new_game.json" }
|
47
47
|
|
48
48
|
it { is_expected.to be_a TriviaCrack::GameStatistics }
|
49
49
|
its(:correct_answers) { is_expected.to be 0 }
|
@@ -7,7 +7,7 @@ describe TriviaCrack::Parsers::ProfileParser do
|
|
7
7
|
subject { TriviaCrack::Parsers::ProfileParser.parse raw_data }
|
8
8
|
|
9
9
|
context 'when given data from the profile API' do
|
10
|
-
let(:raw_data) { SpecData.
|
10
|
+
let(:raw_data) { SpecData.get_json "profile.json" }
|
11
11
|
|
12
12
|
it { is_expected.to be_a TriviaCrack::Profile }
|
13
13
|
its(:id) { is_expected.to be 111 }
|
@@ -32,7 +32,7 @@ describe TriviaCrack::Parsers::ProfileParser do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'when given data from the current user profile API' do
|
35
|
-
let(:raw_data) { SpecData.
|
35
|
+
let(:raw_data) { SpecData.get_json "my_profile.json" }
|
36
36
|
|
37
37
|
it { is_expected.to be_a TriviaCrack::Profile }
|
38
38
|
its(:id) { is_expected.to be 222 }
|
@@ -7,7 +7,7 @@ describe TriviaCrack::Parsers::QuestionParser do
|
|
7
7
|
subject { TriviaCrack::Parsers::QuestionParser.parse raw_data }
|
8
8
|
|
9
9
|
context 'when given data without an image' do
|
10
|
-
let(:raw_data) { SpecData.
|
10
|
+
let(:raw_data) { SpecData.get_json "question.json" }
|
11
11
|
|
12
12
|
it { is_expected.to be_a TriviaCrack::Question }
|
13
13
|
its(:type) { is_expected.to be :normal }
|
@@ -19,7 +19,7 @@ describe TriviaCrack::Parsers::QuestionParser do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when given data with an image' do
|
22
|
-
let(:raw_data) { SpecData.
|
22
|
+
let(:raw_data) { SpecData.get_json "question_image.json" }
|
23
23
|
|
24
24
|
it { is_expected.to be_a TriviaCrack::Question }
|
25
25
|
its(:type) { is_expected.to be :normal }
|
@@ -7,7 +7,7 @@ describe TriviaCrack::Parsers::SessionParser do
|
|
7
7
|
subject { TriviaCrack::Parsers::SessionParser.parse raw_data }
|
8
8
|
|
9
9
|
context 'when given data from the login API' do
|
10
|
-
let(:raw_data) { SpecData.
|
10
|
+
let(:raw_data) { SpecData.get_json "login.json" }
|
11
11
|
|
12
12
|
it { is_expected.to be_a TriviaCrack::Session }
|
13
13
|
its(:user_id) { is_expected.to be 111 }
|
@@ -7,7 +7,7 @@ describe TriviaCrack::Parsers::UserParser do
|
|
7
7
|
subject { TriviaCrack::Parsers::UserParser.parse raw_data }
|
8
8
|
|
9
9
|
context 'when given data from the user API' do
|
10
|
-
let(:raw_data) { SpecData.
|
10
|
+
let(:raw_data) { SpecData.get_json "user.json" }
|
11
11
|
|
12
12
|
it { is_expected.to be_a TriviaCrack::User }
|
13
13
|
its(:id) { is_expected.to be 111 }
|
@@ -28,7 +28,7 @@ describe TriviaCrack::Parsers::UserParser do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'when given opponent data from the game API' do
|
31
|
-
let(:raw_data) { SpecData.
|
31
|
+
let(:raw_data) { SpecData.get_json("game.json")["opponent"] }
|
32
32
|
|
33
33
|
it { is_expected.to be_a TriviaCrack::User }
|
34
34
|
its(:id) { is_expected.to be 111 }
|
data/spec/spec_helper.rb
CHANGED
@@ -33,6 +33,10 @@ require_relative "../lib/triviacrack/parsers/user_parser"
|
|
33
33
|
class SpecData
|
34
34
|
|
35
35
|
def self.get(filename)
|
36
|
+
File.read(File.expand_path("../data/#{filename}", __FILE__))
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get_json(filename)
|
36
40
|
file = File.read(File.expand_path("../data/#{filename}", __FILE__))
|
37
41
|
JSON.parse(file)
|
38
42
|
end
|
data/triviacrack.gemspec
CHANGED
@@ -20,13 +20,13 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = ">= 2.0"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 2.
|
24
|
-
spec.add_development_dependency "simplecov", "~> 0.
|
25
|
-
spec.add_development_dependency "rake", "~> 13.0.
|
26
|
-
spec.add_development_dependency "rspec", "~> 3.
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.2.27"
|
24
|
+
spec.add_development_dependency "simplecov", "~> 0.21.2"
|
25
|
+
spec.add_development_dependency "rake", "~> 13.0.6"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.10.0"
|
27
27
|
spec.add_development_dependency "rspec-its", "~> 1.3.0"
|
28
|
-
spec.add_development_dependency "
|
29
|
-
spec.add_development_dependency "fuubar", "~> 2.5.0"
|
28
|
+
spec.add_development_dependency "fuubar", "~> 2.5.1"
|
30
29
|
|
31
|
-
spec.add_dependency "
|
30
|
+
spec.add_dependency "json", "~> 2.5.1"
|
31
|
+
spec.add_dependency "faraday", "~> 1.7.2"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triviacrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Kus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.27
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.2.27
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.21.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.21.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 13.0.
|
47
|
+
version: 13.0.6
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 13.0.
|
54
|
+
version: 13.0.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.10.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.10.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-its
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,47 +81,47 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.3.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: fuubar
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.
|
89
|
+
version: 2.5.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
96
|
+
version: 2.5.1
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: json
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.5.
|
104
|
-
type: :
|
103
|
+
version: 2.5.1
|
104
|
+
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.5.
|
110
|
+
version: 2.5.1
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: faraday
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
117
|
+
version: 1.7.2
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
124
|
+
version: 1.7.2
|
125
125
|
description: A Ruby interface to the Trivia Crack API.
|
126
126
|
email:
|
127
127
|
- david@kus.dk
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".github/workflows/publish.yml"
|
134
134
|
- ".gitignore"
|
135
135
|
- ".rspec"
|
136
|
+
- ".ruby-version"
|
136
137
|
- Gemfile
|
137
138
|
- Gemfile.lock
|
138
139
|
- LICENSE.txt
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- spec/data/answer.json
|
173
174
|
- spec/data/dashboard.json
|
174
175
|
- spec/data/game.json
|
176
|
+
- spec/data/game_duel.json
|
175
177
|
- spec/data/login.json
|
176
178
|
- spec/data/my_profile.json
|
177
179
|
- spec/data/new_game.json
|
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
- !ruby/object:Gem::Version
|
212
214
|
version: '0'
|
213
215
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
216
|
+
rubygems_version: 3.2.22
|
215
217
|
signing_key:
|
216
218
|
specification_version: 4
|
217
219
|
summary: A Ruby interface to the Trivia Crack API.
|
@@ -224,6 +226,7 @@ test_files:
|
|
224
226
|
- spec/data/answer.json
|
225
227
|
- spec/data/dashboard.json
|
226
228
|
- spec/data/game.json
|
229
|
+
- spec/data/game_duel.json
|
227
230
|
- spec/data/login.json
|
228
231
|
- spec/data/my_profile.json
|
229
232
|
- spec/data/new_game.json
|