triviacrack 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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +19 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +120 -0
  8. data/Rakefile +7 -0
  9. data/lib/triviacrack.rb +12 -0
  10. data/lib/triviacrack/api/client.rb +31 -0
  11. data/lib/triviacrack/api/common.rb +76 -0
  12. data/lib/triviacrack/api/game.rb +72 -0
  13. data/lib/triviacrack/api/login.rb +35 -0
  14. data/lib/triviacrack/api/profile.rb +44 -0
  15. data/lib/triviacrack/api/question.rb +43 -0
  16. data/lib/triviacrack/api/user.rb +56 -0
  17. data/lib/triviacrack/category_statistics.rb +27 -0
  18. data/lib/triviacrack/errors/parse_error.rb +7 -0
  19. data/lib/triviacrack/errors/request_error.rb +18 -0
  20. data/lib/triviacrack/game.rb +100 -0
  21. data/lib/triviacrack/game_statistics.rb +35 -0
  22. data/lib/triviacrack/parsers/category_statistics_parser.rb +45 -0
  23. data/lib/triviacrack/parsers/game_parser.rb +74 -0
  24. data/lib/triviacrack/parsers/game_statistics_parser.rb +44 -0
  25. data/lib/triviacrack/parsers/profile_parser.rb +55 -0
  26. data/lib/triviacrack/parsers/question_parser.rb +36 -0
  27. data/lib/triviacrack/parsers/session_parser.rb +36 -0
  28. data/lib/triviacrack/parsers/time_parser.rb +26 -0
  29. data/lib/triviacrack/parsers/user_parser.rb +47 -0
  30. data/lib/triviacrack/profile.rb +96 -0
  31. data/lib/triviacrack/question.rb +43 -0
  32. data/lib/triviacrack/session.rb +30 -0
  33. data/lib/triviacrack/user.rb +91 -0
  34. data/lib/triviacrack/version.rb +4 -0
  35. data/spec/api/game_spec.rb +72 -0
  36. data/spec/api/login_spec.rb +34 -0
  37. data/spec/api/profile_spec.rb +51 -0
  38. data/spec/api/question_spec.rb +45 -0
  39. data/spec/api/user_spec.rb +50 -0
  40. data/spec/data/answer.json +161 -0
  41. data/spec/data/dashboard.json +949 -0
  42. data/spec/data/game.json +147 -0
  43. data/spec/data/login.json +25 -0
  44. data/spec/data/my_profile.json +556 -0
  45. data/spec/data/new_game.json +363 -0
  46. data/spec/data/profile.json +553 -0
  47. data/spec/data/question.json +14 -0
  48. data/spec/data/question_image.json +15 -0
  49. data/spec/data/search.json +123 -0
  50. data/spec/data/user.json +25 -0
  51. data/spec/game_spec.rb +60 -0
  52. data/spec/parsers/category_statistics_parser_spec.rb +41 -0
  53. data/spec/parsers/game_parser_spec.rb +114 -0
  54. data/spec/parsers/game_statistics_parser_spec.rb +56 -0
  55. data/spec/parsers/profile_parser_spec.rb +59 -0
  56. data/spec/parsers/question_parser_spec.rb +34 -0
  57. data/spec/parsers/session_parser_spec.rb +20 -0
  58. data/spec/parsers/time_parser_spec.rb +19 -0
  59. data/spec/parsers/user_parser_spec.rb +51 -0
  60. data/spec/spec_helper.rb +48 -0
  61. data/spec/user_spec.rb +33 -0
  62. data/triviacrack.gemspec +31 -0
  63. metadata +258 -0
@@ -0,0 +1,14 @@
1
+ {
2
+ "id":4227,
3
+ "category":"ENTERTAINMENT",
4
+ "text":"Who recorded this album?",
5
+ "answers":[
6
+ "Creedence Cleawater Revival",
7
+ "Bob Marley",
8
+ "blink-182",
9
+ "Jimmy Hendrix"
10
+ ],
11
+ "correct_answer":3,
12
+ "media_type":"NORMAL",
13
+ "type": "NORMAL"
14
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "id":4227,
3
+ "category":"ENTERTAINMENT",
4
+ "text":"Who recorded this album?",
5
+ "answers":[
6
+ "Creedence Cleawater Revival",
7
+ "Bob Marley",
8
+ "blink-182",
9
+ "Jimmy Hendrix"
10
+ ],
11
+ "correct_answer":3,
12
+ "media_type":"IMAGE",
13
+ "base_url":"http://qimg.preguntados.com/ENT_3028",
14
+ "type": "NORMAL"
15
+ }
@@ -0,0 +1,123 @@
1
+ {
2
+ "list": [{
3
+ "id": 111,
4
+ "allow_og_posts": true,
5
+ "username": "example.1",
6
+ "facebook_name": "Example 1",
7
+ "photo_url": "",
8
+ "is_app_user": true,
9
+ "facebook_id": "1",
10
+ "online_status": "ONLINE",
11
+ "fb_show_picture": true,
12
+ "twitter_name": "",
13
+ "fb_show_name": true
14
+ }, {
15
+ "id": 112,
16
+ "allow_og_posts": true,
17
+ "username": "example.2",
18
+ "facebook_name": "Example 2",
19
+ "photo_url": "",
20
+ "is_app_user": true,
21
+ "facebook_id": "2",
22
+ "online_status": "ONLINE",
23
+ "fb_show_picture": true,
24
+ "twitter_name": "",
25
+ "fb_show_name": true
26
+ }, {
27
+ "id": 113,
28
+ "allow_og_posts": true,
29
+ "username": "example.3",
30
+ "facebook_name": "Example 3",
31
+ "photo_url": "",
32
+ "is_app_user": true,
33
+ "facebook_id": "3",
34
+ "online_status": "ONLINE",
35
+ "fb_show_picture": true,
36
+ "twitter_name": "",
37
+ "fb_show_name": true
38
+ }, {
39
+ "id": 114,
40
+ "allow_og_posts": true,
41
+ "username": "example.4",
42
+ "facebook_name": "Example 4",
43
+ "photo_url": "",
44
+ "is_app_user": true,
45
+ "facebook_id": "4",
46
+ "online_status": "ONLINE",
47
+ "fb_show_picture": true,
48
+ "twitter_name": "",
49
+ "fb_show_name": true
50
+ }, {
51
+ "id": 115,
52
+ "allow_og_posts": true,
53
+ "username": "example.5",
54
+ "facebook_name": "Example 5.",
55
+ "photo_url": "",
56
+ "is_app_user": true,
57
+ "facebook_id": "5",
58
+ "online_status": "ONLINE",
59
+ "fb_show_picture": true,
60
+ "twitter_name": "",
61
+ "fb_show_name": true
62
+ }, {
63
+ "id": 116,
64
+ "allow_og_posts": true,
65
+ "username": "example.6",
66
+ "facebook_name": "Example 6",
67
+ "photo_url": "",
68
+ "is_app_user": true,
69
+ "facebook_id": "6",
70
+ "online_status": "ONLINE",
71
+ "fb_show_picture": true,
72
+ "twitter_name": "",
73
+ "fb_show_name": true
74
+ }, {
75
+ "id": 117,
76
+ "allow_og_posts": true,
77
+ "username": "example.7",
78
+ "facebook_name": "Example 7",
79
+ "photo_url": "",
80
+ "is_app_user": true,
81
+ "facebook_id": "7",
82
+ "online_status": "ONLINE",
83
+ "fb_show_picture": true,
84
+ "twitter_name": "",
85
+ "fb_show_name": true
86
+ }, {
87
+ "id": 118,
88
+ "allow_og_posts": true,
89
+ "username": "example.8",
90
+ "facebook_name": "Example 8",
91
+ "photo_url": "",
92
+ "is_app_user": true,
93
+ "facebook_id": "8",
94
+ "online_status": "ONLINE",
95
+ "fb_show_picture": true,
96
+ "twitter_name": "",
97
+ "fb_show_name": true
98
+ }, {
99
+ "id": 119,
100
+ "allow_og_posts": true,
101
+ "username": "example.9",
102
+ "facebook_name": "Example 9",
103
+ "photo_url": "",
104
+ "is_app_user": true,
105
+ "facebook_id": "9",
106
+ "online_status": "ONLINE",
107
+ "fb_show_picture": true,
108
+ "twitter_name": "",
109
+ "fb_show_name": true
110
+ }, {
111
+ "id": 120,
112
+ "allow_og_posts": true,
113
+ "username": "example.10",
114
+ "facebook_name": "Example 10",
115
+ "photo_url": "",
116
+ "is_app_user": true,
117
+ "facebook_id": "10",
118
+ "online_status": "ONLINE",
119
+ "fb_show_picture": true,
120
+ "twitter_name": "",
121
+ "fb_show_name": true
122
+ }]
123
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "id": 111,
3
+ "alerts_count": 0,
4
+ "username": "example",
5
+ "facebook_id": "1",
6
+ "facebook_name": "Example Name",
7
+ "fb_show_picture": true,
8
+ "fb_show_name": true,
9
+ "allow_og_posts": true,
10
+ "coins": 111,
11
+ "lives": {
12
+ "quantity": 3,
13
+ "max": 3,
14
+ "unlimited": false
15
+ },
16
+ "country": "CA",
17
+ "extra_shots": 3,
18
+ "level_data": {
19
+ "level": 31,
20
+ "points": 546,
21
+ "progress": 63,
22
+ "goal_points": 558,
23
+ "level_up": false
24
+ }
25
+ }
@@ -0,0 +1,60 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe TriviaCrack::Game do
4
+
5
+ let(:game_id) { 1111 }
6
+ let(:game) { TriviaCrack::Game.new id: game_id, my_turn: my_turn, game_status: game_status }
7
+
8
+ describe "#playable?" do
9
+
10
+ subject { game.playable? }
11
+
12
+ context 'when the game status is active' do
13
+ let(:game_status) { :active }
14
+
15
+ context 'and it is the users turn' do
16
+ let(:my_turn) { true }
17
+
18
+ it { is_expected.to be true }
19
+ end
20
+
21
+ context 'and it is not the users turn' do
22
+ let(:my_turn) { false }
23
+
24
+ it { is_expected.to be false }
25
+ end
26
+ end
27
+
28
+ context 'when the game status is pending_approval' do
29
+ let(:game_status) { :pending_approval }
30
+
31
+ context 'and it is the users turn' do
32
+ let(:my_turn) { true }
33
+
34
+ it { is_expected.to be true }
35
+ end
36
+
37
+ context 'and it is not the users turn' do
38
+ let(:my_turn) { false }
39
+
40
+ it { is_expected.to be false }
41
+ end
42
+ end
43
+
44
+ context 'when the game status is ended' do
45
+ let(:game_status) { :ended }
46
+
47
+ context 'and it is the users turn' do
48
+ let(:my_turn) { true }
49
+
50
+ it { is_expected.to be false }
51
+ end
52
+
53
+ context 'and it is not the users turn' do
54
+ let(:my_turn) { false }
55
+
56
+ it { is_expected.to be false }
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe TriviaCrack::Parsers::CategoryStatisticsParser do
4
+
5
+ describe ".parse" do
6
+
7
+ subject { TriviaCrack::Parsers::CategoryStatisticsParser.parse(category_data).values.first }
8
+
9
+ let(:category_data) { raw_data["statistics"]["player_one_statistics"]["category_questions"] }
10
+
11
+ context 'when given data from the games API' do
12
+ let(:raw_data) { SpecData.get "game.json" }
13
+
14
+ it { is_expected.to be_a TriviaCrack::CategoryStatistics }
15
+ its(:category) { is_expected.to be :geography }
16
+ its(:correct) { is_expected.to be 2 }
17
+ its(:incorrect) { is_expected.to be 1 }
18
+ its(:worst) { is_expected.to be false }
19
+ end
20
+
21
+ context 'when given data from the dashboard API' do
22
+ let(:raw_data) { SpecData.get("dashboard.json")["list"][3] }
23
+
24
+ it { is_expected.to be_a TriviaCrack::CategoryStatistics }
25
+ its(:category) { is_expected.to eq :arts }
26
+ its(:correct) { is_expected.to be 3 }
27
+ its(:incorrect) { is_expected.to be 0 }
28
+ its(:worst) { is_expected.to be false }
29
+ end
30
+
31
+ context 'when given data from the answers API' do
32
+ let(:raw_data) { SpecData.get "answer.json" }
33
+
34
+ it { is_expected.to be_a TriviaCrack::CategoryStatistics }
35
+ its(:category) { is_expected.to eq :sports }
36
+ its(:correct) { is_expected.to be 1 }
37
+ its(:incorrect) { is_expected.to be 0 }
38
+ its(:worst) { is_expected.to be false }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,114 @@
1
+ require "spec_helper"
2
+
3
+ describe TriviaCrack::Parsers::GameParser do
4
+
5
+ describe ".parse" do
6
+
7
+ subject { TriviaCrack::Parsers::GameParser.parse raw_data }
8
+
9
+ let(:game_data) { SpecData.get "game.json" }
10
+ let(:dashboard_data) { SpecData.get "dashboard.json" }
11
+ let(:answer_data) { SpecData.get "answer.json" }
12
+ let(:new_game_data) { SpecData.get "new_game.json" }
13
+
14
+ context 'when given data from the games API' do
15
+ let(:raw_data) { SpecData.get "game.json" }
16
+
17
+ it { is_expected.to be_a TriviaCrack::Game }
18
+ its(:id) { is_expected.to be 1111 }
19
+ its(:opponent) { is_expected.to be_a TriviaCrack::User }
20
+ its('opponent.id') { is_expected.to be 111 }
21
+ its(:game_status) { is_expected.to be :active }
22
+ its(:language) { is_expected.to be :en }
23
+ its(:created) { is_expected.to be_a Time }
24
+ its(:last_turn) { is_expected.to be_a Time }
25
+ its(:type) { is_expected.to be :normal }
26
+ its(:expiration_date) { is_expected.to be_a Time }
27
+ its(:my_turn) { is_expected.to be true }
28
+ its(:round_number) { is_expected.to be 4 }
29
+ its(:is_random) { is_expected.to be true }
30
+ its(:unread_messages) { is_expected.to be 0 }
31
+ its(:status_version) { is_expected.to be 23 }
32
+ its(:available_crowns) { is_expected.to contain_exactly(:entertainment, :arts, :sports) }
33
+ its('questions.first') { is_expected.to be_a TriviaCrack::Question }
34
+ its('questions.first.id') { is_expected.to be 16653413 }
35
+ its(:my_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
36
+ its(:opponent_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
37
+ end
38
+
39
+ context 'when given data from the dashboard API' do
40
+ let(:raw_data) { SpecData.get("dashboard.json")["list"][3] }
41
+
42
+ it { is_expected.to be_a TriviaCrack::Game }
43
+ its(:id) { is_expected.to be 1115 }
44
+ its(:opponent) { is_expected.to be_a TriviaCrack::User }
45
+ its('opponent.id') { is_expected.to be 114 }
46
+ its(:game_status) { is_expected.to be :active }
47
+ its(:language) { is_expected.to be :en }
48
+ its(:created) { is_expected.to be_a Time }
49
+ its(:last_turn) { is_expected.to be_a Time }
50
+ its(:type) { is_expected.to be :normal }
51
+ its(:expiration_date) { is_expected.to be_a Time }
52
+ its(:my_turn) { is_expected.to be true }
53
+ its(:round_number) { is_expected.to be 4 }
54
+ its(:is_random) { is_expected.to be true }
55
+ its(:unread_messages) { is_expected.to be 0 }
56
+ its(:status_version) { is_expected.to be 24 }
57
+ its(:available_crowns) { is_expected.to contain_exactly(:entertainment, :arts, :sports) }
58
+ its('questions.first') { is_expected.to be_a TriviaCrack::Question }
59
+ its('questions.first.id') { is_expected.to be 15593975 }
60
+ its(:my_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
61
+ its(:opponent_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
62
+ end
63
+
64
+ context 'when given data from the answers API' do
65
+ let(:raw_data) { SpecData.get "answer.json" }
66
+
67
+ it { is_expected.to be_a TriviaCrack::Game }
68
+ its(:id) { is_expected.to be 1111 }
69
+ its(:opponent) { is_expected.to be_a TriviaCrack::User }
70
+ its('opponent.id') { is_expected.to be 111 }
71
+ its(:game_status) { is_expected.to be :active }
72
+ its(:language) { is_expected.to be :en }
73
+ its(:created) { is_expected.to be_a Time }
74
+ its(:last_turn) { is_expected.to be_a Time }
75
+ its(:type) { is_expected.to be :normal }
76
+ its(:expiration_date) { is_expected.to be_a Time }
77
+ its(:my_turn) { is_expected.to be true }
78
+ its(:round_number) { is_expected.to be 4 }
79
+ its(:is_random) { is_expected.to be true }
80
+ its(:unread_messages) { is_expected.to be 0 }
81
+ its(:status_version) { is_expected.to be 24 }
82
+ its(:available_crowns) { is_expected.to contain_exactly(:entertainment, :arts, :sports) }
83
+ its('questions.first') { is_expected.to be_a TriviaCrack::Question }
84
+ its('questions.first.id') { is_expected.to be 15593975 }
85
+ its(:my_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
86
+ its(:opponent_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
87
+ end
88
+
89
+ context 'when given data from the new game API' do
90
+ let(:raw_data) { SpecData.get "new_game.json" }
91
+
92
+ it { is_expected.to be_a TriviaCrack::Game }
93
+ its(:id) { is_expected.to be 2222 }
94
+ its(:opponent) { is_expected.to be_a TriviaCrack::User }
95
+ its('opponent.id') { is_expected.to be 0 }
96
+ its(:game_status) { is_expected.to be :pending_approval }
97
+ its(:language) { is_expected.to be :en }
98
+ its(:created) { is_expected.to be_a Time }
99
+ its(:last_turn) { is_expected.to be_a Time }
100
+ its(:type) { is_expected.to be :normal }
101
+ its(:expiration_date) { is_expected.to be_a Time }
102
+ its(:my_turn) { is_expected.to be true }
103
+ its(:round_number) { is_expected.to be 1 }
104
+ its(:is_random) { is_expected.to be true }
105
+ its(:unread_messages) { is_expected.to be 0 }
106
+ its(:status_version) { is_expected.to be 0 }
107
+ its(:available_crowns) { is_expected.to contain_exactly(:arts, :entertainment, :geography, :history, :science, :sports) }
108
+ its('questions.first') { is_expected.to be_a TriviaCrack::Question }
109
+ its('questions.first.id') { is_expected.to be 12785 }
110
+ its(:my_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
111
+ its(:opponent_statistics) { is_expected.to be_a TriviaCrack::GameStatistics }
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe TriviaCrack::Parsers::GameStatisticsParser do
4
+
5
+ describe ".parse" do
6
+
7
+ subject { TriviaCrack::Parsers::GameStatisticsParser.parse statistics_data }
8
+
9
+ let(:statistics_data) { raw_data["statistics"]["player_one_statistics"] }
10
+ before { statistics_data["crowns"] = raw_data["player_one"]["crowns"] }
11
+
12
+ context 'when given data from the games API' do
13
+ let(:raw_data) { SpecData.get "game.json" }
14
+
15
+ it { is_expected.to be_a TriviaCrack::GameStatistics }
16
+ its(:correct_answers) { is_expected.to be 12 }
17
+ its(:incorrect_answers) { is_expected.to be 3 }
18
+ its(:challenges_won) { is_expected.to be 0 }
19
+ its(:questions_answered) { is_expected.to be 15 }
20
+ its(:crowns) { is_expected.to contain_exactly :history, :science, :geography }
21
+ end
22
+
23
+ context 'when given data from the dashboard API' do
24
+ let(:raw_data) { SpecData.get("dashboard.json")["list"][3] }
25
+
26
+ it { is_expected.to be_a TriviaCrack::GameStatistics }
27
+ its(:correct_answers) { is_expected.to be 13 }
28
+ its(:incorrect_answers) { is_expected.to be 3 }
29
+ its(:challenges_won) { is_expected.to be 0 }
30
+ its(:questions_answered) { is_expected.to be 16 }
31
+ its(:crowns) { is_expected.to contain_exactly :history, :science, :geography }
32
+ end
33
+
34
+ context 'when given data from the answer API' do
35
+ let(:raw_data) { SpecData.get "answer.json" }
36
+
37
+ it { is_expected.to be_a TriviaCrack::GameStatistics }
38
+ its(:correct_answers) { is_expected.to be 13 }
39
+ its(:incorrect_answers) { is_expected.to be 3 }
40
+ its(:challenges_won) { is_expected.to be 0 }
41
+ its(:questions_answered) { is_expected.to be 16 }
42
+ its(:crowns) { is_expected.to contain_exactly :history, :science, :geography }
43
+ end
44
+
45
+ context 'when given data from the new game API' do
46
+ let(:raw_data) { SpecData.get "new_game.json" }
47
+
48
+ it { is_expected.to be_a TriviaCrack::GameStatistics }
49
+ its(:correct_answers) { is_expected.to be 0 }
50
+ its(:incorrect_answers) { is_expected.to be 0 }
51
+ its(:challenges_won) { is_expected.to be 0 }
52
+ its(:questions_answered) { is_expected.to be 0 }
53
+ its(:crowns) { is_expected.to be_empty}
54
+ end
55
+ end
56
+ end