edmodo-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +38 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +80 -0
- data/Rakefile +7 -0
- data/edmodo-api.gemspec +27 -0
- data/lib/edmodo-api/client.rb +323 -0
- data/lib/edmodo-api/config.rb +17 -0
- data/lib/edmodo-api/request.rb +36 -0
- data/lib/edmodo-api/version.rb +7 -0
- data/lib/edmodo-api.rb +6 -0
- data/spec/edmodo-api_spec.rb +111 -0
- data/spec/spec_helper.rb +87 -0
- metadata +156 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
edmodo-api (0.0.1)
|
5
|
+
httparty
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
awesome_print (1.1.0)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
fakeweb (1.3.0)
|
14
|
+
httparty (0.9.0)
|
15
|
+
multi_json (~> 1.0)
|
16
|
+
multi_xml
|
17
|
+
json (1.7.5)
|
18
|
+
multi_json (1.5.0)
|
19
|
+
multi_xml (0.5.1)
|
20
|
+
rake (10.0.3)
|
21
|
+
rspec (2.12.0)
|
22
|
+
rspec-core (~> 2.12.0)
|
23
|
+
rspec-expectations (~> 2.12.0)
|
24
|
+
rspec-mocks (~> 2.12.0)
|
25
|
+
rspec-core (2.12.2)
|
26
|
+
rspec-expectations (2.12.1)
|
27
|
+
diff-lcs (~> 1.1.3)
|
28
|
+
rspec-mocks (2.12.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
awesome_print
|
35
|
+
edmodo-api!
|
36
|
+
fakeweb
|
37
|
+
rake
|
38
|
+
rspec
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009-2012 Gabriel Cebrian
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
Edmodo::API - Edmodo Ruby API client
|
2
|
+
=======
|
3
|
+
|
4
|
+
A Ruby wrapper for the Edmodo REST API.
|
5
|
+
|
6
|
+
Install:
|
7
|
+
-------
|
8
|
+
|
9
|
+
gem install edmodo-api
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
-------
|
13
|
+
|
14
|
+
- Get an Edmodo Publisher Account at http://www.edmodo.com/publishers-requests.
|
15
|
+
- Initialize an edmodo-api object passing your api key.
|
16
|
+
- Start calling Edmodo API methods.
|
17
|
+
|
18
|
+
The gem uses sandbox mode by default. Use :mode => :production to use it on production environments
|
19
|
+
|
20
|
+
You can set the environment EDMODO_API_KEY and the gem will use it if you pass nil as the api_key when you create an instance
|
21
|
+
|
22
|
+
Examples:
|
23
|
+
----------
|
24
|
+
client = Edmodo::API::Client.new(api_key , :mode => :production)
|
25
|
+
client.launchRequests "5c18c7"
|
26
|
+
|
27
|
+
Error Handling:
|
28
|
+
--------
|
29
|
+
|
30
|
+
The gem raises EdmodoApiError exceptions if a request doesn't return with status code 200 or if a key cannot be found on initialization
|
31
|
+
|
32
|
+
Support:
|
33
|
+
--------
|
34
|
+
|
35
|
+
This gem is not associated with Edmodo so please contact them for Edmodo specific questions
|
36
|
+
|
37
|
+
ZOMG Fork! Thank you!
|
38
|
+
---------
|
39
|
+
|
40
|
+
You're welcome to fork this project and send pull requests. Just remember to include specs.
|
41
|
+
|
42
|
+
TO DO
|
43
|
+
---------
|
44
|
+
|
45
|
+
- Finish implementation of all the methods
|
46
|
+
- Thinking about adding all the requests name into an array and overriding the Ruby method_missing method to DRY up the client code
|
47
|
+
- Adding tests for every method
|
48
|
+
|
49
|
+
Edmodo methods that will be supported
|
50
|
+
---------
|
51
|
+
|
52
|
+
- launchRequests
|
53
|
+
- users
|
54
|
+
- groups
|
55
|
+
- groupsForUser
|
56
|
+
- members
|
57
|
+
- classmates
|
58
|
+
- teachers
|
59
|
+
- teachermates
|
60
|
+
- teacherConnections
|
61
|
+
- assignmentsComingDue
|
62
|
+
- gradesSetByAppForUser
|
63
|
+
- gradesSetByAppForGroup
|
64
|
+
- badgesAwarded
|
65
|
+
- eventsByApp
|
66
|
+
- parents
|
67
|
+
- children
|
68
|
+
- profiles
|
69
|
+
- userPost
|
70
|
+
- turnInAssignment
|
71
|
+
- registerBadge
|
72
|
+
- updateBadge
|
73
|
+
- awardBadge
|
74
|
+
- revokeBadge
|
75
|
+
- newGrade
|
76
|
+
- setGrade
|
77
|
+
- newEvent
|
78
|
+
- addToLibrary
|
79
|
+
- setNotification
|
80
|
+
|
data/Rakefile
ADDED
data/edmodo-api.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/edmodo-api/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Gabriel Cebrian"]
|
6
|
+
gem.email = ["gabceb@gmail.com"]
|
7
|
+
gem.description = %q{To be used when creating apps for Edmodo}
|
8
|
+
gem.summary = %q{Ruby wrapper for the Edmodo API}
|
9
|
+
gem.homepage = "https://github.com/gabceb/edmodo-api"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
+
gem.name = "edmodo-api"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Edmodo::API::VERSION
|
17
|
+
|
18
|
+
gem.required_ruby_version = '>= 1.9.2'
|
19
|
+
|
20
|
+
gem.add_dependency('httparty')
|
21
|
+
gem.add_dependency('json')
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rspec'
|
24
|
+
gem.add_development_dependency 'fakeweb'
|
25
|
+
gem.add_development_dependency 'awesome_print'
|
26
|
+
gem.add_development_dependency 'rake'
|
27
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
EdmodoApiError = Class.new(StandardError)
|
7
|
+
|
8
|
+
module Edmodo
|
9
|
+
module API
|
10
|
+
class Client
|
11
|
+
|
12
|
+
include Edmodo::API::Request
|
13
|
+
include HTTParty
|
14
|
+
|
15
|
+
attr_reader :api_key
|
16
|
+
attr_reader :mode
|
17
|
+
|
18
|
+
# Initializes a new instance of the Edmodo API client
|
19
|
+
# Options:
|
20
|
+
#
|
21
|
+
# => mode: Sets the mode to production or sandbox
|
22
|
+
#
|
23
|
+
def initialize(api_key, options = {})
|
24
|
+
|
25
|
+
options = defaults.merge(options)
|
26
|
+
|
27
|
+
@format = options[:format]
|
28
|
+
@mode = options[:mode]
|
29
|
+
@api_key = (api_key || ENV['EDMODO_API_KEY'] || "").strip
|
30
|
+
|
31
|
+
raise_init_errors
|
32
|
+
|
33
|
+
@endpoint = Edmodo::API::Config.endpoints[@mode]
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# -- GET Requests --
|
38
|
+
|
39
|
+
# Returns user data for the user that requested the application launch.
|
40
|
+
# Params:
|
41
|
+
#
|
42
|
+
# => launch_key: launch_key that was passed to the application's server.
|
43
|
+
def launch_requests launch_key
|
44
|
+
request :get, resource_uri("launchRequests", @format), {:launch_key => launch_key}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns user data for a given user token or array of user tokens.
|
48
|
+
# Params:
|
49
|
+
#
|
50
|
+
# => user_tokens: array of user tokens
|
51
|
+
def users user_tokens
|
52
|
+
user_tokens = Array(user_tokens)
|
53
|
+
|
54
|
+
request :get, resource_uri("users", @format), {:user_tokens => user_tokens.to_json}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns group data for a given array of group ids.
|
58
|
+
# Params:
|
59
|
+
#
|
60
|
+
# => group_ids: array of group ids
|
61
|
+
def groups group_ids
|
62
|
+
group_ids = Arary(group_ids)
|
63
|
+
|
64
|
+
request :get, resource_uri("groups", @format), {:group_ids => group_ids.to_json}
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the data for groups a user belongs to given a user token.
|
68
|
+
# Params:
|
69
|
+
#
|
70
|
+
# => user_token: User token
|
71
|
+
def groups_for_user user_token
|
72
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns an array of user data for members of a group, specified by group id.
|
76
|
+
# Params:
|
77
|
+
#
|
78
|
+
# => group_id: integer Group ID
|
79
|
+
def members group_id
|
80
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns an array of user data for all students that belong to at least one group with the student specified by user token.
|
84
|
+
# Params:
|
85
|
+
#
|
86
|
+
# => user_token: User token of the student
|
87
|
+
def classmates user_token
|
88
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns an array of user data for all teachers for a student specified by user token.
|
92
|
+
# Params:
|
93
|
+
#
|
94
|
+
# => user_token: User token of the student
|
95
|
+
def teachers user_token
|
96
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns an array of user data for all teachers that are connected to the teacher specified by user token.
|
100
|
+
# Params:
|
101
|
+
#
|
102
|
+
# => user_token: User token of the teacher
|
103
|
+
def teachermates user_token
|
104
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
105
|
+
end
|
106
|
+
|
107
|
+
# Returns an array of assignments coming due (in the next 60 days) for the user specified by the token.
|
108
|
+
# Params:
|
109
|
+
#
|
110
|
+
# => user_token: User token of the user
|
111
|
+
def teacher_connections user_token
|
112
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
113
|
+
end
|
114
|
+
|
115
|
+
# This call can be used in conjunction with turnInAssignment to allow a user to submit content from the app for a particular assignment in Edmodo.
|
116
|
+
# Params:
|
117
|
+
#
|
118
|
+
# => user_token: User token of the user
|
119
|
+
def assignments_coming_due user_token
|
120
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
121
|
+
end
|
122
|
+
|
123
|
+
# Returns an array of grades set by the app for the given user token.
|
124
|
+
# Params:
|
125
|
+
#
|
126
|
+
# => user_token: User token of the user to get grades for
|
127
|
+
def grades_set_by_app_for_user user_token
|
128
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
129
|
+
end
|
130
|
+
|
131
|
+
# Returns an array of grades set by the app for the given group.
|
132
|
+
# Params:
|
133
|
+
#
|
134
|
+
# => group_id: The group to get grades for.
|
135
|
+
def grades_set_by_app_for_group group_id
|
136
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
137
|
+
end
|
138
|
+
|
139
|
+
# Returns an array of badges awarded by the app to the given user token.
|
140
|
+
# Params:
|
141
|
+
#
|
142
|
+
# => user_token: The user_token to get badges awarded for.
|
143
|
+
def badges_awarded user_token
|
144
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
145
|
+
end
|
146
|
+
|
147
|
+
# Returns an array of events set on behalf of the specified user by the app.
|
148
|
+
# Params:
|
149
|
+
#
|
150
|
+
# => user_token: The user token for the user from which events were set for.
|
151
|
+
def events_by_app user_token
|
152
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns an array of parent user data, given a specified student user token.
|
156
|
+
# Params:
|
157
|
+
#
|
158
|
+
# => user_token: User token of the student
|
159
|
+
def parents user_token
|
160
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
161
|
+
end
|
162
|
+
|
163
|
+
# Returns an array of data for students, given a specified parent user token.
|
164
|
+
# Params:
|
165
|
+
#
|
166
|
+
# => user_token: User token of the parent
|
167
|
+
def children user_token
|
168
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
169
|
+
end
|
170
|
+
|
171
|
+
# Fetches user profile information.
|
172
|
+
# Currently, this is only for teacher users to obtain their school information (if a school is set for the teacher).
|
173
|
+
# Params:
|
174
|
+
#
|
175
|
+
# => user_token: Array of teacher user tokens.
|
176
|
+
def profiles user_tokens
|
177
|
+
|
178
|
+
user_tokens = Array(user_tokens)
|
179
|
+
|
180
|
+
request :get, resource_uri("profiles", "json"), {:user_tokens => user_tokens.to_json}
|
181
|
+
end
|
182
|
+
|
183
|
+
# -- POST Requests --
|
184
|
+
|
185
|
+
# Send a post to the recipient group(s) or user(s) from the user token specified.
|
186
|
+
# Params:
|
187
|
+
#
|
188
|
+
# => user_token: The user token for the user sending the post.
|
189
|
+
# => content: The text of the message.
|
190
|
+
# => recipients: Array of objects specifying the recipients of the post. These can be either users (specified by a user_token) or groups (specified by a group_id).
|
191
|
+
# => attachments (Optional): array of objects specifying links/embed codes to include in the post message.
|
192
|
+
def user_post user_token, content, recipients, attachments = nil
|
193
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
194
|
+
end
|
195
|
+
|
196
|
+
# Submits a response to the specified assignment for the given user. The id's for assignments coming due can be retrieved using the assignments_coming_due.
|
197
|
+
# Params:
|
198
|
+
#
|
199
|
+
# => user_token: The user token for the user turning in the assignment.
|
200
|
+
# => assignment_id: Assignment Id for the assignment to turn in, obtained from the assignments_coming_due
|
201
|
+
# => content: Text of the submission
|
202
|
+
# => attachments (Optional): Array of objects specifying links/embed codes to include in the assignment submission
|
203
|
+
def turn_in_assignment user_token, assignment_id, content, attachments = nil
|
204
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
205
|
+
end
|
206
|
+
|
207
|
+
# Registers a badge with Edmodo, returning a badge id that can be used to award a badge that will display on an Edmodo user's profile.
|
208
|
+
# Params:
|
209
|
+
#
|
210
|
+
# => badge_title: limit 50 characters
|
211
|
+
# => description: limit 140 characters
|
212
|
+
# => image_url: url to badge image, should be 114x114 pixels. Accepted image types: jpg, gif, png
|
213
|
+
def register_badge badge_title, description, image_url
|
214
|
+
request(:post, resource_uri("registerBadge"), {:badge_title => badge_title, :description => description, :image_url => image_url})
|
215
|
+
end
|
216
|
+
|
217
|
+
# Returns an array of user data for all teachers for a student specified by user token.
|
218
|
+
# Params:
|
219
|
+
#
|
220
|
+
# => badge_id: the registered badge id
|
221
|
+
# => badge_title: limit 50 characters
|
222
|
+
# => description: limit 140 characters
|
223
|
+
# => image_url (Optional): If you wish to replace the image of the badge, specify the url of the new badge image. Otherwise, to keep the old badge image, you do not need to specify this parameter.
|
224
|
+
def update_badge badge_id, badge_title, description, image_url = nil
|
225
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
226
|
+
end
|
227
|
+
|
228
|
+
# Awards a badge to a given user.
|
229
|
+
# Params:
|
230
|
+
#
|
231
|
+
# => badge_id: Badge ID of the badge being awarded
|
232
|
+
# => user_token: User token of the user receiving the badge
|
233
|
+
def award_badge user_token, badge_id
|
234
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
235
|
+
end
|
236
|
+
|
237
|
+
# Revokes a badge that has been awarded to a given user.
|
238
|
+
# Params:
|
239
|
+
#
|
240
|
+
# => badge_id: Badge ID of the badge being revoked
|
241
|
+
# => user_token: User token of the user who has been awarded the badge and whom it will be revoked from.
|
242
|
+
def revoke_badge badge_id, user_token
|
243
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
244
|
+
end
|
245
|
+
|
246
|
+
# Add a new grade to the gradebook for a given group.
|
247
|
+
# Params:
|
248
|
+
#
|
249
|
+
# => group_id: The group this grade will be created in
|
250
|
+
# => title: The title for this grade
|
251
|
+
# => total: The total grade possible for this grade
|
252
|
+
def new_grade group_id, title, total
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
# Set a score for a grade given a specific user token.
|
257
|
+
# Params:
|
258
|
+
#
|
259
|
+
# => grade_id: The grade the score is being set upon
|
260
|
+
# => user_token: The user_token of the user to set the grade for
|
261
|
+
# => score: The score to set for this grade
|
262
|
+
def set_grade grade_id, user_token, score
|
263
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
264
|
+
end
|
265
|
+
|
266
|
+
# Set a new event on behalf of a user to specified recipients. Events will be seen on the calendar as well as notifications as the event approaches.
|
267
|
+
# Params:
|
268
|
+
#
|
269
|
+
# => user_token: The user_token of the user to set the event on behalf for.
|
270
|
+
# => description: The description of the event.
|
271
|
+
# => start_date: The start date of the event (specified in the format YYYY-MM-DD).
|
272
|
+
# => end_date: The end date of the event (specified in the format YYYY-MM-DD). If this is a single day event, the end date should simply be the same as the start date.
|
273
|
+
# => recipients: array of objects specifying the recipients of the post. These can be either users (specified by a user_token) or groups (specified by a group_id).
|
274
|
+
def new_event user_token, description, start_date, end_date, recipients
|
275
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
276
|
+
end
|
277
|
+
|
278
|
+
# Adds a resource (url or embed code) to a user's Library
|
279
|
+
# Params:
|
280
|
+
#
|
281
|
+
# => user_token: The user_token of the user that will have the resource added to her/his library.
|
282
|
+
# => publisher_owned: If you want the resources's author to be the publisher account associated with the app, set this parameter. Set to '1' if you want the resource to be publisher owned
|
283
|
+
# => resource: Object specifying the link or embed code to add to the user's library.
|
284
|
+
def add_to_library user_token, publisher_owned, resource
|
285
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
286
|
+
end
|
287
|
+
|
288
|
+
# Sets a specified count of app notifications for the user.
|
289
|
+
# Params:
|
290
|
+
#
|
291
|
+
# => user_token: The user_token of the user that will have the resource added to her/his library.
|
292
|
+
# => notification_count: The number to add to the user's notification count for the app
|
293
|
+
def set_notification user_token, notification
|
294
|
+
raise EdmodoApiError.new("Edmodo API Error: Method not implemented")
|
295
|
+
end
|
296
|
+
|
297
|
+
private
|
298
|
+
|
299
|
+
def defaults
|
300
|
+
{
|
301
|
+
:mode => :sandbox,
|
302
|
+
:format => "json"
|
303
|
+
}
|
304
|
+
end
|
305
|
+
|
306
|
+
# Checks for all required variables to be set when an instance is created and throws errors if they haven't
|
307
|
+
def raise_init_errors
|
308
|
+
raise EdmodoApiError.new("Edmodo API Error: Api key was not set") if @api_key.empty?
|
309
|
+
|
310
|
+
raise EdmodoApiError.new("EdmodoAPI Error: Mode not available on Edmodo API") unless Edmodo::API::Config.endpoints.keys.include? @mode
|
311
|
+
end
|
312
|
+
|
313
|
+
# Creates a uri using for a specific resource based on the mode and format
|
314
|
+
def resource_uri resource, format = nil
|
315
|
+
|
316
|
+
format = ".#{format}" if format
|
317
|
+
|
318
|
+
"#{@endpoint}/#{resource}#{format}?api_key=#{api_key}"
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Edmodo
|
2
|
+
module API
|
3
|
+
module Config
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :endpoints
|
7
|
+
attr_accessor :version
|
8
|
+
end
|
9
|
+
|
10
|
+
self.version = "v1"
|
11
|
+
self.endpoints = {
|
12
|
+
:production => "https://appsapi.edmodo.com/#{version}",
|
13
|
+
:sandbox => "https://appsapi.edmodobox.com/#{version}"
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'json'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module Edmodo
|
6
|
+
module API
|
7
|
+
module Request
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# Method to make a request using either GET or POST
|
12
|
+
def request method, uri, query
|
13
|
+
raw_response = case method
|
14
|
+
when :get
|
15
|
+
self.class.get(uri, query: query )
|
16
|
+
when :post
|
17
|
+
self.class.post(uri, query: query)
|
18
|
+
else
|
19
|
+
raise EdmodoApiError.new "EdmodoAPI Error: Request Method error."
|
20
|
+
end
|
21
|
+
|
22
|
+
check_response_for_errors(raw_response) && JSON.parse(raw_response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Helper method to make sure the request returned with 200 status and raised an exception otherwise
|
26
|
+
def check_response_for_errors response
|
27
|
+
unless (success = response.code == 200)
|
28
|
+
raise EdmodoApiError.new "EdmodoAPI Error: Request Error. #{response.body} (status: #{response.code})"
|
29
|
+
end
|
30
|
+
|
31
|
+
return success
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/edmodo-api.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), "/spec_helper")
|
4
|
+
|
5
|
+
describe Edmodo::API::Client do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@api_key = "1234567890abcdefghijklmn"
|
9
|
+
@invalid_api_key = "invalid_key"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Initialization' do
|
13
|
+
|
14
|
+
it 'should accept an api key in the constructor' do
|
15
|
+
Edmodo::API::Client.new(@api_key).api_key.should == @api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be initialized with sandbox mode by default" do
|
19
|
+
Edmodo::API::Client.new(@api_key).mode.should == :sandbox
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be initialized with production mode if passed to the initialize method" do
|
23
|
+
Edmodo::API::Client.new(@api_key, mode: :production).mode.should == :production
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be initialized with sandbox mode if passed to the initialize method" do
|
27
|
+
Edmodo::API::Client.new(@api_key, mode: :sandbox).mode.should == :sandbox
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should throw an exception if an unkown mode is passed to the initialize method" do
|
31
|
+
expect { Edmodo::API::Client.new(@api_key, mode: :mymode) }.to raise_error(EdmodoApiError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should throw an exception if no api key is passed to the initialize method" do
|
35
|
+
expect { Edmodo::API::Client.new(nil) }.to raise_error(EdmodoApiError)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'Config' do
|
41
|
+
it 'should have a version on the config' do
|
42
|
+
Edmodo::API::Config.version.should_not be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should have a production endopoint' do
|
46
|
+
Edmodo::API::Config.endpoints[:production].should_not be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should have a sandbox endpoint' do
|
50
|
+
Edmodo::API::Config.endpoints[:sandbox].should_not be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'Invalid Requests' do
|
55
|
+
it 'should throw an error when a request doesnt return a 200 status code' do
|
56
|
+
client = Edmodo::API::Client.new(@invalid_api_key)
|
57
|
+
|
58
|
+
expect { client.launch_requests("5c18c7") }.to raise_error(EdmodoApiError)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'GET Requests' do
|
63
|
+
before do
|
64
|
+
@client = Edmodo::API::Client.new(@api_key)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should get the correct hash back from the launchRequest request' do
|
68
|
+
|
69
|
+
response = @client.launch_requests("5c18c7")
|
70
|
+
|
71
|
+
response.should == {"user_type"=>"TEACHER", "user_token"=>"b020c42d1", "first_name"=>"Bob", "last_name"=>"Smith", "avatar_url"=>"http://edmodoimages.s3.amazonaws.com/default_avatar.png", "thumb_url"=>"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png", "groups"=>[{"group_id"=>379557, "is_owner"=>1}, {"group_id"=>379562, "is_owner"=>1}]}
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should get the correct hash back from the profiles request' do
|
75
|
+
|
76
|
+
response = @client.profiles("b020c42d1")
|
77
|
+
|
78
|
+
response.should == [{"user_token"=>"b020c42d1", "school"=>{"edmodo_school_id"=>123456, "nces_school_id"=>"ABC987654", "name"=>"Edmodo High", "address"=>"60 E. 3rd Avenue, #390", "city"=>"San Mateo", "state"=>"CA", "zip_code"=>"94401", "country_code"=>"US"}}]
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should get the correct hash back from the users request' do
|
82
|
+
|
83
|
+
users_ids = ["b020c42d1","jd3i1c0pl"]
|
84
|
+
response = @client.users(users_ids)
|
85
|
+
|
86
|
+
response.should == [{"user_type"=>"TEACHER", "user_token"=>"b020c42d1", "first_name"=>"Bob", "last_name"=>"Smith", "avatar_url"=>"http://edmodoimages.s3.amazonaws.com/default_avatar.png", "thumb_url"=>"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png"}, {"user_type"=>"STUDENT", "user_token"=>"jd3i1c0pl", "first_name"=>"Jane", "last_name"=>"Student", "avatar_url"=>"http://edmodoimages.s3.amazonaws.com/default_avatar.png", "thumb_url"=>"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png"}]
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should throw an exception if the method is not yet implemented' do
|
90
|
+
user_id = "b020c42d1"
|
91
|
+
|
92
|
+
expect { @client.children user_id }.to raise_error(EdmodoApiError)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'POST Requests' do
|
98
|
+
before do
|
99
|
+
api_key = "1234567890abcdefghijklmn"
|
100
|
+
@client = Edmodo::API::Client.new(api_key)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should get the correct hash response from the registerBadge request' do
|
104
|
+
response = @client.register_badge("Good Job", "You did a good job", "http://www.edmodo.com/badge_image.png")
|
105
|
+
|
106
|
+
response.should == {"badge_id" => 6580}
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$: << File.join(File.dirname(__FILE__), "/../lib")
|
4
|
+
require 'edmodo-api'
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
@api_key = "1234567890abcdefghijklmn"
|
8
|
+
@invalid_api_key = "invalid_key"
|
9
|
+
|
10
|
+
FakeWeb.allow_net_connect = false
|
11
|
+
|
12
|
+
# Unauthorized request
|
13
|
+
uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/launchRequests.json?api_key=#{@invalid_api_key}&launch_key=5c18c7"
|
14
|
+
|
15
|
+
FakeWeb.register_uri(:get, uri, :body => '{"error":{"code":3000,"message":"Unauthorized API request"}}', :status => ["401", "Authorization Required"])
|
16
|
+
|
17
|
+
# launchRequest request uri
|
18
|
+
uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/launchRequests.json?api_key=#{@api_key}&launch_key=5c18c7"
|
19
|
+
|
20
|
+
FakeWeb.register_uri(:get, uri,
|
21
|
+
:body => ' {
|
22
|
+
"user_type":"TEACHER",
|
23
|
+
"user_token":"b020c42d1",
|
24
|
+
"first_name":"Bob",
|
25
|
+
"last_name":"Smith",
|
26
|
+
"avatar_url":"http://edmodoimages.s3.amazonaws.com/default_avatar.png",
|
27
|
+
"thumb_url":"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png",
|
28
|
+
"groups":[
|
29
|
+
{
|
30
|
+
"group_id":379557,
|
31
|
+
"is_owner":1
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"group_id":379562,
|
35
|
+
"is_owner":1
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}')
|
39
|
+
|
40
|
+
# Users request uri
|
41
|
+
uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/users.json?api_key=#{@api_key}&user_tokens=%5B%22b020c42d1%22%2C%22jd3i1c0pl%22%5D"
|
42
|
+
|
43
|
+
FakeWeb.register_uri(:get, uri,
|
44
|
+
:body => ' [
|
45
|
+
{
|
46
|
+
"user_type":"TEACHER",
|
47
|
+
"user_token":"b020c42d1",
|
48
|
+
"first_name":"Bob",
|
49
|
+
"last_name":"Smith",
|
50
|
+
"avatar_url":"http://edmodoimages.s3.amazonaws.com/default_avatar.png",
|
51
|
+
"thumb_url":"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"user_type":"STUDENT",
|
55
|
+
"user_token":"jd3i1c0pl",
|
56
|
+
"first_name":"Jane",
|
57
|
+
"last_name":"Student",
|
58
|
+
"avatar_url":"http://edmodoimages.s3.amazonaws.com/default_avatar.png",
|
59
|
+
"thumb_url":"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png"
|
60
|
+
}
|
61
|
+
]')
|
62
|
+
|
63
|
+
# Profiles request uri
|
64
|
+
uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/profiles.json?api_key=#{@api_key}&user_tokens=%5B%22b020c42d1%22%5D"
|
65
|
+
|
66
|
+
FakeWeb.register_uri(:get, uri,
|
67
|
+
:body => '[
|
68
|
+
{
|
69
|
+
"user_token":"b020c42d1",
|
70
|
+
"school":{
|
71
|
+
"edmodo_school_id":123456,
|
72
|
+
"nces_school_id":"ABC987654",
|
73
|
+
"name":"Edmodo High",
|
74
|
+
"address":"60 E. 3rd Avenue, #390",
|
75
|
+
"city":"San Mateo",
|
76
|
+
"state":"CA",
|
77
|
+
"zip_code":"94401",
|
78
|
+
"country_code":"US"
|
79
|
+
}
|
80
|
+
}
|
81
|
+
]')
|
82
|
+
|
83
|
+
# RegisterBadge request uri
|
84
|
+
uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/registerBadge?api_key=#{@api_key}&badge_title=Good%20Job&description=You%20did%20a%20good%20job&image_url=http%3A%2F%2Fwww.edmodo.com%2Fbadge_image.png"
|
85
|
+
|
86
|
+
FakeWeb.register_uri(:post, uri, :body => '{"badge_id":6580}')
|
87
|
+
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edmodo-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabriel Cebrian
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fakeweb
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: awesome_print
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: To be used when creating apps for Edmodo
|
111
|
+
email:
|
112
|
+
- gabceb@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- MIT-LICENSE
|
121
|
+
- README.markdown
|
122
|
+
- Rakefile
|
123
|
+
- edmodo-api.gemspec
|
124
|
+
- lib/edmodo-api.rb
|
125
|
+
- lib/edmodo-api/client.rb
|
126
|
+
- lib/edmodo-api/config.rb
|
127
|
+
- lib/edmodo-api/request.rb
|
128
|
+
- lib/edmodo-api/version.rb
|
129
|
+
- spec/edmodo-api_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: https://github.com/gabceb/edmodo-api
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 1.9.2
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.8.24
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: Ruby wrapper for the Edmodo API
|
156
|
+
test_files: []
|