talentlms 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac0dec21de1848e106494349efde89e7a0987f32
4
+ data.tar.gz: 3170a23e6d4f092f36ff8a571b705dbc11de8c8c
5
+ SHA512:
6
+ metadata.gz: ca1f462b79ebb2456518e8d502b53d0a51c29b0fc1266d63d5a2c3646dcf9dc0d2dbd3e9197c4bf5b33c8fa03abbe4fbad24357f06d3e2779dca8ee326f9c1f1
7
+ data.tar.gz: 37ddedea22e72c351cfe3334eb453996c82645068bca673d30743005f9944bdf22420e5d414b193abd9dbe942df29943fe2ba923d7cb17f07f3d0a7bda327884
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in talentlms.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tyler Mercier
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,105 @@
1
+ # Talentlms
2
+
3
+ Ruby gem for the [Talent LMS API](http://www.talentlms.com)
4
+
5
+ ## Status
6
+ [![Gem Version](https://badge.fury.io/rb/talentlms.png)](http://badge.fury.io/rb/talentlms)
7
+ [![Build Status](https://secure.travis-ci.org/tylermercier/talentlms.png)](http://travis-ci.org/tylermercier/talentlms)
8
+ [![Code Climate](https://codeclimate.com/github/tylermercier/talentlms.png)](https://codeclimate.com/github/tylermercier/talentlms)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'talentlms'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install talentlms
23
+
24
+ ## Usage
25
+
26
+ @client = TalentLMS::Client.new({
27
+ :api_key => '03a82de6de2d939564aa607b0e24a030b5047c54ed87c77fea',
28
+ :sub_domain => 'example'
29
+ })
30
+
31
+ @client.users
32
+
33
+ @client.users(:id => 1)
34
+
35
+ @client.users(:email => 'tyler@example.com')
36
+
37
+ @client.courses
38
+
39
+ @client.courses(:id => 1)
40
+
41
+ @client.categories
42
+
43
+ @client.categories(:id => 1)
44
+
45
+ @client.groups
46
+
47
+ @client.groups(:id => 1)
48
+
49
+ @client.branches
50
+
51
+ @client.branches(:id => 1)
52
+
53
+ @client.siteinfo
54
+
55
+ @client.siteinfo
56
+
57
+ @client.userlogin
58
+
59
+ @client.userlogout
60
+
61
+ @client.usersignup
62
+
63
+ @client.usersetstatus(:user_id =>1, status => 'complete')
64
+
65
+ @client.forgotusername(email => 'tyler@example.com', domain_url => 'http://www.example.com/login')
66
+
67
+ @client.forgotpassword(username => 'tyler', domain_url => 'http://www.example.com', redirect_url => 'http://www.example.com/login')
68
+
69
+ @client.addusertocourse
70
+
71
+ @client.addusertobranch(:user_id => 1, :branch_id => 111)
72
+
73
+ @client.addcoursetobranch(:course_id => 1, :branch_id => 111)
74
+
75
+ @client.addusertogroup(:user_id => 1, :group_key => 12)
76
+
77
+ @client.removeuserfromgroup(:user_id => 1, :group_id => 12)
78
+
79
+ @client.addcoursetogroup(:course_id => 1, :group_id => 12)
80
+
81
+ @client.gotocourse(:user_id => 1, :course_id => 1)
82
+
83
+ @client.buycourse
84
+
85
+ @client.buycategorycourses
86
+
87
+ @client.getcustomregistrationfields
88
+
89
+ @client.categoryleafsandcourses(:id => 3)
90
+
91
+ @client.getusersprogressinunits(:unit_id => 56, :user_id => 1)
92
+
93
+ @client.creategroup
94
+
95
+ @client.createbranch
96
+
97
+ @client.ratelimit
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it ( http://github.com/<my-github-username>/talentlms/fork )
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler"
3
+ require "bundler/gem_tasks"
4
+ require 'rake/testtask'
5
+
6
+ task default: 'test'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,2 @@
1
+ require "talentlms/version"
2
+ require "talentlms/client"
@@ -0,0 +1,35 @@
1
+ require 'http'
2
+ require 'json'
3
+ require 'base64'
4
+
5
+ module TalentLMS
6
+ class Client
7
+ def initialize(config = {})
8
+ raise ArgumentError.new('Missing API key') unless config.has_key?(:api_key)
9
+ @auth_header = auth_header(config[:api_key])
10
+
11
+ raise ArgumentError.new('Missing Sub Domain') unless config.has_key?(:sub_domain)
12
+ @sub_domain = config[:sub_domain]
13
+
14
+ @version = 'v1' || config[:version]
15
+ end
16
+
17
+ def auth_header(username)
18
+ key = Base64.strict_encode64("#{username}:")
19
+ { 'Authorization' => "Basic #{key}" }
20
+ end
21
+
22
+ def route_for_method(method, options=nil)
23
+ url = "https://#{@sub_domain}.talentlms.com/api/#{@version}/#{method}"
24
+ return url if options.nil?
25
+ arguments = options.map {|k,v| "#{k}:#{v}"}.join(',')
26
+ "#{url}/#{arguments}"
27
+ end
28
+
29
+ def method_missing(sym, *args, &block)
30
+ url = route_for_method(sym.to_s, *args)
31
+ response = HTTP.with(@auth_header).get(url)
32
+ JSON.parse(response)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Talentlms
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'talentlms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "talentlms"
8
+ spec.version = Talentlms::VERSION
9
+ spec.authors = ["Tyler Mercier"]
10
+ spec.email = ["tylermercier@gmail.com"]
11
+ spec.summary = %q{Talent LMS API gem}
12
+ spec.description = %q{Talent LMS API gem}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "http"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "minitest-reporters"
25
+ spec.add_development_dependency "webmock"
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ require 'webmock/minitest'
4
+
5
+ Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new(color: true))
6
+
7
+ ENV['RACK_ENV'] = 'test'
8
+
9
+ Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each do |file|
10
+ require File.basename(file, File.extname(file))
11
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Client' do
4
+ before do
5
+ @key = '03a82de6de2d939564aa607b0e24a030b5047c54ed87c77fea'
6
+ @client = TalentLMS::Client.new({
7
+ :api_key => @key,
8
+ :sub_domain => 'example'
9
+ })
10
+ @headers = {
11
+ 'Authorization' => 'Basic MDNhODJkZTZkZTJkOTM5NTY0YWE2MDdiMGUyNGEwMzBiNTA0N2M1NGVkODdjNzdmZWE6',
12
+ 'Host' => 'example.talentlms.com',
13
+ 'User-Agent' => 'RubyHTTPGem/0.5.0'
14
+ }
15
+ end
16
+
17
+ describe '#auth_header' do
18
+ it 'adds auth header without white space' do
19
+ expected = @headers["Authorization"]
20
+ assert_equal expected, @client.auth_header(@key)["Authorization"]
21
+ end
22
+ end
23
+
24
+ describe '#route_for_method' do
25
+ it 'creates index route' do
26
+ expected = 'https://example.talentlms.com/api/v1/users'
27
+ assert_equal expected, @client.route_for_method('users')
28
+ end
29
+
30
+ it 'creates index route with argument' do
31
+ expected = 'https://example.talentlms.com/api/v1/users/id:1'
32
+ assert_equal expected, @client.route_for_method('users', :id => 1)
33
+ end
34
+
35
+ it 'creates index route with arguments' do
36
+ expected = 'https://example.talentlms.com/api/v1/usersetstatus/user_id:1,status:ok'
37
+ assert_equal expected, @client.route_for_method('usersetstatus', :user_id => 1, :status => 'ok')
38
+ end
39
+ end
40
+
41
+ describe 'API' do
42
+ it 'finds user by id' do
43
+ stub_request(:get, "https://example.talentlms.com/api/v1/users/id:1").
44
+ with(:headers => @headers).
45
+ to_return(:status => 200, :body => "{\"id\": 1}", :headers => {})
46
+
47
+ expected = {"id" => 1}
48
+ assert_equal expected, @client.users(:id => 1)
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: talentlms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Mercier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Talent LMS API gem
84
+ email:
85
+ - tylermercier@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/talentlms.rb
97
+ - lib/talentlms/client.rb
98
+ - lib/talentlms/version.rb
99
+ - talentlms.gemspec
100
+ - test/test_helper.rb
101
+ - test/unit/client_test.rb
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.14
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Talent LMS API gem
126
+ test_files:
127
+ - test/test_helper.rb
128
+ - test/unit/client_test.rb