triviacrack 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/triviacrack/api/common.rb +5 -5
- data/lib/triviacrack/errors/request_error.rb +10 -1
- data/lib/triviacrack/version.rb +1 -1
- data/spec/api/game_spec.rb +14 -1
- data/spec/api/login_spec.rb +5 -1
- data/spec/api/profile_spec.rb +10 -1
- data/spec/api/question_spec.rb +4 -0
- data/spec/api/user_spec.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92b5c77a56e170172762ed6a3c145743b913128803db0980fe500d23f355dfc8
|
4
|
+
data.tar.gz: 64e7b4d9ca31159378e038bcd5892a8caed86f053ad0550ac026d1d74ca6bad8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ab48a4eb4d28486d4a898bea402ece598b3643e0dad5ca2f19eddc35bbadf3a7aac55ac181d21949a88ea0bb18ccfeb9064ee63eb5231247c46f06e8cd94f15
|
7
|
+
data.tar.gz: ca05c593330b0b7ddad16214c3bedc8c3e211d0eba02004f17447832f09ae083fe5117e151fab833818b872e358bc350e3634c61ccb4e67fa63881542469df97
|
@@ -19,7 +19,7 @@ module TriviaCrack
|
|
19
19
|
response = Unirest.get "#{API_HOST}#{url}", parameters: parameters,
|
20
20
|
headers: default_headers
|
21
21
|
|
22
|
-
check_response response
|
22
|
+
check_response url, response
|
23
23
|
end
|
24
24
|
|
25
25
|
# Internal: Makes a POST request to the Trivia Crack API using the set of
|
@@ -34,7 +34,7 @@ module TriviaCrack
|
|
34
34
|
response = Unirest.post "#{API_HOST}#{url}", parameters: parameters,
|
35
35
|
headers: default_headers
|
36
36
|
|
37
|
-
check_response response
|
37
|
+
check_response url, response
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
@@ -63,10 +63,10 @@ module TriviaCrack
|
|
63
63
|
#
|
64
64
|
# Returns the response object.
|
65
65
|
# Raises TriviaCrack:Errors::RequestError if the request failed.
|
66
|
-
def check_response(response)
|
66
|
+
def check_response(url, response)
|
67
67
|
if not response.code.between? 200, 299
|
68
|
-
raise TriviaCrack::Errors::RequestError.new(response.code),
|
69
|
-
"Request to
|
68
|
+
raise TriviaCrack::Errors::RequestError.new(response.code, url, response.body),
|
69
|
+
"Request to #{API_HOST}#{url} failed with code #{response.code}."
|
70
70
|
end
|
71
71
|
|
72
72
|
response
|
@@ -7,11 +7,20 @@ module TriviaCrack
|
|
7
7
|
# Public: The HTTP status code returned by the Trivia Crack server.
|
8
8
|
attr_reader :code
|
9
9
|
|
10
|
+
#Public: The URL that was requested.
|
11
|
+
attr_reader :url
|
12
|
+
|
13
|
+
#Public: The response body that was returned by the Trivia Crack server.
|
14
|
+
attr_reader :body
|
15
|
+
|
10
16
|
# Public: Initializes a RequestError.
|
11
17
|
#
|
12
18
|
# code - The HTTP status code returned by the Trivia Crack server.
|
13
|
-
|
19
|
+
# url - The URL that was requested.
|
20
|
+
# body - The response body that was returned by the Trivia Crack server.
|
21
|
+
def initialize(code, url, body)
|
14
22
|
@code = code
|
23
|
+
@url = url
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
data/lib/triviacrack/version.rb
CHANGED
data/spec/api/game_spec.rb
CHANGED
@@ -27,12 +27,17 @@ describe TriviaCrack::API::Game do
|
|
27
27
|
let(:code) { 400 }
|
28
28
|
|
29
29
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
30
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
31
|
+
.and having_attributes(code: 400)) }
|
32
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
33
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/dashboard")) }
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
describe "#get_game" do
|
38
|
+
let(:game_id) { 123 }
|
34
39
|
|
35
|
-
subject { client.get_game
|
40
|
+
subject { client.get_game game_id }
|
36
41
|
|
37
42
|
let(:raw_data) { SpecData.get "game.json" }
|
38
43
|
|
@@ -47,6 +52,10 @@ describe TriviaCrack::API::Game do
|
|
47
52
|
let(:code) { 400 }
|
48
53
|
|
49
54
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
55
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
56
|
+
.and having_attributes(code: code)) }
|
57
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
58
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}")) }
|
50
59
|
end
|
51
60
|
end
|
52
61
|
|
@@ -67,6 +76,10 @@ describe TriviaCrack::API::Game do
|
|
67
76
|
let(:code) { 400 }
|
68
77
|
|
69
78
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
79
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
80
|
+
.and having_attributes(code: code)) }
|
81
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
82
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/games")) }
|
70
83
|
end
|
71
84
|
end
|
72
85
|
end
|
data/spec/api/login_spec.rb
CHANGED
@@ -25,10 +25,14 @@ describe TriviaCrack::API::Login do
|
|
25
25
|
its(:session_id) { is_expected.to eq "session123" }
|
26
26
|
end
|
27
27
|
|
28
|
-
context 'given that the request
|
28
|
+
context 'given that the request fails' do
|
29
29
|
let(:code) { 400 }
|
30
30
|
|
31
31
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
32
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
33
|
+
.and having_attributes(code: code)) }
|
34
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
35
|
+
.and having_attributes(url: '/api/login')) }
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
data/spec/api/profile_spec.rb
CHANGED
@@ -10,8 +10,9 @@ describe TriviaCrack::API::Profile do
|
|
10
10
|
before { allow(Unirest).to receive(:get) { response } }
|
11
11
|
|
12
12
|
describe "#get_profile" do
|
13
|
+
let(:user_id) { 111 }
|
13
14
|
|
14
|
-
subject { client.get_profile
|
15
|
+
subject { client.get_profile user_id }
|
15
16
|
|
16
17
|
let(:raw_data) { SpecData.get "profile.json" }
|
17
18
|
|
@@ -26,6 +27,10 @@ describe TriviaCrack::API::Profile do
|
|
26
27
|
let(:code) { 400 }
|
27
28
|
|
28
29
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
30
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
31
|
+
.and having_attributes(code: code)) }
|
32
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
33
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/profiles/#{user_id}")) }
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -46,6 +51,10 @@ describe TriviaCrack::API::Profile do
|
|
46
51
|
let(:code) { 400 }
|
47
52
|
|
48
53
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
54
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
55
|
+
.and having_attributes(code: code)) }
|
56
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
57
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/profiles/#{session.user_id}")) }
|
49
58
|
end
|
50
59
|
end
|
51
60
|
end
|
data/spec/api/question_spec.rb
CHANGED
@@ -40,6 +40,10 @@ describe TriviaCrack::API::Question do
|
|
40
40
|
let(:answer) { 1 }
|
41
41
|
|
42
42
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
43
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
44
|
+
.and having_attributes(code: code)) }
|
45
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
46
|
+
.and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")) }
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
data/spec/api/user_spec.rb
CHANGED
@@ -10,8 +10,9 @@ describe TriviaCrack::API::User do
|
|
10
10
|
before { allow(Unirest).to receive(:get) { response } }
|
11
11
|
|
12
12
|
describe "#get_user_id" do
|
13
|
+
let(:username) { "example.2" }
|
13
14
|
|
14
|
-
subject { client.get_user_id
|
15
|
+
subject { client.get_user_id username }
|
15
16
|
|
16
17
|
let(:raw_data) { SpecData.get "search.json" }
|
17
18
|
|
@@ -25,6 +26,10 @@ describe TriviaCrack::API::User do
|
|
25
26
|
let(:code) { 400 }
|
26
27
|
|
27
28
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
29
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
30
|
+
.and having_attributes(code: code)) }
|
31
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
32
|
+
.and having_attributes(url: "/api/search?username=#{username}")) }
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
@@ -45,6 +50,10 @@ describe TriviaCrack::API::User do
|
|
45
50
|
let(:code) { 400 }
|
46
51
|
|
47
52
|
it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
|
53
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
54
|
+
.and having_attributes(code: code)) }
|
55
|
+
it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
|
56
|
+
.and having_attributes(url: "/api/users/#{session.user_id}")) }
|
48
57
|
end
|
49
58
|
end
|
50
59
|
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.3.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: 2020-
|
11
|
+
date: 2020-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|