litmos-client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- litmos-client (0.0.3)
5
- hashugar
4
+ litmos-client (0.0.4)
6
5
  json
7
6
  litmos-client
8
7
  rest-client
@@ -14,13 +13,12 @@ GEM
14
13
  i18n (~> 0.6)
15
14
  multi_json (~> 1.0)
16
15
  git (1.2.5)
17
- hashugar (0.0.6)
18
16
  i18n (0.6.0)
19
17
  jeweler (1.5.2)
20
18
  bundler (~> 1.0.0)
21
19
  git (>= 1.2.5)
22
20
  rake
23
- json (1.7.4)
21
+ json (1.7.5)
24
22
  metaclass (0.0.1)
25
23
  mime-types (1.19)
26
24
  mocha (0.12.3)
data/README.rdoc CHANGED
@@ -41,7 +41,7 @@ For methods that aren't yet implemented in the gem, you can simply use the *get*
41
41
 
42
42
  == Dependencies
43
43
 
44
- Litmos-client depends on the Rest-client[https://github.com/archiloque/rest-client], JSON, and Hashugar[https://github.com/jsuchal/hashugar] gems (should be automatically loaded via the gemspec).
44
+ Litmos-client depends on the Rest-client[https://github.com/archiloque/rest-client], and JSON gems (should be automatically loaded via the gemspec).
45
45
 
46
46
  == TODO
47
47
  * Support for retrieving Teams and Courses
data/Rakefile CHANGED
@@ -15,14 +15,13 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "litmos-client"
16
16
  gem.homepage = "http://github.com/kennon/litmos-client"
17
17
  gem.license = "MIT"
18
- gem.version = "0.0.3"
18
+ gem.version = "0.0.4"
19
19
  gem.summary = %Q{Litmos-client is a Ruby wrapper for the Litmos API}
20
20
  gem.description = %Q{Litmos-Client is a Ruby gem that provides a wrapper for interacting with the Litmos Learning Management System API.}
21
21
  gem.email = "kennon@angryturnip.com"
22
22
  gem.authors = ["Kennon Ballou"]
23
23
  gem.add_dependency "rest-client"
24
24
  gem.add_dependency "json"
25
- gem.add_dependency "hashugar"
26
25
  end
27
26
  Jeweler::RubygemsDotOrgTasks.new
28
27
 
data/lib/litmos_client.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rest_client'
2
2
  require 'json'
3
- require 'hashugar'
4
3
 
5
4
  require File.dirname(__FILE__) + '/litmos_client/users'
6
5
  require File.dirname(__FILE__) + '/litmos_client/teams'
@@ -9,6 +8,7 @@ require File.dirname(__FILE__) + '/litmos_client/courses'
9
8
  module LitmosClient
10
9
  class NotFound < Exception; end
11
10
  class ApiError < Exception; end
11
+ class ArgumentError < Exception; end
12
12
 
13
13
  class API
14
14
  include LitmosClient::Users
@@ -44,7 +44,7 @@ module LitmosClient
44
44
  when 200, 201
45
45
  # 200 Success. User/Course etc updated, deleted or retrieved
46
46
  # 201 Success. User/Course etc created
47
- return StringHelpers.convert_hash_keys(JSON.parse(response))
47
+ return response.blank? ? true : StringHelpers.convert_hash_keys(JSON.parse(response))
48
48
 
49
49
  when 404 # 404 Not Found. The User/Course etc that you requested does not exist
50
50
  raise NotFound.new(response)
@@ -58,6 +58,63 @@ module LitmosClient
58
58
  end
59
59
  end
60
60
  end
61
+
62
+ def post(path, params={}, query_params={})
63
+ query_params = query_params.merge(:apikey => @api_key, :source => @source)
64
+ query_string = query_params.collect { |k,v| "#{k}=#{CGI::escape(v)}" }.join('&')
65
+ query_string = "?#{query_string}" unless query_string.blank?
66
+
67
+ options = {
68
+ :content_type => :json,
69
+ :accept => :json,
70
+ }
71
+
72
+ RestClient.post("#{@litmosURL}/#{path}#{query_string}", params.to_json, options) do |response, request, result|
73
+ case response.code
74
+ when 200, 201
75
+ # 200 Success. User/Course etc updated, deleted or retrieved
76
+ # 201 Success. User/Course etc created
77
+ return response.blank? ? true : StringHelpers.convert_hash_keys(JSON.parse(response))
78
+
79
+ when 404 # 404 Not Found. The User/Course etc that you requested does not exist
80
+ raise NotFound.new(response)
81
+
82
+ else
83
+ # 400 Bad Request. Check that your Uri and request body is well formed
84
+ # 403 Forbidden. Check your API key, HTTPS setting, Source parameter etc
85
+ # 409 Conflict. Often occurs when trying to create an item that already exists
86
+ raise ApiError.new(response)
87
+
88
+ end
89
+ end
90
+ end
91
+
92
+ def delete(path, params={})
93
+ options = {
94
+ :content_type => :json,
95
+ :accept => :json,
96
+ :params => params.merge(:apikey => @api_key, :source => @source)
97
+ }
98
+ RestClient.delete("#{@litmosURL}/#{path}", options) do |response, request, result|
99
+ case response.code
100
+ when 200, 201
101
+ # 200 Success. User/Course etc updated, deleted or retrieved
102
+ # 201 Success. User/Course etc created
103
+ return response.blank? ? true : StringHelpers.convert_hash_keys(JSON.parse(response))
104
+
105
+ when 404 # 404 Not Found. The User/Course etc that you requested does not exist
106
+ raise NotFound.new(response)
107
+
108
+ else
109
+ # 400 Bad Request. Check that your Uri and request body is well formed
110
+ # 403 Forbidden. Check your API key, HTTPS setting, Source parameter etc
111
+ # 409 Conflict. Often occurs when trying to create an item that already exists
112
+ raise ApiError.new(response)
113
+
114
+ end
115
+ end
116
+ end
117
+
61
118
  end
62
119
 
63
120
  module StringHelpers
@@ -5,7 +5,13 @@ module LitmosClient
5
5
  end
6
6
 
7
7
  def find_course_by_id(id)
8
- get("courses/#{id}").to_hashugar
8
+ get("courses/#{id}")
9
+ rescue NotFound
10
+ nil
11
+ end
12
+
13
+ def find_courses_by_user_id(id)
14
+ get("users/#{id}/courses")
9
15
  rescue NotFound
10
16
  nil
11
17
  end
@@ -1,13 +1,37 @@
1
1
  module LitmosClient
2
2
  module Teams
3
- def teams(params={})
4
- get :teams, params
3
+ def teams(options={})
4
+ get :teams, options
5
5
  end
6
6
 
7
7
  def find_team_by_id(id)
8
- get("teams/#{id}").to_hashugar
8
+ get("teams/#{id}")
9
9
  rescue NotFound
10
10
  nil
11
11
  end
12
+
13
+ def find_users_by_team_id(id)
14
+ get("teams/#{id}/users")
15
+ rescue NotFound
16
+ nil
17
+ end
18
+
19
+ def add_user_to_team(options={})
20
+ raise ArgumentError.new("team_id is required") if options[:team_id].blank?
21
+ raise ArgumentError.new("user_id is required") if options[:user_id].blank?
22
+
23
+ params = {
24
+ 'Id' => options[:user_id]
25
+ }
26
+
27
+ post("teams/#{options[:team_id]}/users", [params])
28
+ end
29
+
30
+ def remove_user_from_team(options={})
31
+ raise ArgumentError.new("team_id is required") if options[:team_id].blank?
32
+ raise ArgumentError.new("user_id is required") if options[:user_id].blank?
33
+
34
+ delete("teams/#{options[:team_id]}/users/#{options[:user_id]}")
35
+ end
12
36
  end
13
37
  end
@@ -1,13 +1,32 @@
1
1
  module LitmosClient
2
2
  module Users
3
3
  def users(params={})
4
- get :users, params
4
+ get(:users, params)
5
5
  end
6
6
 
7
7
  def find_user_by_id(id)
8
- get("users/#{id}").to_hashugar
8
+ get("users/#{id}")
9
9
  rescue NotFound
10
10
  nil
11
11
  end
12
+
13
+ def create_user(options={})
14
+ raise ArgumentError.new(":username is required") if options[:username].blank?
15
+ raise ArgumentError.new(":first_name is required") if options[:first_name].blank?
16
+ raise ArgumentError.new(":last_name is required") if options[:last_name].blank?
17
+ raise ArgumentError.new(":email is required") if options[:email].blank?
18
+
19
+ params = {
20
+ 'UserName' => options[:username],
21
+ 'FirstName' => options[:first_name],
22
+ 'LastName' => options[:last_name],
23
+ 'Email' => options[:email],
24
+ 'DisableMessages' => true,
25
+ 'IsCustomUsername' => true,
26
+ 'SkipFirstLogin' => true
27
+ }
28
+
29
+ post("users", params)
30
+ end
12
31
  end
13
32
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "litmos-client"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kennon Ballou"]
12
- s.date = "2012-08-21"
12
+ s.date = "2012-09-13"
13
13
  s.description = "Litmos-Client is a Ruby gem that provides a wrapper for interacting with the Litmos Learning Management System API."
14
14
  s.email = "kennon@angryturnip.com"
15
15
  s.extra_rdoc_files = [
@@ -59,7 +59,6 @@ Gem::Specification.new do |s|
59
59
  s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
60
60
  s.add_runtime_dependency(%q<rest-client>, [">= 0"])
61
61
  s.add_runtime_dependency(%q<json>, [">= 0"])
62
- s.add_runtime_dependency(%q<hashugar>, [">= 0"])
63
62
  else
64
63
  s.add_dependency(%q<litmos-client>, [">= 0"])
65
64
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -74,7 +73,6 @@ Gem::Specification.new do |s|
74
73
  s.add_dependency(%q<shoulda>, [">= 2.11.3"])
75
74
  s.add_dependency(%q<rest-client>, [">= 0"])
76
75
  s.add_dependency(%q<json>, [">= 0"])
77
- s.add_dependency(%q<hashugar>, [">= 0"])
78
76
  end
79
77
  else
80
78
  s.add_dependency(%q<litmos-client>, [">= 0"])
@@ -90,7 +88,6 @@ Gem::Specification.new do |s|
90
88
  s.add_dependency(%q<shoulda>, [">= 2.11.3"])
91
89
  s.add_dependency(%q<rest-client>, [">= 0"])
92
90
  s.add_dependency(%q<json>, [">= 0"])
93
- s.add_dependency(%q<hashugar>, [">= 0"])
94
91
  end
95
92
  end
96
93
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litmos-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kennon Ballou
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-21 00:00:00 Z
18
+ date: 2012-09-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -219,20 +219,6 @@ dependencies:
219
219
  version: "0"
220
220
  version_requirements: *id013
221
221
  name: json
222
- - !ruby/object:Gem::Dependency
223
- prerelease: false
224
- type: :runtime
225
- requirement: &id014 !ruby/object:Gem::Requirement
226
- none: false
227
- requirements:
228
- - - ">="
229
- - !ruby/object:Gem::Version
230
- hash: 3
231
- segments:
232
- - 0
233
- version: "0"
234
- version_requirements: *id014
235
- name: hashugar
236
222
  description: Litmos-Client is a Ruby gem that provides a wrapper for interacting with the Litmos Learning Management System API.
237
223
  email: kennon@angryturnip.com
238
224
  executables: []