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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3eb2f3a9b826a7ecace98a90ee361669a68c6a5
4
- data.tar.gz: 40de4863fd8c9b706c802d778fbf6763b25b5748
3
+ metadata.gz: 2dfa1e14ebad755094867288a7c5002bc2eb4dbf
4
+ data.tar.gz: 6593c2baa36abb4193ce804015af31915e6a4527
5
5
  SHA512:
6
- metadata.gz: 0200d4112113652248aa63b2b633bfac3860627afc44561c9715ac6c86ac355faa2cd4318f19071bae8b178ee78dc0c9f3a46943b9ac5619566951527962ac8d
7
- data.tar.gz: 682411c891a5a79d2816a10c847fd0d300ca4dfb10a26af86b585d4abdc0921b8c70fda313bbbd747a4f8eb666b460481229ed0fe056345b2d44644624822816
6
+ metadata.gz: 9515b916444885ee7957287d45c24577da6a44a44dce19b43627f7a5b2f40003aacd2ce3c8716e7f626574bb1ee5180d72a28e5f139fc5fd54d73cf42e23e93d
7
+ data.tar.gz: 388b02e9defb0503e8fee389e15e093548ebced97331d8258d482619a1c0c280df05e600392c57c4228b367849cd1d40cc35c897831f7aff2d6c6c392eee1cbf
@@ -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 = "absorb_api"
7
+ spec.name = 'absorb_api'
8
8
  spec.version = AbsorbApi::VERSION
9
- spec.authors = ["npezza"]
10
- spec.email = ["npezza93@gmail.com"]
9
+ spec.authors = ['npezza']
10
+ spec.email = ['npezza93@gmail.com']
11
11
 
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"
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 = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency 'bundler', '~> 1.11'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
24
  end
@@ -5,48 +5,30 @@ require 'faraday_middleware'
5
5
  require 'active_support/all'
6
6
  require 'active_model'
7
7
 
8
- require "absorb_api/orm"
9
- require "absorb_api/relations"
10
- require "absorb_api/collection"
8
+ require 'absorb_api/orm'
9
+ require 'absorb_api/relations'
10
+ require 'absorb_api/collection'
11
11
 
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"
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
@@ -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, :expire_type, :expire_duration, :expiry_date, :active_status, :tag_ids, :resource_ids, :editor_ids, :prices, :competency_definition_ids, :prerequisite_course_ids, :post_enrollment_course_ids, :allow_course_evaluation, :category_id, :certificate_url, :audience, :goals, :vendor, :company_cost, :learner_cost, :company_time, :learner_time
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.api.in_parallel do
19
- courses.reject { |course| AbsorbApi.configuration.ignored_course_ids.include? course.id }.each do |course|
20
- enrollments << AbsorbApi.api.get("courses/#{course.id}/enrollments", conditions)
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.api.get("users/#{self.user_id}/enrollments/#{self.course_id}/lessons", conditions).body.map! do |lesson_attributes|
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
- AbsorbApi.api.in_parallel do
19
+ connection.in_parallel do
19
20
  enrollment_slice.each do |enrollment|
20
- lessons << AbsorbApi.api.get("users/#{enrollment.user_id}/enrollments/#{enrollment.course_id}/lessons", filters)
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 { |response| response.body.map { |body| LessonEnrollment.new(body) } }.flatten.reject { |lesson| AbsorbApi.configuration.ignored_lesson_types.include? lesson.type }
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
@@ -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.api.get("#{to_s.demodulize.pluralize}/#{id}")
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.api.get("#{to_s.demodulize.pluralize}")
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( response.body.map! do |attributes|
29
+ Collection.new(response.body.map! do |attributes|
30
30
  new(attributes)
31
- end, {klass: to_s.demodulize } )
31
+ end, klass: to_s.demodulize)
32
32
  end
33
33
  end
34
34
  end
@@ -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.api.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}", conditions).body.map! do |attributes|
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.api.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}/#{child_id}")
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.api.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}").body.map! do |attributes|
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.api.get("#{klass.to_s.pluralize}/"+ send(rel_name.to_s + "_id")).body)
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.api.get("#{to_s.demodulize.pluralize}", conditions).body.map! do |attributes|
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.api.post("#{to_s.demodulize.pluralize}", attrs)
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
@@ -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.api.put("users/#{id}", attrs)
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
- AbsorbApi.api.in_parallel do
38
+ connection.in_parallel do
38
39
  user_slice.each do |user|
39
- courses << AbsorbApi.api.get("users/#{user.id}/courses")
40
+ courses << connection.get("users/#{user.id}/courses")
40
41
  end
41
42
  end
42
43
  end
43
- courses.map { |response| response.body.map { |body| Course.new(body) } }.flatten
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
@@ -1,3 +1,3 @@
1
1
  module AbsorbApi
2
- VERSION = "0.1.11"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.11
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-05 00:00:00.000000000 Z
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: "This gem provides a ruby wrapper for Absorb's Learning Management System
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.4.8
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: