edmodo-api 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -43,11 +43,10 @@ You're welcome to fork this project and send pull requests. Just remember to inc
43
43
  TO DO
44
44
  ---------
45
45
 
46
- - Finish implementation of all the methods
46
+ - Find a way to pass a string as query params to a POST requests when using HTTParty to finish implementing the methods that are not supported yet
47
47
  - Thinking about adding all the requests name into an array and overriding the Ruby method_missing method to DRY up the client code
48
- - Adding tests for every method
49
48
 
50
- Edmodo methods that will be supported
49
+ Supported Edmodo API methods
51
50
  ---------
52
51
 
53
52
  - launchRequests
@@ -67,8 +66,6 @@ Edmodo methods that will be supported
67
66
  - parents
68
67
  - children
69
68
  - profiles
70
- - userPost
71
- - turnInAssignment
72
69
  - registerBadge
73
70
  - updateBadge
74
71
  - awardBadge
@@ -78,4 +75,8 @@ Edmodo methods that will be supported
78
75
  - newEvent
79
76
  - addToLibrary
80
77
  - setNotification
78
+ - UserPost
79
+ - turnInAssignment
80
+ - NewEvent
81
+ - AddToLibrary
81
82
 
@@ -0,0 +1,20 @@
1
+ module Edmodo
2
+ module API
3
+ module Normalizer
4
+ EDMODO_JSON_NORMALIZER = Proc.new { |query|
5
+ query.map do |key, v|
6
+ value = String.new
7
+
8
+ if v.is_a?(Array)
9
+ value = URI.encode(v.to_json, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
10
+ else
11
+ value = URI.encode(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
12
+ end
13
+
14
+ "#{key}=#{value}"
15
+ end.join('&')
16
+ }
17
+ end
18
+ end
19
+ end
20
+
@@ -14,7 +14,7 @@ module Edmodo
14
14
  when :get
15
15
  self.class.get(uri, query: query )
16
16
  when :post
17
- self.class.post(uri, query: query)
17
+ self.class.post(uri, query: query, :query_string_normalizer => Edmodo::API::Normalizer::EDMODO_JSON_NORMALIZER)
18
18
  else
19
19
  raise EdmodoApiError.new "EdmodoAPI Error: Request Method error."
20
20
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Edmodo
4
4
  module API
5
- VERSION = "0.0.3"
5
+ VERSION = "0.1.0"
6
6
  end
7
7
  end
data/lib/edmodo-api.rb CHANGED
@@ -2,5 +2,6 @@
2
2
 
3
3
  require 'edmodo-api/version'
4
4
  require 'edmodo-api/config'
5
+ require 'edmodo-api/normalizer'
5
6
  require 'edmodo-api/request'
6
7
  require 'edmodo-api/client'
@@ -59,6 +59,16 @@ describe Edmodo::API::Client do
59
59
  end
60
60
  end
61
61
 
62
+ describe 'GET Requests in Production' do
63
+ it 'should get the correct hash back from the launchRequest request when environment is production' do
64
+ client = Edmodo::API::Client.new(@api_key, :mode => :production)
65
+
66
+ response = client.launch_requests("5c18c7")
67
+
68
+ 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}]}
69
+ end
70
+ end
71
+
62
72
  describe 'GET Requests' do
63
73
  before do
64
74
  @client = Edmodo::API::Client.new(@api_key)
@@ -194,20 +204,16 @@ describe Edmodo::API::Client do
194
204
 
195
205
  it 'should get the correct response back from the userPost request' do
196
206
 
197
- pending("This call has to be fixed")
198
-
199
- response = @client.user_post("b020c42d1", "This is my test message", {:user_token => "b020c42d1", :user_token => "693d5c765", :group_id => 379557}, [{:type => "link", :title => "A link", :url => "http://www.edmodo.com"}, {:type => "embed", :title => "An embed with an optional thumbnail url", :thumb_url => "http://images.edmodo.com/images/logos/edmodo_134x43.png"}])
207
+ response = @client.user_post("b020c42d1", "This is my test message", [{:user_token => "b020c42d1"}, {:user_token => "693d5c765"}, {:group_id => 379557}], [{:type => "link", :title => "A link", :url => "http://www.edmodo.com"}, {:type => "embed", :title => "An embed with an optional thumbnail url", :thumb_url => "http://images.edmodo.com/images/logos/edmodo_134x43.png"}])
200
208
 
201
- response.should == {:status => "success"}
209
+ response.should == {"status" => "success"}
202
210
  end
203
211
 
204
212
  it 'should get the correct response back from the turnInAssignment request' do
205
213
 
206
- pending("This call has to be fixed")
207
-
208
- response = @client.turn_in_assignment("83a8e614d", 4738052, "Here is my assignment submission", {:type => "link", :title => "A link", :url => "http://www.edmodo.com"})
214
+ response = @client.turn_in_assignment("83a8e614d", 4738052, "Here is my assignment submission", [{:type => "link", :title => "A link", :url => "http://www.edmodo.com"}])
209
215
 
210
- response.should == {:status => "success"}
216
+ response.should == {"status" => "success"}
211
217
  end
212
218
 
213
219
  it 'should get the correct hash response from the registerBadge request' do
@@ -248,9 +254,8 @@ describe Edmodo::API::Client do
248
254
 
249
255
  it 'should get the correct hash response from the newEvent request' do
250
256
 
251
- pending("This call has to be fixed")
252
-
253
257
  recipients = [{:user_token => "b020c42d1"},{:group_id => 379557}]
258
+
254
259
  response = @client.new_event("b020c42d1", "Pizza party tomorrow", "2011-12-07", "2011-12-07", recipients)
255
260
 
256
261
  response.should == {"event_id" => 621119}
@@ -258,8 +263,6 @@ describe Edmodo::API::Client do
258
263
 
259
264
  it 'should get the correct hash response from the addToLibrary request' do
260
265
 
261
- pending("This call has to be fixed")
262
-
263
266
  resource = {:type => "link", :title => "A link", :url => "http://www.edmodo.com", :thumb_url => "http://images.edmodo.com/images/logos/edmodo_134x43.png" }
264
267
  response = @client.add_to_library("b020c42d1", true, resource)
265
268
 
@@ -3,6 +3,29 @@ uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/launchRequests.json?api_key=#{
3
3
 
4
4
  FakeWeb.register_uri(:get, uri, :body => '{"error":{"code":3000,"message":"Unauthorized API request"}}', :status => ["401", "Authorization Required"])
5
5
 
6
+ # launchRequest request uri on production
7
+ uri = "#{Edmodo::API::Config.endpoints[:production]}/launchRequests.json?api_key=#{@api_key}&launch_key=5c18c7"
8
+
9
+ FakeWeb.register_uri(:get, uri,
10
+ :body => ' {
11
+ "user_type":"TEACHER",
12
+ "user_token":"b020c42d1",
13
+ "first_name":"Bob",
14
+ "last_name":"Smith",
15
+ "avatar_url":"http://edmodoimages.s3.amazonaws.com/default_avatar.png",
16
+ "thumb_url":"http://edmodoimages.s3.amazonaws.com/default_avatar_t.png",
17
+ "groups":[
18
+ {
19
+ "group_id":379557,
20
+ "is_owner":1
21
+ },
22
+ {
23
+ "group_id":379562,
24
+ "is_owner":1
25
+ }
26
+ ]
27
+ }')
28
+
6
29
  # launchRequest request uri
7
30
  uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/launchRequests.json?api_key=#{@api_key}&launch_key=5c18c7"
8
31
 
@@ -1,17 +1,12 @@
1
1
  # -- POST REQUESTS ---
2
2
 
3
3
  # userPost request uri
4
- recipients = "[{'user_token':'b020c42d1'},{'user_token':'693d5c765'},{'group_id':379557}]"
5
- attachments = "[{'type':'link','title':'A link','url':'http://www.edmodo.com'},{'type':'embed','title':'An embed with an optional thumbnail url','thumb_url':'http://images.edmodo.com/images/logos/edmodo_134x43.png'}]"
6
-
7
- uri = URI.encode "#{Edmodo::API::Config.endpoints[:sandbox]}/userPost?api_key=#{@api_key}&user_token=b020c42d1&content=This%20is%20my%20test%20message&recipients=#{recipients}&attachments=#{attachments}"
4
+ uri = "https://appsapi.edmodobox.com/v1/userPost?api_key=1234567890abcdefghijklmn&user_token=b020c42d1&content=This%20is%20my%20test%20message&recipients=%5B%7B%22user_token%22%3A%22b020c42d1%22%7D%2C%7B%22user_token%22%3A%22693d5c765%22%7D%2C%7B%22group_id%22%3A379557%7D%5D&attachments=%5B%7B%22type%22%3A%22link%22%2C%22title%22%3A%22A%20link%22%2C%22url%22%3A%22http%3A%2F%2Fwww.edmodo.com%22%7D%2C%7B%22type%22%3A%22embed%22%2C%22title%22%3A%22An%20embed%20with%20an%20optional%20thumbnail%20url%22%2C%22thumb_url%22%3A%22http%3A%2F%2Fimages.edmodo.com%2Fimages%2Flogos%2Fedmodo_134x43.png%22%7D%5D"
8
5
 
9
6
  FakeWeb.register_uri(:post, uri, :body => '{"status":"success"}')
10
7
 
11
8
  # turnInAssignment request uri
12
- attachments = "[{'type':'link','title':'A link','url':'http://www.edmodo.com'}]"
13
-
14
- uri = URI.encode "#{Edmodo::API::Config.endpoints[:sandbox]}/turnInAssignment?api_key=#{@api_key}&user_token=b020c42d1&assignment_id=4738052&content=Here%20is%20my%20assignment%20submission&attachments=#{attachments}"
9
+ uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/turnInAssignment?api_key=#{@api_key}&user_token=83a8e614d&assignment_id=4738052&content=Here%20is%20my%20assignment%20submission&attachments=%5B%7B%22type%22%3A%22link%22%2C%22title%22%3A%22A%20link%22%2C%22url%22%3A%22http%3A%2F%2Fwww.edmodo.com%22%7D%5D"
15
10
 
16
11
  FakeWeb.register_uri(:post, uri, :body => '{"status":"success"}')
17
12
 
@@ -46,16 +41,13 @@ uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/setGrade?api_key=#{@api_key}&g
46
41
  FakeWeb.register_uri(:post, uri, :body => '{"user_token":"83a8e614d", "score":"3", "total":"10"}')
47
42
 
48
43
  # newEvent request uri
49
- receipients = URI.encode '[{"user_token":"b020c42d1"},{"group_id":379557}]'
50
-
51
- uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/newEvent?api_key=#{@api_key}&user_token=b020c42d1&description=Pizza+party+tomorrow&start_date=2011-12-07&end_date=2011-12-07&recipients=#{receipients}"
44
+ uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/newEvent?api_key=#{@api_key}&user_token=b020c42d1&description=Pizza%20party%20tomorrow&start_date=2011-12-07&end_date=2011-12-07&recipients=%5B%7B%22user_token%22%3A%22b020c42d1%22%7D%2C%7B%22group_id%22%3A379557%7D%5D"
52
45
 
53
46
  FakeWeb.register_uri(:post, uri, :body => '{"event_id":621119}')
54
47
 
55
48
  # addToLibrary request uri
56
- resource = URI.encode '{"type":"link","title":"A link","url":"http://www.edmodo.com","thumb_url":"http://images.edmodo.com/images/logos/edmodo_134x43.png"}'
57
49
 
58
- uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/addToLibrary?api_key=#{@api_key}&user_token=b020c42d1&publisher_owned=1&resource=#{resource}"
50
+ uri = "#{Edmodo::API::Config.endpoints[:sandbox]}/addToLibrary?api_key=#{@api_key}&user_token=b020c42d1&publisher_owned=1&resource=%7B%3Atype%3D%3E%22link%22%2C%20%3Atitle%3D%3E%22A%20link%22%2C%20%3Aurl%3D%3E%22http%3A%2F%2Fwww.edmodo.com%22%2C%20%3Athumb_url%3D%3E%22http%3A%2F%2Fimages.edmodo.com%2Fimages%2Flogos%2Fedmodo_134x43.png%22%7D"
59
51
 
60
52
  FakeWeb.register_uri(:post, uri, :body => '{"library_item_id":"456"}')
61
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edmodo-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-05 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -125,6 +125,7 @@ files:
125
125
  - lib/edmodo-api.rb
126
126
  - lib/edmodo-api/client.rb
127
127
  - lib/edmodo-api/config.rb
128
+ - lib/edmodo-api/normalizer.rb
128
129
  - lib/edmodo-api/request.rb
129
130
  - lib/edmodo-api/version.rb
130
131
  - spec/edmodo-api_spec.rb