talentlms 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -35
- data/lib/talentlms.rb +9 -2
- data/lib/talentlms/api_error.rb +8 -0
- data/lib/talentlms/client.rb +2 -2
- data/lib/talentlms/version.rb +1 -1
- data/test/unit/api_test.rb +9 -0
- data/test/unit/client_test.rb +16 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e3b54836421ee2bd2c72bfde400bbf7482c63bb
|
4
|
+
data.tar.gz: 00ec7ae82a6eb16c3404b0471f3f3add14d3b4e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1f6dcb4defd3c221e557505a7a2b5f767fe8891f05a318fd5b65043f359f54be630414b26cf0ae11dc1d3c0238cf6f3fdf1ce4fdafa5236997185be00b60ac
|
7
|
+
data.tar.gz: 7775aaf9949a97116e48f6e679f63039fdcce99b26919363acca7934f08f26e7d882947c6b2efab55b19c4b67616531978b54deb7b89006e61915921c265b26a
|
data/README.md
CHANGED
@@ -23,78 +23,78 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
|
26
|
+
TalentLMS.init({
|
27
27
|
:api_key => '03a82de6de2d939564aa607b0e24a030b5047c54ed87c77fea',
|
28
28
|
:sub_domain => 'example'
|
29
29
|
})
|
30
30
|
|
31
|
-
|
31
|
+
TalentLMS.users
|
32
32
|
|
33
|
-
|
33
|
+
TalentLMS.users(:id => 1)
|
34
34
|
|
35
|
-
|
35
|
+
TalentLMS.users(:email => 'tyler@example.com')
|
36
36
|
|
37
|
-
|
37
|
+
TalentLMS.courses
|
38
38
|
|
39
|
-
|
39
|
+
TalentLMS.courses(:id => 1)
|
40
40
|
|
41
|
-
|
41
|
+
TalentLMS.categories
|
42
42
|
|
43
|
-
|
43
|
+
TalentLMS.categories(:id => 1)
|
44
44
|
|
45
|
-
|
45
|
+
TalentLMS.groups
|
46
46
|
|
47
|
-
|
47
|
+
TalentLMS.groups(:id => 1)
|
48
48
|
|
49
|
-
|
49
|
+
TalentLMS.branches
|
50
50
|
|
51
|
-
|
51
|
+
TalentLMS.branches(:id => 1)
|
52
52
|
|
53
|
-
|
53
|
+
TalentLMS.siteinfo
|
54
54
|
|
55
|
-
|
55
|
+
TalentLMS.siteinfo
|
56
56
|
|
57
|
-
|
57
|
+
TalentLMS.userlogin
|
58
58
|
|
59
|
-
|
59
|
+
TalentLMS.userlogout
|
60
60
|
|
61
|
-
|
61
|
+
TalentLMS.usersignup
|
62
62
|
|
63
|
-
|
63
|
+
TalentLMS.usersetstatus(:user_id =>1, status => 'complete')
|
64
64
|
|
65
|
-
|
65
|
+
TalentLMS.forgotusername(email => 'tyler@example.com', domain_url => 'http://www.example.com/login')
|
66
66
|
|
67
|
-
|
67
|
+
TalentLMS.forgotpassword(username => 'tyler', domain_url => 'http://www.example.com', redirect_url => 'http://www.example.com/login')
|
68
68
|
|
69
|
-
|
69
|
+
TalentLMS.addusertocourse
|
70
70
|
|
71
|
-
|
71
|
+
TalentLMS.addusertobranch(:user_id => 1, :branch_id => 111)
|
72
72
|
|
73
|
-
|
73
|
+
TalentLMS.addcoursetobranch(:course_id => 1, :branch_id => 111)
|
74
74
|
|
75
|
-
|
75
|
+
TalentLMS.addusertogroup(:user_id => 1, :group_key => 12)
|
76
76
|
|
77
|
-
|
77
|
+
TalentLMS.removeuserfromgroup(:user_id => 1, :group_id => 12)
|
78
78
|
|
79
|
-
|
79
|
+
TalentLMS.addcoursetogroup(:course_id => 1, :group_id => 12)
|
80
80
|
|
81
|
-
|
81
|
+
TalentLMS.gotocourse(:user_id => 1, :course_id => 1)
|
82
82
|
|
83
|
-
|
83
|
+
TalentLMS.buycourse
|
84
84
|
|
85
|
-
|
85
|
+
TalentLMS.buycategorycourses
|
86
86
|
|
87
|
-
|
87
|
+
TalentLMS.getcustomregistrationfields
|
88
88
|
|
89
|
-
|
89
|
+
TalentLMS.categoryleafsandcourses(:id => 3)
|
90
90
|
|
91
|
-
|
91
|
+
TalentLMS.getusersprogressinunits(:unit_id => 56, :user_id => 1)
|
92
92
|
|
93
|
-
|
93
|
+
TalentLMS.creategroup
|
94
94
|
|
95
|
-
|
95
|
+
TalentLMS.createbranch
|
96
96
|
|
97
|
-
|
97
|
+
TalentLMS.ratelimit
|
98
98
|
|
99
99
|
## Contributing
|
100
100
|
|
data/lib/talentlms.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
require "talentlms/version"
|
2
2
|
require "talentlms/client"
|
3
|
+
require "talentlms/api_error"
|
3
4
|
|
4
5
|
module TalentLMS
|
5
6
|
extend self
|
6
7
|
|
7
8
|
def init(options={})
|
8
|
-
@@client =
|
9
|
+
@@client = Client.new(options)
|
9
10
|
end
|
10
11
|
|
11
12
|
def method_missing(method, *args, &block)
|
12
|
-
@@client.send(method, *args, &block)
|
13
|
+
response = @@client.send(method, *args, &block)
|
14
|
+
raise ApiError.new(response) if error_response?(response)
|
15
|
+
response
|
16
|
+
end
|
17
|
+
|
18
|
+
def error_response?(response)
|
19
|
+
response.is_a?(Hash) && response.key?("error")
|
13
20
|
end
|
14
21
|
end
|
data/lib/talentlms/client.rb
CHANGED
@@ -5,10 +5,10 @@ require 'base64'
|
|
5
5
|
module TalentLMS
|
6
6
|
class Client
|
7
7
|
def initialize(config = {})
|
8
|
-
raise ArgumentError.new('Missing
|
8
|
+
raise ArgumentError.new('Missing api_key') unless config.has_key?(:api_key)
|
9
9
|
@auth_header = auth_header(config[:api_key])
|
10
10
|
|
11
|
-
raise ArgumentError.new('Missing
|
11
|
+
raise ArgumentError.new('Missing sub_domain') unless config.has_key?(:sub_domain)
|
12
12
|
@sub_domain = config[:sub_domain]
|
13
13
|
|
14
14
|
@version = 'v1' || config[:version]
|
data/lib/talentlms/version.rb
CHANGED
data/test/unit/api_test.rb
CHANGED
@@ -37,4 +37,13 @@ describe 'API' do
|
|
37
37
|
expected = {"id" => 5}
|
38
38
|
assert_equal expected, TalentLMS.courses(:id => 5)
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'throws exception with details on error' do
|
42
|
+
error_message = "{\"error\":{\"type\": \"invalid_request_error\", \"message\": \"Invalid arguments provided\"}}"
|
43
|
+
stub_request(:get, "https://example.talentlms.com/api/v1/courses/id:5")
|
44
|
+
.with(:headers => @headers)
|
45
|
+
.to_return(:status => 200, :body => error_message, :headers => {})
|
46
|
+
|
47
|
+
assert_raises(ApiError) { TalentLMS.courses(:id => 5) }
|
48
|
+
end
|
40
49
|
end
|
data/test/unit/client_test.rb
CHANGED
@@ -9,6 +9,22 @@ describe 'Client' do
|
|
9
9
|
})
|
10
10
|
end
|
11
11
|
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'api_key is a required field' do
|
14
|
+
err = -> {
|
15
|
+
TalentLMS::Client.new(:sub_domain => '')
|
16
|
+
}.must_raise ArgumentError
|
17
|
+
err.message.must_match /api_key/
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'subdomain is a required field' do
|
21
|
+
err = -> {
|
22
|
+
TalentLMS::Client.new(:api_key => '')
|
23
|
+
}.must_raise ArgumentError
|
24
|
+
err.message.must_match /sub_domain/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
12
28
|
describe '#auth_header' do
|
13
29
|
it 'adds auth header without white space' do
|
14
30
|
expected = 'Basic MDNhODJkZTZkZTJkOTM5NTY0YWE2MDdiMGUyNGEwMzBiNTA0N2M1NGVkODdjNzdmZWE6'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talentlms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Mercier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- lib/talentlms.rb
|
98
|
+
- lib/talentlms/api_error.rb
|
98
99
|
- lib/talentlms/client.rb
|
99
100
|
- lib/talentlms/version.rb
|
100
101
|
- talentlms.gemspec
|