absorb_api 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/absorb_api.gemspec +11 -11
- data/lib/absorb_api.rb +23 -41
- data/lib/absorb_api/api.rb +16 -0
- data/lib/absorb_api/authorize.rb +17 -0
- data/lib/absorb_api/course.rb +15 -4
- data/lib/absorb_api/course_enrollment.rb +12 -4
- data/lib/absorb_api/orm.rb +4 -4
- data/lib/absorb_api/relations.rb +6 -6
- data/lib/absorb_api/user.rb +7 -4
- data/lib/absorb_api/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dfa1e14ebad755094867288a7c5002bc2eb4dbf
|
4
|
+
data.tar.gz: 6593c2baa36abb4193ce804015af31915e6a4527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9515b916444885ee7957287d45c24577da6a44a44dce19b43627f7a5b2f40003aacd2ce3c8716e7f626574bb1ee5180d72a28e5f139fc5fd54d73cf42e23e93d
|
7
|
+
data.tar.gz: 388b02e9defb0503e8fee389e15e093548ebced97331d8258d482619a1c0c280df05e600392c57c4228b367849cd1d40cc35c897831f7aff2d6c6c392eee1cbf
|
data/absorb_api.gemspec
CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'absorb_api/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'absorb_api'
|
8
8
|
spec.version = AbsorbApi::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['npezza']
|
10
|
+
spec.email = ['npezza93@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'API wrapper for Absorb LMS'
|
13
|
+
spec.description = 'This gem provides a ruby wrapper for Absorb\'s Learning Management System API. \n\n'
|
14
|
+
spec.homepage = 'https://github.com/npezza93/absorb_api'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
end
|
data/lib/absorb_api.rb
CHANGED
@@ -5,48 +5,30 @@ require 'faraday_middleware'
|
|
5
5
|
require 'active_support/all'
|
6
6
|
require 'active_model'
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
8
|
+
require 'absorb_api/orm'
|
9
|
+
require 'absorb_api/relations'
|
10
|
+
require 'absorb_api/collection'
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
12
|
+
require 'absorb_api/version'
|
13
|
+
require 'absorb_api/configuration'
|
14
|
+
require 'absorb_api/base'
|
15
|
+
require 'absorb_api/user'
|
16
|
+
require 'absorb_api/course'
|
17
|
+
require 'absorb_api/course_enrollment'
|
18
|
+
require 'absorb_api/lesson_enrollment'
|
19
|
+
require 'absorb_api/category'
|
20
|
+
require 'absorb_api/certificate'
|
21
|
+
require 'absorb_api/chapter'
|
22
|
+
require 'absorb_api/curriculum'
|
23
|
+
require 'absorb_api/department'
|
24
|
+
require 'absorb_api/tag'
|
25
|
+
require 'absorb_api/session_schedule'
|
26
|
+
require 'absorb_api/role'
|
27
|
+
require 'absorb_api/resource'
|
28
|
+
require 'absorb_api/prerequisite'
|
29
|
+
require 'absorb_api/lesson'
|
30
|
+
require 'absorb_api/authorize'
|
31
|
+
require 'absorb_api/api'
|
30
32
|
|
31
33
|
module AbsorbApi
|
32
|
-
def self.authorize
|
33
|
-
@authorize ||= Faraday.new(:url => AbsorbApi.configuration.url) do |faraday|
|
34
|
-
faraday.request :url_encoded
|
35
|
-
faraday.response :logger
|
36
|
-
faraday.adapter :typhoeus
|
37
|
-
end.post do |req|
|
38
|
-
req.url 'Authenticate', { username: AbsorbApi.configuration.absorbuser, password: AbsorbApi.configuration.absorbpass, privateKey: AbsorbApi.configuration.absorbkey }
|
39
|
-
req.headers['Content-Type'] = 'application/json'
|
40
|
-
req.headers["accept"] = "json"
|
41
|
-
end.body.delete('\\"')
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.api
|
45
|
-
@api ||= Faraday.new(:url => AbsorbApi.configuration.url, :parallel_manager => Typhoeus::Hydra.new(:max_concurrency => 200)) do |faraday|
|
46
|
-
faraday.request :json
|
47
|
-
faraday.response :json, :content_type => /\bjson$/
|
48
|
-
faraday.adapter :typhoeus
|
49
|
-
faraday.headers = {"Authorization" => authorize }
|
50
|
-
end
|
51
|
-
end
|
52
34
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AbsorbApi
|
2
|
+
class Api
|
3
|
+
attr_reader :connection, :token
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@token = AbsorbApi::Authorize.new.token
|
7
|
+
|
8
|
+
@connection ||= Faraday.new(url: AbsorbApi.configuration.url, parallel_manager: Typhoeus::Hydra.new(max_concurrency: 200)) do |faraday|
|
9
|
+
faraday.request :json
|
10
|
+
faraday.response :json, content_type: /\bjson$/
|
11
|
+
faraday.adapter :typhoeus
|
12
|
+
faraday.headers = { 'Authorization' => @token }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AbsorbApi
|
2
|
+
class Authorize
|
3
|
+
attr_reader :token
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@token ||= Faraday.new(url: AbsorbApi.configuration.url) do |faraday|
|
7
|
+
faraday.request :url_encoded
|
8
|
+
faraday.response :logger
|
9
|
+
faraday.adapter :typhoeus
|
10
|
+
end.post do |req|
|
11
|
+
req.url 'Authenticate', username: AbsorbApi.configuration.absorbuser, password: AbsorbApi.configuration.absorbpass, privateKey: AbsorbApi.configuration.absorbkey
|
12
|
+
req.headers['Content-Type'] = 'application/json'
|
13
|
+
req.headers['accept'] = 'json'
|
14
|
+
end.body.delete('\\"')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/absorb_api/course.rb
CHANGED
@@ -2,7 +2,13 @@ module AbsorbApi
|
|
2
2
|
class Course < Base
|
3
3
|
include Relations
|
4
4
|
|
5
|
-
attr_accessor :id, :name, :description, :notes, :external_id, :access_date,
|
5
|
+
attr_accessor :id, :name, :description, :notes, :external_id, :access_date,
|
6
|
+
:expire_type, :expire_duration, :expiry_date, :active_status,
|
7
|
+
:tag_ids, :resource_ids, :editor_ids, :prices,
|
8
|
+
:competency_definition_ids, :prerequisite_course_ids,
|
9
|
+
:post_enrollment_course_ids, :allow_course_evaluation,
|
10
|
+
:category_id, :certificate_url, :audience, :goals, :vendor,
|
11
|
+
:company_cost, :learner_cost, :company_time, :learner_time
|
6
12
|
|
7
13
|
has_many :certificates
|
8
14
|
has_many :chapters
|
@@ -15,9 +21,14 @@ module AbsorbApi
|
|
15
21
|
# all calls are called in parallel
|
16
22
|
def self.enrollments_from_collection(courses, **conditions)
|
17
23
|
enrollments = []
|
18
|
-
AbsorbApi.
|
19
|
-
|
20
|
-
|
24
|
+
connection = AbsorbApi::Api.new.connection
|
25
|
+
courses.reject! do |course|
|
26
|
+
AbsorbApi.configuration.ignored_course_ids.include? course.id
|
27
|
+
end
|
28
|
+
|
29
|
+
connection.in_parallel do
|
30
|
+
courses.each do |course|
|
31
|
+
enrollments << connection.get("courses/#{course.id}/enrollments", conditions)
|
21
32
|
end
|
22
33
|
end
|
23
34
|
enrollments.map { |response| response.body.map { |attrs| CourseEnrollment.new(attrs) } }.flatten
|
@@ -3,7 +3,7 @@ module AbsorbApi
|
|
3
3
|
attr_accessor :id, :course_id, :course_name, :course_version_id, :user_id, :full_name, :status, :progress, :score, :accepted_terms_and_conditions, :time_spent, :date_started, :date_completed, :enrollment_key_id, :certificate_id, :credits
|
4
4
|
|
5
5
|
def lessons(**conditions)
|
6
|
-
AbsorbApi.
|
6
|
+
AbsorbApi::Api.new.connection.get("users/#{self.user_id}/enrollments/#{self.course_id}/lessons", conditions).body.map! do |lesson_attributes|
|
7
7
|
LessonEnrollment.new(lesson_attributes)
|
8
8
|
end
|
9
9
|
end
|
@@ -14,14 +14,22 @@ module AbsorbApi
|
|
14
14
|
# modifiedSince must be a DateTime object
|
15
15
|
def self.lessons_from_collection(course_enrollments, **filters)
|
16
16
|
lessons = []
|
17
|
+
connection = AbsorbApi::Api.new.connection
|
17
18
|
course_enrollments.each_slice(105) do |enrollment_slice|
|
18
|
-
|
19
|
+
connection.in_parallel do
|
19
20
|
enrollment_slice.each do |enrollment|
|
20
|
-
lessons <<
|
21
|
+
lessons << connection.get("users/#{enrollment.user_id}/enrollments/#{enrollment.course_id}/lessons", filters)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
24
|
-
lessons.map
|
25
|
+
lessons.map! do |response|
|
26
|
+
response.body.map do |body|
|
27
|
+
LessonEnrollment.new(body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
lessons.flatten.reject do |lesson|
|
31
|
+
AbsorbApi.configuration.ignored_lesson_types.include? lesson.type
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/absorb_api/orm.rb
CHANGED
@@ -9,7 +9,7 @@ module AbsorbApi
|
|
9
9
|
class_methods do
|
10
10
|
def find(id)
|
11
11
|
raise ResourceNotFound if id.blank?
|
12
|
-
response = AbsorbApi.
|
12
|
+
response = AbsorbApi::Api.new.connection.get("#{to_s.demodulize.pluralize}/#{id}")
|
13
13
|
if response.status == 404
|
14
14
|
raise(RouteNotFound)
|
15
15
|
elsif response.status == 400
|
@@ -20,15 +20,15 @@ module AbsorbApi
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def all
|
23
|
-
response = AbsorbApi.
|
23
|
+
response = AbsorbApi::Api.new.connection.get(to_s.demodulize.pluralize)
|
24
24
|
if response.status == 404
|
25
25
|
raise RouteNotFound
|
26
26
|
elsif response.status == 400
|
27
27
|
raise ResourceNotFound
|
28
28
|
else
|
29
|
-
Collection.new(
|
29
|
+
Collection.new(response.body.map! do |attributes|
|
30
30
|
new(attributes)
|
31
|
-
end,
|
31
|
+
end, klass: to_s.demodulize)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/absorb_api/relations.rb
CHANGED
@@ -7,13 +7,13 @@ module AbsorbApi
|
|
7
7
|
klass ||= rel_name
|
8
8
|
|
9
9
|
define_method "#{rel_name.to_s}" do |**conditions|
|
10
|
-
AbsorbApi.
|
10
|
+
AbsorbApi::Api.new.connection.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}", conditions).body.map! do |attributes|
|
11
11
|
"AbsorbApi::#{klass.to_s.classify}".constantize.new(attributes)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
define_method "find_#{rel_name.to_s.singularize}" do |child_id|
|
16
|
-
response = AbsorbApi.
|
16
|
+
response = AbsorbApi::Api.new.connection.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}/#{child_id}")
|
17
17
|
if response.status == 400
|
18
18
|
raise ResourceNotFound
|
19
19
|
else
|
@@ -22,7 +22,7 @@ module AbsorbApi
|
|
22
22
|
end
|
23
23
|
|
24
24
|
define_method "#{rel_name.to_s.singularize}_ids" do
|
25
|
-
AbsorbApi.
|
25
|
+
AbsorbApi::Api.new.connection.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}").body.map! do |attributes|
|
26
26
|
"AbsorbApi::#{klass.to_s.classify}".constantize.new(attributes)
|
27
27
|
end.map(&:id)
|
28
28
|
end
|
@@ -32,12 +32,12 @@ module AbsorbApi
|
|
32
32
|
klass ||= rel_name
|
33
33
|
|
34
34
|
define_method "#{rel_name.to_s}" do
|
35
|
-
"AbsorbApi::#{klass.to_s.classify}".constantize.new(AbsorbApi.
|
35
|
+
"AbsorbApi::#{klass.to_s.classify}".constantize.new(AbsorbApi::Api.new.connection.get("#{klass.to_s.pluralize}/"+ send(rel_name.to_s + "_id")).body)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
def where(**conditions)
|
40
|
-
Collection.new( AbsorbApi.
|
40
|
+
Collection.new( AbsorbApi::Api.new.connection.get("#{to_s.demodulize.pluralize}", conditions).body.map! do |attributes|
|
41
41
|
new(attributes)
|
42
42
|
end, {klass: to_s.demodulize } )
|
43
43
|
end
|
@@ -47,7 +47,7 @@ module AbsorbApi
|
|
47
47
|
yield object if block_given?
|
48
48
|
attrs = JSON.parse(object.to_json)
|
49
49
|
attrs.keys.each { |k| attrs[ k.camelize ] = attrs.delete(k) }
|
50
|
-
response = AbsorbApi.
|
50
|
+
response = AbsorbApi::Api.new.connection.post("#{to_s.demodulize.pluralize}", attrs)
|
51
51
|
if response.status == 500
|
52
52
|
raise ValidationError
|
53
53
|
elsif response.status == 405
|
data/lib/absorb_api/user.rb
CHANGED
@@ -21,7 +21,7 @@ module AbsorbApi
|
|
21
21
|
attrs.keys.each { |k| attrs[k.to_s.camelize] = attrs.delete(k) }
|
22
22
|
attrs['Username'] = username
|
23
23
|
|
24
|
-
response = AbsorbApi.
|
24
|
+
response = AbsorbApi::Api.new.connection.put("users/#{id}", attrs)
|
25
25
|
raise ValidationError if response.status == 500
|
26
26
|
raise RouteNotFound if response.status == 405
|
27
27
|
|
@@ -33,14 +33,17 @@ module AbsorbApi
|
|
33
33
|
# users are chunked in groups of 105 to keep typhoeus from bogging down
|
34
34
|
def self.courses_from_collection(users)
|
35
35
|
courses = []
|
36
|
+
connection = AbsorbApi::Api.new.connection
|
36
37
|
users.each_slice(105) do |user_slice|
|
37
|
-
|
38
|
+
connection.in_parallel do
|
38
39
|
user_slice.each do |user|
|
39
|
-
courses <<
|
40
|
+
courses << connection.get("users/#{user.id}/courses")
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
43
|
-
courses.map
|
44
|
+
courses.map do |response|
|
45
|
+
response.body.map { |body| Course.new(body) }
|
46
|
+
end.flatten
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
data/lib/absorb_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: absorb_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- npezza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,8 +38,8 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
42
|
-
API. \n\n
|
41
|
+
description: This gem provides a ruby wrapper for Absorb's Learning Management System
|
42
|
+
API. \n\n
|
43
43
|
email:
|
44
44
|
- npezza93@gmail.com
|
45
45
|
executables: []
|
@@ -131,6 +131,8 @@ files:
|
|
131
131
|
- doc/js/searcher.js.gz
|
132
132
|
- doc/table_of_contents.html
|
133
133
|
- lib/absorb_api.rb
|
134
|
+
- lib/absorb_api/api.rb
|
135
|
+
- lib/absorb_api/authorize.rb
|
134
136
|
- lib/absorb_api/base.rb
|
135
137
|
- lib/absorb_api/category.rb
|
136
138
|
- lib/absorb_api/certificate.rb
|
@@ -172,9 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
174
|
version: '0'
|
173
175
|
requirements: []
|
174
176
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.5.1
|
176
178
|
signing_key:
|
177
179
|
specification_version: 4
|
178
180
|
summary: API wrapper for Absorb LMS
|
179
181
|
test_files: []
|
180
|
-
has_rdoc:
|