badgeapi 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +15 -0
- data/badgeapi.gemspec +33 -0
- data/lib/badgeapi/badge.rb +29 -0
- data/lib/badgeapi/badgeapi_object.rb +149 -0
- data/lib/badgeapi/collection.rb +10 -0
- data/lib/badgeapi/errors/api_error.rb +5 -0
- data/lib/badgeapi/errors/badgeapi_error.rb +18 -0
- data/lib/badgeapi/errors/invalid_request_error.rb +5 -0
- data/lib/badgeapi/recipient.rb +18 -0
- data/lib/badgeapi/version.rb +3 -0
- data/lib/badgeapi.rb +36 -0
- data/test/badge/badge_test.rb +469 -0
- data/test/badgeapi_test.rb +20 -0
- data/test/collection/collection_test.rb +275 -0
- data/test/fixtures/all_badges.yml +121 -0
- data/test/fixtures/all_badges_bad_user.yml +138 -0
- data/test/fixtures/all_badges_expanded.yml +196 -0
- data/test/fixtures/all_badges_from_collection.yml +52 -0
- data/test/fixtures/all_badges_issued.yml +430 -0
- data/test/fixtures/all_badges_limited.yml +49 -0
- data/test/fixtures/all_collection.yml +50 -0
- data/test/fixtures/all_collection_expanded.yml +131 -0
- data/test/fixtures/all_collection_limit.yml +49 -0
- data/test/fixtures/bad_Recipient.yml +183 -0
- data/test/fixtures/bad_Recipietn_request.yml +93 -0
- data/test/fixtures/bad_api_key.yml +49 -0
- data/test/fixtures/badge_error.yml +47 -0
- data/test/fixtures/badge_requirements.yml +351 -0
- data/test/fixtures/collection_error.yml +91 -0
- data/test/fixtures/create_badge.yml +97 -0
- data/test/fixtures/create_collection.yml +97 -0
- data/test/fixtures/create_new_badge_failure.yml +143 -0
- data/test/fixtures/create_new_collection_failure.yml +189 -0
- data/test/fixtures/destroy_badge.yml +277 -0
- data/test/fixtures/destroy_badge_error.yml +231 -0
- data/test/fixtures/destroy_collection.yml +185 -0
- data/test/fixtures/destroy_collection_error.yml +185 -0
- data/test/fixtures/issue_already_owned_badge.yml +49 -0
- data/test/fixtures/issue_badge_to_bad_user.yml +50 -0
- data/test/fixtures/issue_badge_to_user.yml +199 -0
- data/test/fixtures/issue_badge_to_user_with_library_card.yml +103 -0
- data/test/fixtures/one_badge.yml +49 -0
- data/test/fixtures/one_badge_expanded.yml +50 -0
- data/test/fixtures/one_collection.yml +49 -0
- data/test/fixtures/one_collection_expanded.yml +104 -0
- data/test/fixtures/recipient_with_badges.yml +187 -0
- data/test/fixtures/recipient_with_badges_unicard.yml +50 -0
- data/test/fixtures/revoke_badge_from_user.yml +199 -0
- data/test/fixtures/revoke_badge_not_issued.yml +49 -0
- data/test/fixtures/update_badge_via_update.yml +145 -0
- data/test/fixtures/update_badge_via_update_slug_history.yml +191 -0
- data/test/fixtures/update_collection.yml +191 -0
- data/test/fixtures/update_collection_via_update.yml +145 -0
- data/test/recipient/recipient_test.rb +108 -0
- data/test/test_helper.rb +11 -0
- metadata +274 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://gamification-api.dev/v1/badges
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: badge%5Bcollection_id%5D=1&badge%5Bdescription%5D=This+is+a+new+badge&badge%5Bhint%5D=Love+us..&badge%5Blevel%5D=bronze&badge%5Bname%5D=Create+Badge+for+update&badge%5Brequirements%5D=You+need+to+love+the+Badge+API
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Authorization:
|
13
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 201
|
23
|
+
message: Created
|
24
|
+
headers:
|
25
|
+
X-Frame-Options:
|
26
|
+
- SAMEORIGIN
|
27
|
+
X-Xss-Protection:
|
28
|
+
- 1; mode=block
|
29
|
+
X-Content-Type-Options:
|
30
|
+
- nosniff
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Etag:
|
34
|
+
- '"174370f656ce2bf2ac00d179859459cb"'
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
X-Request-Id:
|
38
|
+
- ced0ec41-5b1e-4081-8868-4bab646cf169
|
39
|
+
X-Runtime:
|
40
|
+
- '0.071541'
|
41
|
+
Date:
|
42
|
+
- Thu, 03 Sep 2015 10:56:01 GMT
|
43
|
+
Connection:
|
44
|
+
- close
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"name":"Create Badge for update","description":"This is a new badge","requirements":"You
|
48
|
+
need to love the Badge API","hint":"Love us..","image":"http://gamification-api.dev/badge_images/create-badge-for-update/badge.png","collection_id":"library","created_at":"2015-09-03T10:56:01.214Z","updated_at":"2015-09-03T10:56:01.214Z","level":"bronze","auto_issue":false,"status":"draft","required_badges":[],"points":25,"object":"badge","id":"create-badge-for-update"}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Thu, 03 Sep 2015 10:56:01 GMT
|
51
|
+
- request:
|
52
|
+
method: patch
|
53
|
+
uri: http://gamification-api.dev/v1/badges/create-badge-for-update
|
54
|
+
body:
|
55
|
+
encoding: UTF-8
|
56
|
+
string: badge%5Bcollection_id%5D=trim-trail&badge%5Bdescription%5D=Updated+Description&badge%5Bhint%5D=Updated+Hint&badge%5Bname%5D=Updated+Badge&badge%5Brequirements%5D=Updated+Requirements
|
57
|
+
headers:
|
58
|
+
User-Agent:
|
59
|
+
- Faraday v0.9.1
|
60
|
+
Authorization:
|
61
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
62
|
+
Content-Type:
|
63
|
+
- application/x-www-form-urlencoded
|
64
|
+
Accept-Encoding:
|
65
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
66
|
+
Accept:
|
67
|
+
- "*/*"
|
68
|
+
response:
|
69
|
+
status:
|
70
|
+
code: 200
|
71
|
+
message: OK
|
72
|
+
headers:
|
73
|
+
X-Frame-Options:
|
74
|
+
- SAMEORIGIN
|
75
|
+
X-Xss-Protection:
|
76
|
+
- 1; mode=block
|
77
|
+
X-Content-Type-Options:
|
78
|
+
- nosniff
|
79
|
+
Content-Type:
|
80
|
+
- application/json; charset=utf-8
|
81
|
+
Etag:
|
82
|
+
- '"16df778d53540ec72b860dcfbf86fae0"'
|
83
|
+
Cache-Control:
|
84
|
+
- max-age=0, private, must-revalidate
|
85
|
+
X-Request-Id:
|
86
|
+
- 6b2e1586-be7d-4fc9-b2cb-8ccb74a9c26b
|
87
|
+
X-Runtime:
|
88
|
+
- '0.073083'
|
89
|
+
Date:
|
90
|
+
- Thu, 03 Sep 2015 10:56:01 GMT
|
91
|
+
Connection:
|
92
|
+
- close
|
93
|
+
body:
|
94
|
+
encoding: UTF-8
|
95
|
+
string: '{"name":"Updated Badge","description":"Updated Description","requirements":"Updated
|
96
|
+
Requirements","hint":"Updated Hint","image":"http://gamification-api.dev/badge_images/updated-badge/badge.png","collection_id":"trim-trail","created_at":"2015-09-03T10:56:01.214Z","updated_at":"2015-09-03T10:56:01.301Z","level":"bronze","auto_issue":false,"status":"draft","required_badges":[],"points":25,"object":"badge","id":"updated-badge"}'
|
97
|
+
http_version:
|
98
|
+
recorded_at: Thu, 03 Sep 2015 10:56:01 GMT
|
99
|
+
- request:
|
100
|
+
method: get
|
101
|
+
uri: http://gamification-api.dev/v1/badges/create-badge-for-update
|
102
|
+
body:
|
103
|
+
encoding: US-ASCII
|
104
|
+
string: ''
|
105
|
+
headers:
|
106
|
+
User-Agent:
|
107
|
+
- Faraday v0.9.1
|
108
|
+
Authorization:
|
109
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
110
|
+
Accept-Encoding:
|
111
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
112
|
+
Accept:
|
113
|
+
- "*/*"
|
114
|
+
response:
|
115
|
+
status:
|
116
|
+
code: 200
|
117
|
+
message: OK
|
118
|
+
headers:
|
119
|
+
X-Frame-Options:
|
120
|
+
- SAMEORIGIN
|
121
|
+
X-Xss-Protection:
|
122
|
+
- 1; mode=block
|
123
|
+
X-Content-Type-Options:
|
124
|
+
- nosniff
|
125
|
+
Content-Type:
|
126
|
+
- application/json; charset=utf-8
|
127
|
+
Etag:
|
128
|
+
- '"16df778d53540ec72b860dcfbf86fae0"'
|
129
|
+
Cache-Control:
|
130
|
+
- max-age=0, private, must-revalidate
|
131
|
+
X-Request-Id:
|
132
|
+
- ad53f14c-71bd-4450-8d7b-2a46de6951e6
|
133
|
+
X-Runtime:
|
134
|
+
- '0.013193'
|
135
|
+
Date:
|
136
|
+
- Thu, 03 Sep 2015 10:56:01 GMT
|
137
|
+
Connection:
|
138
|
+
- close
|
139
|
+
body:
|
140
|
+
encoding: UTF-8
|
141
|
+
string: '{"name":"Updated Badge","description":"Updated Description","requirements":"Updated
|
142
|
+
Requirements","hint":"Updated Hint","image":"http://gamification-api.dev/badge_images/updated-badge/badge.png","collection_id":"trim-trail","created_at":"2015-09-03T10:56:01.214Z","updated_at":"2015-09-03T10:56:01.301Z","level":"bronze","auto_issue":false,"status":"draft","required_badges":[],"points":25,"object":"badge","id":"updated-badge"}'
|
143
|
+
http_version:
|
144
|
+
recorded_at: Thu, 03 Sep 2015 10:56:01 GMT
|
145
|
+
- request:
|
146
|
+
method: delete
|
147
|
+
uri: http://gamification-api.dev/v1/badges/create-badge-for-update
|
148
|
+
body:
|
149
|
+
encoding: US-ASCII
|
150
|
+
string: ''
|
151
|
+
headers:
|
152
|
+
User-Agent:
|
153
|
+
- Faraday v0.9.1
|
154
|
+
Authorization:
|
155
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
156
|
+
Accept-Encoding:
|
157
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
158
|
+
Accept:
|
159
|
+
- "*/*"
|
160
|
+
response:
|
161
|
+
status:
|
162
|
+
code: 200
|
163
|
+
message: OK
|
164
|
+
headers:
|
165
|
+
X-Frame-Options:
|
166
|
+
- SAMEORIGIN
|
167
|
+
X-Xss-Protection:
|
168
|
+
- 1; mode=block
|
169
|
+
X-Content-Type-Options:
|
170
|
+
- nosniff
|
171
|
+
Content-Type:
|
172
|
+
- application/json; charset=utf-8
|
173
|
+
Etag:
|
174
|
+
- '"16df778d53540ec72b860dcfbf86fae0"'
|
175
|
+
Cache-Control:
|
176
|
+
- max-age=0, private, must-revalidate
|
177
|
+
X-Request-Id:
|
178
|
+
- 2b896a5c-1114-4e64-935e-53904af44423
|
179
|
+
X-Runtime:
|
180
|
+
- '0.027496'
|
181
|
+
Date:
|
182
|
+
- Thu, 03 Sep 2015 10:56:01 GMT
|
183
|
+
Connection:
|
184
|
+
- close
|
185
|
+
body:
|
186
|
+
encoding: UTF-8
|
187
|
+
string: '{"name":"Updated Badge","description":"Updated Description","requirements":"Updated
|
188
|
+
Requirements","hint":"Updated Hint","image":"http://gamification-api.dev/badge_images/updated-badge/badge.png","collection_id":"trim-trail","created_at":"2015-09-03T10:56:01.214Z","updated_at":"2015-09-03T10:56:01.301Z","level":"bronze","auto_issue":false,"status":"draft","required_badges":[],"points":25,"object":"badge","id":"updated-badge"}'
|
189
|
+
http_version:
|
190
|
+
recorded_at: Thu, 03 Sep 2015 10:56:01 GMT
|
191
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,191 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://gamification-api.dev/v1/collections
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: collection%5Bdescription%5D=This+is+a+new+collection&collection%5Bname%5D=Create+Collection+for+update
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Authorization:
|
13
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 201
|
23
|
+
message: Created
|
24
|
+
headers:
|
25
|
+
X-Frame-Options:
|
26
|
+
- SAMEORIGIN
|
27
|
+
X-Xss-Protection:
|
28
|
+
- 1; mode=block
|
29
|
+
X-Content-Type-Options:
|
30
|
+
- nosniff
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Etag:
|
34
|
+
- '"c666289a55798731fd3cc77deb74f315"'
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
X-Request-Id:
|
38
|
+
- 978bd974-39db-45de-95fd-2ee8f036793e
|
39
|
+
X-Runtime:
|
40
|
+
- '0.026095'
|
41
|
+
Date:
|
42
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
43
|
+
Connection:
|
44
|
+
- close
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"id":"create-collection-for-update","name":"Create Collection for
|
48
|
+
update","description":"This is a new collection","created_at":"2015-09-03T10:59:41.624Z","updated_at":"2015-09-03T10:59:41.624Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
51
|
+
- request:
|
52
|
+
method: patch
|
53
|
+
uri: http://gamification-api.dev/v1/collections/create-collection-for-update
|
54
|
+
body:
|
55
|
+
encoding: UTF-8
|
56
|
+
string: collection%5Bdescription%5D=Updated+Collection&collection%5Bname%5D=Updated+Collection
|
57
|
+
headers:
|
58
|
+
User-Agent:
|
59
|
+
- Faraday v0.9.1
|
60
|
+
Authorization:
|
61
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
62
|
+
Content-Type:
|
63
|
+
- application/x-www-form-urlencoded
|
64
|
+
Accept-Encoding:
|
65
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
66
|
+
Accept:
|
67
|
+
- "*/*"
|
68
|
+
response:
|
69
|
+
status:
|
70
|
+
code: 200
|
71
|
+
message: OK
|
72
|
+
headers:
|
73
|
+
X-Frame-Options:
|
74
|
+
- SAMEORIGIN
|
75
|
+
X-Xss-Protection:
|
76
|
+
- 1; mode=block
|
77
|
+
X-Content-Type-Options:
|
78
|
+
- nosniff
|
79
|
+
Content-Type:
|
80
|
+
- application/json; charset=utf-8
|
81
|
+
Etag:
|
82
|
+
- '"7494bb3e8456455d91f253f85cab43c3"'
|
83
|
+
Cache-Control:
|
84
|
+
- max-age=0, private, must-revalidate
|
85
|
+
X-Request-Id:
|
86
|
+
- e9728551-643e-4147-8ac5-4aa8c4bbe060
|
87
|
+
X-Runtime:
|
88
|
+
- '0.025605'
|
89
|
+
Date:
|
90
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
91
|
+
Connection:
|
92
|
+
- close
|
93
|
+
body:
|
94
|
+
encoding: UTF-8
|
95
|
+
string: '{"id":"updated-collection","name":"Updated Collection","description":"Updated
|
96
|
+
Collection","created_at":"2015-09-03T10:59:41.624Z","updated_at":"2015-09-03T10:59:41.676Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
97
|
+
http_version:
|
98
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
99
|
+
- request:
|
100
|
+
method: get
|
101
|
+
uri: http://gamification-api.dev/v1/collections/create-collection-for-update
|
102
|
+
body:
|
103
|
+
encoding: US-ASCII
|
104
|
+
string: ''
|
105
|
+
headers:
|
106
|
+
User-Agent:
|
107
|
+
- Faraday v0.9.1
|
108
|
+
Authorization:
|
109
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
110
|
+
Accept-Encoding:
|
111
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
112
|
+
Accept:
|
113
|
+
- "*/*"
|
114
|
+
response:
|
115
|
+
status:
|
116
|
+
code: 200
|
117
|
+
message: OK
|
118
|
+
headers:
|
119
|
+
X-Frame-Options:
|
120
|
+
- SAMEORIGIN
|
121
|
+
X-Xss-Protection:
|
122
|
+
- 1; mode=block
|
123
|
+
X-Content-Type-Options:
|
124
|
+
- nosniff
|
125
|
+
Content-Type:
|
126
|
+
- application/json; charset=utf-8
|
127
|
+
Etag:
|
128
|
+
- '"7494bb3e8456455d91f253f85cab43c3"'
|
129
|
+
Cache-Control:
|
130
|
+
- max-age=0, private, must-revalidate
|
131
|
+
X-Request-Id:
|
132
|
+
- 9b1ed3d4-efcf-4a83-b48b-ad4c38c3e2a3
|
133
|
+
X-Runtime:
|
134
|
+
- '0.033049'
|
135
|
+
Date:
|
136
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
137
|
+
Connection:
|
138
|
+
- close
|
139
|
+
body:
|
140
|
+
encoding: UTF-8
|
141
|
+
string: '{"id":"updated-collection","name":"Updated Collection","description":"Updated
|
142
|
+
Collection","created_at":"2015-09-03T10:59:41.624Z","updated_at":"2015-09-03T10:59:41.676Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
143
|
+
http_version:
|
144
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
145
|
+
- request:
|
146
|
+
method: delete
|
147
|
+
uri: http://gamification-api.dev/v1/collections/create-collection-for-update
|
148
|
+
body:
|
149
|
+
encoding: US-ASCII
|
150
|
+
string: ''
|
151
|
+
headers:
|
152
|
+
User-Agent:
|
153
|
+
- Faraday v0.9.1
|
154
|
+
Authorization:
|
155
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
156
|
+
Accept-Encoding:
|
157
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
158
|
+
Accept:
|
159
|
+
- "*/*"
|
160
|
+
response:
|
161
|
+
status:
|
162
|
+
code: 200
|
163
|
+
message: OK
|
164
|
+
headers:
|
165
|
+
X-Frame-Options:
|
166
|
+
- SAMEORIGIN
|
167
|
+
X-Xss-Protection:
|
168
|
+
- 1; mode=block
|
169
|
+
X-Content-Type-Options:
|
170
|
+
- nosniff
|
171
|
+
Content-Type:
|
172
|
+
- application/json; charset=utf-8
|
173
|
+
Etag:
|
174
|
+
- '"7494bb3e8456455d91f253f85cab43c3"'
|
175
|
+
Cache-Control:
|
176
|
+
- max-age=0, private, must-revalidate
|
177
|
+
X-Request-Id:
|
178
|
+
- 39aa1c48-f0ea-41b7-a2f5-b7624f4a92f0
|
179
|
+
X-Runtime:
|
180
|
+
- '0.022458'
|
181
|
+
Date:
|
182
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
183
|
+
Connection:
|
184
|
+
- close
|
185
|
+
body:
|
186
|
+
encoding: UTF-8
|
187
|
+
string: '{"id":"updated-collection","name":"Updated Collection","description":"Updated
|
188
|
+
Collection","created_at":"2015-09-03T10:59:41.624Z","updated_at":"2015-09-03T10:59:41.676Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
189
|
+
http_version:
|
190
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
191
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,145 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://gamification-api.dev/v1/collections
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: collection%5Bdescription%5D=This+is+a+new+collection&collection%5Bname%5D=Create+Collection+for+update
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Authorization:
|
13
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 201
|
23
|
+
message: Created
|
24
|
+
headers:
|
25
|
+
X-Frame-Options:
|
26
|
+
- SAMEORIGIN
|
27
|
+
X-Xss-Protection:
|
28
|
+
- 1; mode=block
|
29
|
+
X-Content-Type-Options:
|
30
|
+
- nosniff
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Etag:
|
34
|
+
- '"46e030fb97fab917228bda746fc557b1"'
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
X-Request-Id:
|
38
|
+
- 0abbf4e8-63ff-4835-a216-c4fc9922d5a3
|
39
|
+
X-Runtime:
|
40
|
+
- '0.023212'
|
41
|
+
Date:
|
42
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
43
|
+
Connection:
|
44
|
+
- close
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"id":"create-collection-for-update","name":"Create Collection for
|
48
|
+
update","description":"This is a new collection","created_at":"2015-09-03T10:59:41.823Z","updated_at":"2015-09-03T10:59:41.823Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
51
|
+
- request:
|
52
|
+
method: patch
|
53
|
+
uri: http://gamification-api.dev/v1/collections/create-collection-for-update
|
54
|
+
body:
|
55
|
+
encoding: UTF-8
|
56
|
+
string: collection%5Bdescription%5D=Updated+Description&collection%5Bname%5D=Updated+Badge
|
57
|
+
headers:
|
58
|
+
User-Agent:
|
59
|
+
- Faraday v0.9.1
|
60
|
+
Authorization:
|
61
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
62
|
+
Content-Type:
|
63
|
+
- application/x-www-form-urlencoded
|
64
|
+
Accept-Encoding:
|
65
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
66
|
+
Accept:
|
67
|
+
- "*/*"
|
68
|
+
response:
|
69
|
+
status:
|
70
|
+
code: 200
|
71
|
+
message: OK
|
72
|
+
headers:
|
73
|
+
X-Frame-Options:
|
74
|
+
- SAMEORIGIN
|
75
|
+
X-Xss-Protection:
|
76
|
+
- 1; mode=block
|
77
|
+
X-Content-Type-Options:
|
78
|
+
- nosniff
|
79
|
+
Content-Type:
|
80
|
+
- application/json; charset=utf-8
|
81
|
+
Etag:
|
82
|
+
- '"7ee6f28cc71adcdfc0ac35b28ab6a2b7"'
|
83
|
+
Cache-Control:
|
84
|
+
- max-age=0, private, must-revalidate
|
85
|
+
X-Request-Id:
|
86
|
+
- bfb422eb-108e-4f9c-8cec-bb8816f8ad09
|
87
|
+
X-Runtime:
|
88
|
+
- '0.023264'
|
89
|
+
Date:
|
90
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
91
|
+
Connection:
|
92
|
+
- close
|
93
|
+
body:
|
94
|
+
encoding: UTF-8
|
95
|
+
string: '{"id":"updated-badge","name":"Updated Badge","description":"Updated
|
96
|
+
Description","created_at":"2015-09-03T10:59:41.823Z","updated_at":"2015-09-03T10:59:41.866Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
97
|
+
http_version:
|
98
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
99
|
+
- request:
|
100
|
+
method: delete
|
101
|
+
uri: http://gamification-api.dev/v1/collections/create-collection-for-update
|
102
|
+
body:
|
103
|
+
encoding: US-ASCII
|
104
|
+
string: ''
|
105
|
+
headers:
|
106
|
+
User-Agent:
|
107
|
+
- Faraday v0.9.1
|
108
|
+
Authorization:
|
109
|
+
- Token token="c9cde524238644fa93393159e5e9ad87"
|
110
|
+
Accept-Encoding:
|
111
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
112
|
+
Accept:
|
113
|
+
- "*/*"
|
114
|
+
response:
|
115
|
+
status:
|
116
|
+
code: 200
|
117
|
+
message: OK
|
118
|
+
headers:
|
119
|
+
X-Frame-Options:
|
120
|
+
- SAMEORIGIN
|
121
|
+
X-Xss-Protection:
|
122
|
+
- 1; mode=block
|
123
|
+
X-Content-Type-Options:
|
124
|
+
- nosniff
|
125
|
+
Content-Type:
|
126
|
+
- application/json; charset=utf-8
|
127
|
+
Etag:
|
128
|
+
- '"7ee6f28cc71adcdfc0ac35b28ab6a2b7"'
|
129
|
+
Cache-Control:
|
130
|
+
- max-age=0, private, must-revalidate
|
131
|
+
X-Request-Id:
|
132
|
+
- b651b40d-d6ea-4aa1-80a4-041016937317
|
133
|
+
X-Runtime:
|
134
|
+
- '0.018966'
|
135
|
+
Date:
|
136
|
+
- Thu, 03 Sep 2015 10:59:41 GMT
|
137
|
+
Connection:
|
138
|
+
- close
|
139
|
+
body:
|
140
|
+
encoding: UTF-8
|
141
|
+
string: '{"id":"updated-badge","name":"Updated Badge","description":"Updated
|
142
|
+
Description","created_at":"2015-09-03T10:59:41.823Z","updated_at":"2015-09-03T10:59:41.866Z","total_points_available":0,"badge_count":0,"object":"collection"}'
|
143
|
+
http_version:
|
144
|
+
recorded_at: Thu, 03 Sep 2015 10:59:41 GMT
|
145
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#test/collection/collection_test.rb
|
2
|
+
require './test/test_helper'
|
3
|
+
|
4
|
+
class BadgeapiCollectionTest < MiniTest::Test
|
5
|
+
|
6
|
+
def self.test_order
|
7
|
+
:alpha
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_exists
|
11
|
+
assert Badgeapi::Recipient
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_object_path
|
15
|
+
assert_equal "recipients", Badgeapi::Recipient.collection_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_object_name
|
19
|
+
assert_equal "recipient", Badgeapi::Recipient.member_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_it_return_back_recipient_stats
|
23
|
+
VCR.use_cassette('recipient_with_badges', :record => :all) do
|
24
|
+
Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
|
25
|
+
|
26
|
+
recipient = Badgeapi::Recipient.find(recipient: "t.skarbek-wazynski@lancaster.ac.uk")
|
27
|
+
|
28
|
+
assert_equal recipient.class, Badgeapi::Recipient
|
29
|
+
|
30
|
+
assert_kind_of Integer, recipient.total_score
|
31
|
+
assert_kind_of Integer, recipient.badges_total
|
32
|
+
assert_kind_of Integer, recipient.bronze_count
|
33
|
+
assert_kind_of Integer, recipient.silver_count
|
34
|
+
assert_kind_of Integer, recipient.gold_count
|
35
|
+
assert_kind_of Integer, recipient.platinum_count
|
36
|
+
|
37
|
+
assert_equal Badgeapi::Badge, recipient.badges.first.class
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_it_return_back_recipient_stats_with_unicard
|
42
|
+
VCR.use_cassette('recipient_with_badges_unicard', :record => :all) do
|
43
|
+
Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
|
44
|
+
|
45
|
+
recipient = Badgeapi::Recipient.find(user: "0043181")
|
46
|
+
|
47
|
+
assert_equal recipient.class, Badgeapi::Recipient
|
48
|
+
|
49
|
+
assert_kind_of Integer, recipient.total_score
|
50
|
+
assert_kind_of Integer, recipient.badges_total
|
51
|
+
assert_kind_of Integer, recipient.bronze_count
|
52
|
+
assert_kind_of Integer, recipient.silver_count
|
53
|
+
assert_kind_of Integer, recipient.gold_count
|
54
|
+
assert_kind_of Integer, recipient.platinum_count
|
55
|
+
|
56
|
+
assert_equal Badgeapi::Badge, recipient.badges.first.class
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_it_raise_issue_if_bad_user
|
61
|
+
VCR.use_cassette('bad_Recipient', :record => :all) do
|
62
|
+
Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
|
63
|
+
|
64
|
+
assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Recipient.find(user: "dfsgsdgg") }
|
65
|
+
|
66
|
+
begin
|
67
|
+
Badgeapi::Recipient.find(user: "dfsgsdgg")
|
68
|
+
rescue Badgeapi::InvalidRequestError => e
|
69
|
+
assert_equal(404, e.http_status)
|
70
|
+
refute_empty e.message
|
71
|
+
assert_equal(true, e.json_body.kind_of?(Hash))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_it_raise_issue_if_bad_user_does_not_yet_exist
|
77
|
+
VCR.use_cassette('bad_Recipient', :record => :all) do
|
78
|
+
Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
|
79
|
+
|
80
|
+
assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Recipient.find(user: "j.stennet@lancaster.ac.uk") }
|
81
|
+
|
82
|
+
begin
|
83
|
+
Badgeapi::Recipient.find(user: "j.stennet@lancaster.ac.uk")
|
84
|
+
rescue Badgeapi::InvalidRequestError => e
|
85
|
+
assert_equal(404, e.http_status)
|
86
|
+
refute_empty e.message
|
87
|
+
assert_equal(true, e.json_body.kind_of?(Hash))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def test_you_cannot_request_any_other_function_on_recipients
|
94
|
+
VCR.use_cassette('bad_recipient_request', :record => :all) do
|
95
|
+
Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
|
96
|
+
|
97
|
+
assert_raises(NoMethodError) { Badgeapi::Recipient.all }
|
98
|
+
|
99
|
+
assert_raises(NoMethodError) { Badgeapi::Recipient.find(1) }
|
100
|
+
|
101
|
+
assert_raises(NoMethodError) { Badgeapi::Recipient.create(1) }
|
102
|
+
|
103
|
+
assert_raises(NoMethodError) { Badgeapi::Recipient.update(1) }
|
104
|
+
|
105
|
+
assert_raises(NoMethodError) { Badgeapi::Recipient.destroy(1) }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/test/test_helper.rb
ADDED