docebo 0.0.1 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +58 -0
- data/lib/docebo_ruby.rb +11 -2
- data/lib/docebo_ruby/api.rb +64 -0
- data/lib/docebo_ruby/configuration.rb +43 -0
- data/lib/docebo_ruby/course.rb +14 -0
- data/lib/docebo_ruby/engine.rb +3 -0
- data/lib/docebo_ruby/orgchart.rb +10 -0
- data/lib/docebo_ruby/parameters.rb +11 -0
- data/lib/docebo_ruby/resource.rb +19 -0
- data/lib/docebo_ruby/user.rb +27 -0
- data/lib/docebo_ruby/version.rb +3 -0
- metadata +43 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3883b022f7625a9ce41ece2c0044138f888d7aec
|
4
|
+
data.tar.gz: 5330293da3c9cc42e58cdf810f542f6b46749872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947b68778e5bf9a314ae081937d9ffe716beee49117058394fa27771554c7da84601c5f5e7d663100961d0c494123de004b7ee44cdde9ca75f15947cfb90d86f
|
7
|
+
data.tar.gz: 2ef3f22a19fb31964ec0559e2a1919e1cdf50a826b8b751703915cc66895fa560bf607a45a5783bfa464bd46261109f98c90a50534c6a985f0ab51e6ba0e047e
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
DoceboRuby - Ruby wrapper for Decobo LMS API
|
2
|
+
============================
|
3
|
+
|
4
|
+
### Installation
|
5
|
+
|
6
|
+
```sh
|
7
|
+
gem install docebo
|
8
|
+
```
|
9
|
+
|
10
|
+
or add it to Gemfile
|
11
|
+
|
12
|
+
```
|
13
|
+
gem 'docebo', '~> 0.0.1'
|
14
|
+
```
|
15
|
+
|
16
|
+
### Usage
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
api = Docebo::API.new(
|
20
|
+
key: 'key',
|
21
|
+
secret: 'secret',
|
22
|
+
url: 'your_saas_platform/api'
|
23
|
+
)
|
24
|
+
|
25
|
+
results = api.make_request(
|
26
|
+
'user',
|
27
|
+
'authenticate',
|
28
|
+
username: 'hello',
|
29
|
+
password: 'hell'
|
30
|
+
)
|
31
|
+
|
32
|
+
# Course
|
33
|
+
DoceboRuby::Course.all
|
34
|
+
|
35
|
+
# User
|
36
|
+
DoceboRuby::User.authenticate('john', 'Pa$$W0rd')
|
37
|
+
DoceboRuby::User.check_username('john')
|
38
|
+
DoceboRuby::User.sso_url('john')
|
39
|
+
|
40
|
+
# OrgChart
|
41
|
+
DoceboRuby::Orgchart.create_node(attributes)
|
42
|
+
```
|
43
|
+
|
44
|
+
### TODO
|
45
|
+
|
46
|
+
Create User, Courses, etc. API classes.
|
47
|
+
|
48
|
+
### Contributions
|
49
|
+
|
50
|
+
1. Fork this repository.
|
51
|
+
2. Create your own feature and spec.
|
52
|
+
3. Create a pull request.
|
53
|
+
|
54
|
+
To run test
|
55
|
+
|
56
|
+
```sh
|
57
|
+
rspec
|
58
|
+
```
|
data/lib/docebo_ruby.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
+
require 'docebo_ruby/configuration'
|
2
|
+
require 'docebo_ruby/api'
|
3
|
+
require 'docebo_ruby/parameters'
|
4
|
+
require 'docebo_ruby/resource'
|
5
|
+
require 'docebo_ruby/course'
|
6
|
+
require 'docebo_ruby/orgchart'
|
7
|
+
require 'docebo_ruby/user'
|
8
|
+
|
1
9
|
module DoceboRuby
|
10
|
+
if defined?(Rails)
|
11
|
+
require 'docebo_ruby/engine'
|
12
|
+
end
|
2
13
|
class ArgumentError < Exception; end
|
3
14
|
class NotFound < Exception; end
|
4
15
|
class RequestError < Exception; end
|
5
16
|
end
|
6
17
|
|
7
|
-
require 'docebo_ruby/api'
|
8
|
-
require 'docebo_ruby/parameters'
|
9
18
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require 'digest/sha1'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module DoceboRuby
|
7
|
+
class API
|
8
|
+
def initialize
|
9
|
+
@url = DoceboRuby.config.api_url
|
10
|
+
@key = DoceboRuby.config.api_key
|
11
|
+
@secret = DoceboRuby.config.api_secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def send_request(api, method, params, &block)
|
15
|
+
raise ArgumentError.new('Please specify parameters') if params.nil?
|
16
|
+
parameters = Parameters.new params
|
17
|
+
options = request_options parameters
|
18
|
+
url = rest_url api, method
|
19
|
+
|
20
|
+
RestClient.post(url, params, options) do |raw_response|
|
21
|
+
case raw_response.code
|
22
|
+
when 200
|
23
|
+
response = parse_response raw_response
|
24
|
+
if block_given?
|
25
|
+
yield response
|
26
|
+
else
|
27
|
+
return response
|
28
|
+
end
|
29
|
+
when 404
|
30
|
+
raise NotFound.new(response)
|
31
|
+
else
|
32
|
+
raise RequestError.new(response)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def parse_response(raw_response)
|
40
|
+
JSON.parse(raw_response)
|
41
|
+
end
|
42
|
+
|
43
|
+
def rest_url(api, method)
|
44
|
+
if api == '' || method == ''
|
45
|
+
raise ArgumentError.new('You need to specify a module / method')
|
46
|
+
end
|
47
|
+
"#{@url}/#{api}/#{method}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def code(parameters)
|
51
|
+
codice = Digest::SHA1.hexdigest "#{parameters.to_s},#{@secret}"
|
52
|
+
code = Base64.strict_encode64 "#{@key}:#{codice}"
|
53
|
+
"Docebo #{code}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_options(parameters)
|
57
|
+
{
|
58
|
+
content_type: :json,
|
59
|
+
accept: :json,
|
60
|
+
'X-Authorization' => code(parameters)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copied from Kaminari::Config
|
2
|
+
require 'active_support/configurable'
|
3
|
+
|
4
|
+
module DoceboRuby
|
5
|
+
# Configures global settings for Docebo
|
6
|
+
# DoceboRuby.configure do |config|
|
7
|
+
# config.url = 'example.com'
|
8
|
+
# end
|
9
|
+
def self.configure(&block)
|
10
|
+
yield @config ||= DoceboRuby::Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
# Global settings for DoceboRuby
|
14
|
+
def self.config
|
15
|
+
@config
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
include ActiveSupport::Configurable
|
20
|
+
config_accessor :saas_url
|
21
|
+
config_accessor :api_url
|
22
|
+
config_accessor :api_key
|
23
|
+
config_accessor :api_secret
|
24
|
+
config_accessor :sso_token
|
25
|
+
|
26
|
+
def param_name
|
27
|
+
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
28
|
+
end
|
29
|
+
|
30
|
+
# define param_name writer
|
31
|
+
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
32
|
+
singleton_class.class_eval writer, __FILE__, line
|
33
|
+
class_eval writer, __FILE__, line
|
34
|
+
end
|
35
|
+
|
36
|
+
configure do |config|
|
37
|
+
config.saas_url = 'example.com'
|
38
|
+
config.api_url = 'example.com'
|
39
|
+
config.api_key = 'TEST_KEY'
|
40
|
+
config.api_secret = 'TEST_SECRET'
|
41
|
+
config.sso_token = 'TEST_SSO'
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DoceboRuby
|
2
|
+
class Course < Resource
|
3
|
+
self.api = 'course'
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def all
|
7
|
+
courses = fetch_data('listCourses') do |data|
|
8
|
+
data.delete_if { |key, value| key == 'success' }
|
9
|
+
end
|
10
|
+
courses.map { |key, value| Course.new value['course_info'] }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DoceboRuby
|
2
|
+
class Resource < OpenStruct
|
3
|
+
def self.api=(api)
|
4
|
+
@api = api
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.api
|
8
|
+
@api
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.fetch_data(method, params = {}, &block)
|
12
|
+
@fetcher = API.new
|
13
|
+
@fetcher.send_request(@api, method, params) do |result|
|
14
|
+
return result unless block_given?
|
15
|
+
yield result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module DoceboRuby
|
2
|
+
class User < Resource
|
3
|
+
self.api = 'user'
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def create(attributes = {})
|
7
|
+
fetch_data('create', attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_username(username)
|
11
|
+
fetch_data('checkUsername', {userid: username})['success']
|
12
|
+
end
|
13
|
+
|
14
|
+
def authenticate(username, password)
|
15
|
+
fetch_data('authenticate', {password: password, username: username}) do |response|
|
16
|
+
response['id_user'] || false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def sso_url(username)
|
21
|
+
timestamp = Time.now.to_i
|
22
|
+
token = Digest::MD5.hexdigest([username, timestamp, DoceboRuby.config.sso_token].join(','))
|
23
|
+
"http://#{DoceboRuby.config.saas_url}/doceboLms/index.php?auth_regen=1&modname=login&op=confirm&login_user=#{username}&time=#{timestamp}&token=#{token}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docebo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack A. Huang
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.7.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.7.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -38,14 +38,52 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
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: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
41
69
|
description: Docebo is an online LMS.
|
42
70
|
email: huynhquancam@gmail.com
|
43
71
|
executables: []
|
44
72
|
extensions: []
|
45
73
|
extra_rdoc_files: []
|
46
74
|
files:
|
75
|
+
- README.md
|
47
76
|
- lib/docebo_ruby.rb
|
48
|
-
|
77
|
+
- lib/docebo_ruby/api.rb
|
78
|
+
- lib/docebo_ruby/configuration.rb
|
79
|
+
- lib/docebo_ruby/course.rb
|
80
|
+
- lib/docebo_ruby/engine.rb
|
81
|
+
- lib/docebo_ruby/orgchart.rb
|
82
|
+
- lib/docebo_ruby/parameters.rb
|
83
|
+
- lib/docebo_ruby/resource.rb
|
84
|
+
- lib/docebo_ruby/user.rb
|
85
|
+
- lib/docebo_ruby/version.rb
|
86
|
+
homepage: https://github.com/huynhquancam/docebo_ruby
|
49
87
|
licenses:
|
50
88
|
- MIT
|
51
89
|
metadata: {}
|
@@ -65,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
103
|
version: '0'
|
66
104
|
requirements: []
|
67
105
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.4.
|
106
|
+
rubygems_version: 2.4.6
|
69
107
|
signing_key:
|
70
108
|
specification_version: 4
|
71
109
|
summary: Ruby wrapper for Docebo LMS.
|