kag 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.kag2d.com/player/prostosuper/info
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 301
13
+ message: Moved Permanently
14
+ headers:
15
+ Server:
16
+ - nginx/1.0.5
17
+ Date:
18
+ - Thu, 26 Apr 2012 12:26:50 GMT
19
+ Content-Type:
20
+ - application/json
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Location:
26
+ - https://api.kag2d.com/player/prostosuper/info
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ''
30
+ http_version:
31
+ recorded_at: Thu, 26 Apr 2012 12:26:45 GMT
32
+ - request:
33
+ method: get
34
+ uri: https://api.kag2d.com/player/prostosuper/info
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ headers: {}
39
+ response:
40
+ status:
41
+ code: 200
42
+ message: OK
43
+ headers:
44
+ Server:
45
+ - nginx/1.0.5
46
+ Date:
47
+ - Thu, 26 Apr 2012 12:26:50 GMT
48
+ Content-Type:
49
+ - application/json
50
+ Transfer-Encoding:
51
+ - chunked
52
+ Connection:
53
+ - keep-alive
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ! '{"active": true, "username": "prostosuper", "banned": false, "role":
57
+ 0, "gold": true}'
58
+ http_version:
59
+ recorded_at: Thu, 26 Apr 2012 12:26:46 GMT
60
+ recorded_with: VCR 2.1.1
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.kag2d.com/player/prostosuper/info
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 301
13
+ message: Moved Permanently
14
+ headers:
15
+ Server:
16
+ - nginx/1.0.5
17
+ Date:
18
+ - Fri, 27 Apr 2012 09:24:12 GMT
19
+ Content-Type:
20
+ - application/json
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Location:
26
+ - https://api.kag2d.com/player/prostosuper/info
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ''
30
+ http_version:
31
+ recorded_at: Fri, 27 Apr 2012 09:24:06 GMT
32
+ - request:
33
+ method: get
34
+ uri: https://api.kag2d.com/player/prostosuper/info
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ headers: {}
39
+ response:
40
+ status:
41
+ code: 200
42
+ message: OK
43
+ headers:
44
+ Server:
45
+ - nginx/1.0.5
46
+ Date:
47
+ - Fri, 27 Apr 2012 09:24:12 GMT
48
+ Content-Type:
49
+ - application/json
50
+ Transfer-Encoding:
51
+ - chunked
52
+ Connection:
53
+ - keep-alive
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ! '{"active": true, "username": "prostosuper", "banned": false, "role":
57
+ 0, "gold": true}'
58
+ http_version:
59
+ recorded_at: Fri, 27 Apr 2012 09:24:06 GMT
60
+ recorded_with: VCR 2.1.1
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.kag2d.com/player/flieslikeabrick/info
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 301
13
+ message: Moved Permanently
14
+ headers:
15
+ Server:
16
+ - nginx/1.0.5
17
+ Date:
18
+ - Thu, 26 Apr 2012 12:26:51 GMT
19
+ Content-Type:
20
+ - application/json
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Location:
26
+ - https://api.kag2d.com/player/flieslikeabrick/info
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ''
30
+ http_version:
31
+ recorded_at: Thu, 26 Apr 2012 12:26:46 GMT
32
+ - request:
33
+ method: get
34
+ uri: https://api.kag2d.com/player/flieslikeabrick/info
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ headers: {}
39
+ response:
40
+ status:
41
+ code: 200
42
+ message: OK
43
+ headers:
44
+ Server:
45
+ - nginx/1.0.5
46
+ Date:
47
+ - Thu, 26 Apr 2012 12:26:52 GMT
48
+ Content-Type:
49
+ - application/json
50
+ Transfer-Encoding:
51
+ - chunked
52
+ Connection:
53
+ - keep-alive
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ! '{"active": true, "username": "FliesLikeABrick", "banned": false,
57
+ "role": 4, "gold": true}'
58
+ http_version:
59
+ recorded_at: Thu, 26 Apr 2012 12:26:47 GMT
60
+ recorded_with: VCR 2.1.1
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.kag2d.com/player/incarnum/info
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 301
13
+ message: Moved Permanently
14
+ headers:
15
+ Server:
16
+ - nginx/1.0.5
17
+ Date:
18
+ - Thu, 26 Apr 2012 12:26:52 GMT
19
+ Content-Type:
20
+ - application/json
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Location:
26
+ - https://api.kag2d.com/player/incarnum/info
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ''
30
+ http_version:
31
+ recorded_at: Thu, 26 Apr 2012 12:26:47 GMT
32
+ - request:
33
+ method: get
34
+ uri: https://api.kag2d.com/player/incarnum/info
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ headers: {}
39
+ response:
40
+ status:
41
+ code: 200
42
+ message: OK
43
+ headers:
44
+ Server:
45
+ - nginx/1.0.5
46
+ Date:
47
+ - Thu, 26 Apr 2012 12:26:53 GMT
48
+ Content-Type:
49
+ - application/json
50
+ Transfer-Encoding:
51
+ - chunked
52
+ Connection:
53
+ - keep-alive
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ! '{"active": true, "username": "incarnum", "banned": false, "role":
57
+ 5, "gold": true}'
58
+ http_version:
59
+ recorded_at: Thu, 26 Apr 2012 12:26:48 GMT
60
+ recorded_with: VCR 2.1.1
@@ -0,0 +1,133 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe KAG::Player::Avatar do
4
+
5
+ describe 'GET avatar info' do
6
+ let (:avatar) { KAG::Player::Avatar.new('prostosuper') }
7
+
8
+ before do
9
+ VCR.insert_cassette 'avatar', :record => :new_episodes
10
+ end
11
+
12
+ after do
13
+ VCR.eject_cassette
14
+ end
15
+
16
+ it 'records the fixture' do
17
+ KAG.get('/player/prostosuper/avatar')
18
+ end
19
+
20
+ it 'must have the sizes method' do
21
+ avatar.must_respond_to :sizes
22
+ end
23
+
24
+ it 'must parse the API response from JSON to Hash' do
25
+ avatar.sizes.must_be_instance_of Hash
26
+ end
27
+
28
+ it 'must perform request and get the small avatar URL' do
29
+ avatar.sizes['small'].must_equal 'https://forum.kag2d.com/data/avatars/s/0/231.jpg'
30
+ end
31
+
32
+ it 'must perform request and get the medium avatar URL' do
33
+ avatar.sizes['medium'].must_equal 'https://forum.kag2d.com/data/avatars/m/0/231.jpg'
34
+ end
35
+
36
+ it 'must perform request and get the large avatar URL' do
37
+ avatar.sizes['large'].must_equal 'https://forum.kag2d.com/data/avatars/l/0/231.jpg'
38
+ end
39
+
40
+ describe 'GET specific avatar sizes' do
41
+
42
+ describe 'small size' do
43
+ before do
44
+ VCR.insert_cassette 'avatar_s', :record => :new_episodes
45
+ end
46
+
47
+ after do
48
+ VCR.eject_cassette
49
+ end
50
+
51
+ it 'records the fixture' do
52
+ KAG.get('/player/prostosuper/avatar/s')
53
+ end
54
+
55
+ it 'must retrieve only small avatar size' do
56
+ avatar.small.must_equal 'https://forum.kag2d.com/data/avatars/s/0/231.jpg'
57
+ end
58
+ end
59
+
60
+ describe 'medium size' do
61
+ before do
62
+ VCR.insert_cassette 'avatar_m', :record => :new_episodes
63
+ end
64
+
65
+ after do
66
+ VCR.eject_cassette
67
+ end
68
+
69
+ it 'records the fixture' do
70
+ KAG.get('/player/prostosuper/avatar/m')
71
+ end
72
+
73
+ it 'must retrieve only medium avatar size' do
74
+ avatar.medium.must_equal 'https://forum.kag2d.com/data/avatars/m/0/231.jpg'
75
+ end
76
+ end
77
+
78
+ describe 'large size' do
79
+ before do
80
+ VCR.insert_cassette 'avatar_l', :record => :new_episodes
81
+ end
82
+
83
+ after do
84
+ VCR.eject_cassette
85
+ end
86
+
87
+ it 'records the fixture' do
88
+ KAG.get('/player/prostosuper/avatar/l')
89
+ end
90
+
91
+ it 'must retrieve only large avatar size' do
92
+ avatar.large.must_equal 'https://forum.kag2d.com/data/avatars/l/0/231.jpg'
93
+ end
94
+ end
95
+
96
+ end # GET specific sizes
97
+
98
+ describe 'nonexistent avatar nick' do
99
+ let (:avatar) { KAG::Player::Avatar.new('foobarbazbaz') }
100
+
101
+ it 'must return statusMessage telling that player not found' do
102
+ not_found_message = 'Player not found'
103
+
104
+ avatar.small['statusMessage'].must_equal not_found_message
105
+ avatar.medium['statusMessage'].must_equal not_found_message
106
+ avatar.large['statusMessage'].must_equal not_found_message
107
+ avatar.sizes['statusMessage'].must_equal not_found_message
108
+
109
+ avatar.sizes['small'].must_be_nil
110
+ avatar.sizes['medium'].must_be_nil
111
+ avatar.sizes['large'].must_be_nil
112
+ end
113
+ end
114
+
115
+ describe 'caching' do
116
+ before do
117
+ avatar.sizes
118
+ stub_request(:any, /api.kag2d.com/).to_timeout
119
+ end
120
+
121
+ it 'must cache sizes' do
122
+ avatar.sizes.must_be_instance_of Hash
123
+ end
124
+
125
+ it 'must refresh sizes if forced' do
126
+ lambda { avatar.sizes(true) }.must_raise Timeout::Error
127
+ end
128
+ end
129
+
130
+
131
+ end # GET avatar info
132
+
133
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe KAG do
4
+
5
+ describe 'default attributes' do
6
+ it 'must include HTTPparty methods' do
7
+ KAG.must_include HTTParty
8
+ end
9
+
10
+ it 'must have the base URL set to the KAG API' do
11
+ KAG.base_uri.must_equal 'http://api.kag2d.com'
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,258 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe KAG::Player do
4
+
5
+ describe 'default instance attributes' do
6
+ let(:player) { KAG::Player.new('prostosuper') }
7
+
8
+ before do
9
+ VCR.insert_cassette 'avatar', :record => :none
10
+ end
11
+
12
+ after do
13
+ VCR.eject_cassette
14
+ end
15
+
16
+ it 'must have an id attribute' do
17
+ player.must_respond_to :nick
18
+ end
19
+
20
+ it 'must have the right id' do
21
+ player.nick.must_equal 'prostosuper'
22
+ end
23
+
24
+ it 'must have avatar attribute' do
25
+ player.must_respond_to :avatar
26
+ end
27
+
28
+ it 'must have the right avatar' do
29
+ player.avatar.small.must_equal 'https://forum.kag2d.com/data/avatars/s/0/231.jpg'
30
+ end
31
+ end
32
+
33
+ describe 'GET info' do
34
+ let (:player) { KAG::Player.new('prostosuper') }
35
+
36
+ before do
37
+ VCR.insert_cassette 'player', :record => :new_episodes
38
+ end
39
+
40
+ after do
41
+ VCR.eject_cassette
42
+ end
43
+
44
+ it 'records the fixture' do
45
+ KAG.get('/player/prostosuper/info')
46
+ end
47
+
48
+ it 'must have the info method' do
49
+ player.must_respond_to :info
50
+ end
51
+
52
+ it 'must parse the API response from JSON to Hash' do
53
+ player.info.must_be_instance_of Hash
54
+ end
55
+
56
+ it 'must perform the request and get the info' do
57
+ player.info['username'].must_equal 'prostosuper'
58
+ end
59
+
60
+ describe 'JSON player attributes' do
61
+ before do
62
+ player.info
63
+ end
64
+
65
+ it 'must return status of the player (active or not)' do
66
+ player.active?.must_equal true
67
+ end
68
+
69
+ it 'must return username of the player' do
70
+ player.username.must_equal 'prostosuper'
71
+ end
72
+
73
+ it 'must return ban status of the player (banned or not)' do
74
+ player.banned?.must_equal false
75
+ end
76
+
77
+ it 'must return account status (gold or not)' do
78
+ player.gold?.must_equal true
79
+ end
80
+
81
+ describe 'banned players' do
82
+ let (:banned_player) { KAG::Player.new('tiffou') }
83
+
84
+ before do
85
+ VCR.insert_cassette 'banned_player', :record => :new_episodes
86
+ end
87
+
88
+ after do
89
+ VCR.eject_cassette
90
+ end
91
+
92
+ it 'records the fixture' do
93
+ KAG.get('/player/tiffou/info')
94
+ end
95
+
96
+ it 'must return DateTime for ban expiration date' do
97
+ banned_player.ban_expiration.must_be_instance_of DateTime
98
+ end
99
+
100
+ it 'must return ban expiration date' do
101
+ banned_player.ban_expiration.must_equal DateTime.parse('2022/03/02 09:09:53')
102
+ end
103
+
104
+ it 'must return String for ban reason' do
105
+ banned_player.ban_reason.must_be_instance_of String
106
+ end
107
+
108
+ it 'must return ban reason' do
109
+ banned_player.ban_reason.must_equal 'cheating - speedhack.'
110
+ end
111
+ end
112
+
113
+ describe 'roles' do
114
+
115
+ describe 'normal role' do
116
+ let(:normal) { KAG::Player.new('prostosuper') }
117
+
118
+ before do
119
+ VCR.insert_cassette 'normal', :record => :new_episodes
120
+ end
121
+
122
+ after do
123
+ VCR.eject_cassette
124
+ end
125
+
126
+ it 'records the fixture' do
127
+ KAG.get('/player/prostosuper/info')
128
+ end
129
+
130
+ it 'must return numeric role of the player' do
131
+ normal.role.must_equal 0
132
+ end
133
+
134
+ it 'must return human-readable role of the player' do
135
+ normal.role(true).must_equal 'normal'
136
+ end
137
+ end
138
+
139
+ describe 'developer role' do
140
+ let(:developer) { KAG::Player.new('mm') }
141
+
142
+ before do
143
+ VCR.insert_cassette 'developer', :record => :new_episodes
144
+ end
145
+
146
+ after do
147
+ VCR.eject_cassette
148
+ end
149
+
150
+ it 'records the fixture' do
151
+ KAG.get('/player/mm/info')
152
+ end
153
+
154
+ it 'must return numeric role of the player' do
155
+ developer.role.must_equal 1
156
+ end
157
+
158
+ it 'must return human-readable role of the player' do
159
+ developer.role(true).must_equal 'developer'
160
+ end
161
+ end
162
+
163
+ describe 'guard role' do
164
+ let(:guard) { KAG::Player.new('dnmr') }
165
+
166
+ before do
167
+ VCR.insert_cassette 'guard', :record => :new_episodes
168
+ end
169
+
170
+ after do
171
+ VCR.eject_cassette
172
+ end
173
+
174
+ it 'records the fixture' do
175
+ KAG.get('/player/dnmr/info')
176
+ end
177
+
178
+ it 'must return numeric role of the player' do
179
+ guard.role.must_equal 2
180
+ end
181
+
182
+ it 'must return human-readable role of the player' do
183
+ guard.role(true).must_equal 'guard'
184
+ end
185
+ end
186
+
187
+ # KAG Staff role is undecided: https://wiki.kag2d.com/wiki/Role
188
+ # describe 'staff role' do
189
+ # end
190
+
191
+ describe 'team member role' do
192
+ let(:team_member) { KAG::Player.new('flieslikeabrick') }
193
+
194
+ before do
195
+ VCR.insert_cassette 'team_member', :record => :new_episodes
196
+ end
197
+
198
+ after do
199
+ VCR.eject_cassette
200
+ end
201
+
202
+ it 'records the fixture' do
203
+ KAG.get('/player/flieslikeabrick/info')
204
+ end
205
+
206
+ it 'must return numeric role of the player' do
207
+ team_member.role.must_equal 4
208
+ end
209
+
210
+ it 'must return human-readable role of the player' do
211
+ team_member.role(true).must_equal 'team member'
212
+ end
213
+ end
214
+
215
+ describe 'tester role' do
216
+ let(:tester) { KAG::Player.new('incarnum') }
217
+
218
+ before do
219
+ VCR.insert_cassette 'tester', :record => :new_episodes
220
+ end
221
+
222
+ after do
223
+ VCR.eject_cassette
224
+ end
225
+
226
+ it 'records the fixture' do
227
+ KAG.get('/player/incarnum/info')
228
+ end
229
+
230
+ it 'must return numeric role of the player' do
231
+ tester.role.must_equal 5
232
+ end
233
+
234
+ it 'must return human-readable role of the player' do
235
+ tester.role(true).must_equal 'tester'
236
+ end
237
+
238
+ end
239
+ end # roles
240
+ end # JSON player attributes
241
+
242
+ describe 'caching' do
243
+ before do
244
+ player.info
245
+ stub_request(:any, /api.kag2d.com/).to_timeout
246
+ end
247
+
248
+ it 'must cache the info' do
249
+ player.info.must_be_instance_of Hash
250
+ end
251
+
252
+ it 'must refresh the info if forced' do
253
+ lambda { player.info(true) }.must_raise Timeout::Error
254
+ end
255
+ end
256
+ end
257
+
258
+ end