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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e7382d7696dd177403fb5baae0e0616dce60b86
4
- data.tar.gz: 2a183732ab174a48b4389e9142c2f89072c63785
3
+ metadata.gz: 4e3b54836421ee2bd2c72bfde400bbf7482c63bb
4
+ data.tar.gz: 00ec7ae82a6eb16c3404b0471f3f3add14d3b4e2
5
5
  SHA512:
6
- metadata.gz: 8348f14f0370ea7bdace178d85c1b019a6c17b44231550156af73fb1e4f4959a712fac350e9478a18d72772391086f23b5b09cdd61ed7cb4070fbd7dcd44350c
7
- data.tar.gz: 776c9f0bc04a9b9ce1d6813dfc8695fe39649c1394b365d4beec28a3696b469fa684f4ce2167353072b36e03d64eeda1219400583a9e0e4f4632f900b9766a6e
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
- @client = TalentLMS::Client.new({
26
+ TalentLMS.init({
27
27
  :api_key => '03a82de6de2d939564aa607b0e24a030b5047c54ed87c77fea',
28
28
  :sub_domain => 'example'
29
29
  })
30
30
 
31
- @client.users
31
+ TalentLMS.users
32
32
 
33
- @client.users(:id => 1)
33
+ TalentLMS.users(:id => 1)
34
34
 
35
- @client.users(:email => 'tyler@example.com')
35
+ TalentLMS.users(:email => 'tyler@example.com')
36
36
 
37
- @client.courses
37
+ TalentLMS.courses
38
38
 
39
- @client.courses(:id => 1)
39
+ TalentLMS.courses(:id => 1)
40
40
 
41
- @client.categories
41
+ TalentLMS.categories
42
42
 
43
- @client.categories(:id => 1)
43
+ TalentLMS.categories(:id => 1)
44
44
 
45
- @client.groups
45
+ TalentLMS.groups
46
46
 
47
- @client.groups(:id => 1)
47
+ TalentLMS.groups(:id => 1)
48
48
 
49
- @client.branches
49
+ TalentLMS.branches
50
50
 
51
- @client.branches(:id => 1)
51
+ TalentLMS.branches(:id => 1)
52
52
 
53
- @client.siteinfo
53
+ TalentLMS.siteinfo
54
54
 
55
- @client.siteinfo
55
+ TalentLMS.siteinfo
56
56
 
57
- @client.userlogin
57
+ TalentLMS.userlogin
58
58
 
59
- @client.userlogout
59
+ TalentLMS.userlogout
60
60
 
61
- @client.usersignup
61
+ TalentLMS.usersignup
62
62
 
63
- @client.usersetstatus(:user_id =>1, status => 'complete')
63
+ TalentLMS.usersetstatus(:user_id =>1, status => 'complete')
64
64
 
65
- @client.forgotusername(email => 'tyler@example.com', domain_url => 'http://www.example.com/login')
65
+ TalentLMS.forgotusername(email => 'tyler@example.com', domain_url => 'http://www.example.com/login')
66
66
 
67
- @client.forgotpassword(username => 'tyler', domain_url => 'http://www.example.com', redirect_url => 'http://www.example.com/login')
67
+ TalentLMS.forgotpassword(username => 'tyler', domain_url => 'http://www.example.com', redirect_url => 'http://www.example.com/login')
68
68
 
69
- @client.addusertocourse
69
+ TalentLMS.addusertocourse
70
70
 
71
- @client.addusertobranch(:user_id => 1, :branch_id => 111)
71
+ TalentLMS.addusertobranch(:user_id => 1, :branch_id => 111)
72
72
 
73
- @client.addcoursetobranch(:course_id => 1, :branch_id => 111)
73
+ TalentLMS.addcoursetobranch(:course_id => 1, :branch_id => 111)
74
74
 
75
- @client.addusertogroup(:user_id => 1, :group_key => 12)
75
+ TalentLMS.addusertogroup(:user_id => 1, :group_key => 12)
76
76
 
77
- @client.removeuserfromgroup(:user_id => 1, :group_id => 12)
77
+ TalentLMS.removeuserfromgroup(:user_id => 1, :group_id => 12)
78
78
 
79
- @client.addcoursetogroup(:course_id => 1, :group_id => 12)
79
+ TalentLMS.addcoursetogroup(:course_id => 1, :group_id => 12)
80
80
 
81
- @client.gotocourse(:user_id => 1, :course_id => 1)
81
+ TalentLMS.gotocourse(:user_id => 1, :course_id => 1)
82
82
 
83
- @client.buycourse
83
+ TalentLMS.buycourse
84
84
 
85
- @client.buycategorycourses
85
+ TalentLMS.buycategorycourses
86
86
 
87
- @client.getcustomregistrationfields
87
+ TalentLMS.getcustomregistrationfields
88
88
 
89
- @client.categoryleafsandcourses(:id => 3)
89
+ TalentLMS.categoryleafsandcourses(:id => 3)
90
90
 
91
- @client.getusersprogressinunits(:unit_id => 56, :user_id => 1)
91
+ TalentLMS.getusersprogressinunits(:unit_id => 56, :user_id => 1)
92
92
 
93
- @client.creategroup
93
+ TalentLMS.creategroup
94
94
 
95
- @client.createbranch
95
+ TalentLMS.createbranch
96
96
 
97
- @client.ratelimit
97
+ TalentLMS.ratelimit
98
98
 
99
99
  ## Contributing
100
100
 
@@ -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 = TalentLMS::Client.new(options)
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
@@ -0,0 +1,8 @@
1
+ class ApiError < Exception
2
+ attr_accessor :message
3
+
4
+ def initialize(response)
5
+ @type = response["error"]["type"]
6
+ @message = response["error"]["message"]
7
+ end
8
+ end
@@ -5,10 +5,10 @@ require 'base64'
5
5
  module TalentLMS
6
6
  class Client
7
7
  def initialize(config = {})
8
- raise ArgumentError.new('Missing API key') unless config.has_key?(:api_key)
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 Sub Domain') unless config.has_key?(:sub_domain)
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]
@@ -1,3 +1,3 @@
1
1
  module Talentlms
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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
@@ -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.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-19 00:00:00.000000000 Z
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