absorb_api 0.2.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +866 -0
  3. data/.ruby-version +1 -0
  4. data/CODE_OF_CONDUCT.md +46 -0
  5. data/Gemfile +3 -10
  6. data/README.md +0 -2
  7. data/Rakefile +3 -1
  8. data/absorb_api.gemspec +30 -16
  9. data/bin/console +11 -5
  10. data/doc/AbsorbApi.html +33 -64
  11. data/doc/AbsorbApi/Api.html +358 -0
  12. data/doc/AbsorbApi/Authorize.html +263 -0
  13. data/doc/AbsorbApi/Category.html +3 -2
  14. data/doc/AbsorbApi/Certificate.html +3 -2
  15. data/doc/AbsorbApi/Chapter.html +3 -2
  16. data/doc/AbsorbApi/Collection.html +3 -2
  17. data/doc/AbsorbApi/Configuration.html +3 -28
  18. data/doc/AbsorbApi/Course.html +3 -71
  19. data/doc/AbsorbApi/CourseEnrollment.html +6 -58
  20. data/doc/AbsorbApi/Create.html +164 -0
  21. data/doc/AbsorbApi/Curriculum.html +3 -2
  22. data/doc/AbsorbApi/Department.html +4 -14
  23. data/doc/AbsorbApi/Lesson.html +3 -2
  24. data/doc/AbsorbApi/LessonEnrollment.html +3 -2
  25. data/doc/AbsorbApi/Prerequisite.html +3 -2
  26. data/doc/AbsorbApi/Record.html +360 -0
  27. data/doc/AbsorbApi/Relations.html +2 -196
  28. data/doc/AbsorbApi/Relations/ClassMethods.html +197 -0
  29. data/doc/AbsorbApi/Resource.html +3 -2
  30. data/doc/AbsorbApi/ResourceNotFound.html +2 -1
  31. data/doc/AbsorbApi/Role.html +3 -2
  32. data/doc/AbsorbApi/RouteNotFound.html +2 -1
  33. data/doc/AbsorbApi/SessionSchedule.html +3 -2
  34. data/doc/AbsorbApi/Tag.html +4 -14
  35. data/doc/AbsorbApi/User.html +85 -35
  36. data/doc/AbsorbApi/ValidationError.html +2 -1
  37. data/doc/AbsorbApi/Where.html +162 -0
  38. data/doc/CODE_OF_CONDUCT_md.html +196 -0
  39. data/doc/Gemfile.html +8 -8
  40. data/doc/Gemfile_lock.html +57 -29
  41. data/doc/Icon/r.html +96 -0
  42. data/doc/LICENSE_txt.html +6 -1
  43. data/doc/Object.html +159 -0
  44. data/doc/README_md.html +6 -3
  45. data/doc/Rakefile.html +7 -2
  46. data/doc/absorb_api_gemspec.html +24 -7
  47. data/doc/bin/setup.html +6 -1
  48. data/doc/created.rid +34 -30
  49. data/doc/css/fonts.css +6 -6
  50. data/doc/index.html +19 -4
  51. data/doc/js/darkfish.js +7 -7
  52. data/doc/js/search_index.js +1 -1
  53. data/doc/js/search_index.js.gz +0 -0
  54. data/doc/js/searcher.js +1 -0
  55. data/doc/js/searcher.js.gz +0 -0
  56. data/doc/table_of_contents.html +118 -31
  57. data/lib/absorb_api.rb +43 -29
  58. data/lib/absorb_api/api.rb +69 -5
  59. data/lib/absorb_api/authorize.rb +37 -7
  60. data/lib/absorb_api/category.rb +3 -1
  61. data/lib/absorb_api/certificate.rb +5 -2
  62. data/lib/absorb_api/chapter.rb +3 -1
  63. data/lib/absorb_api/collection.rb +2 -19
  64. data/lib/absorb_api/configuration.rb +14 -12
  65. data/lib/absorb_api/course.rb +11 -25
  66. data/lib/absorb_api/course_enrollment.rb +13 -26
  67. data/lib/absorb_api/create.rb +19 -0
  68. data/lib/absorb_api/curriculum.rb +11 -2
  69. data/lib/absorb_api/department.rb +10 -4
  70. data/lib/absorb_api/lesson.rb +5 -2
  71. data/lib/absorb_api/lesson_enrollment.rb +8 -2
  72. data/lib/absorb_api/prerequisite.rb +5 -2
  73. data/lib/absorb_api/record.rb +58 -0
  74. data/lib/absorb_api/relations.rb +42 -40
  75. data/lib/absorb_api/resource.rb +3 -1
  76. data/lib/absorb_api/role.rb +3 -1
  77. data/lib/absorb_api/session_schedule.rb +6 -2
  78. data/lib/absorb_api/tag.rb +6 -3
  79. data/lib/absorb_api/user.rb +13 -29
  80. data/lib/absorb_api/version.rb +3 -1
  81. data/lib/absorb_api/where.rb +17 -0
  82. metadata +133 -8
  83. data/lib/absorb_api/base.rb +0 -12
  84. data/lib/absorb_api/orm.rb +0 -36
@@ -1,60 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
4
  module Relations
3
5
  extend ActiveSupport::Concern
4
6
 
5
- class_methods do
6
- def has_many(rel_name, klass = nil)
7
+ module ClassMethods
8
+ def with_many(rel_name, klass = nil)
7
9
  klass ||= rel_name
10
+ klass = klass.to_s
8
11
 
9
- define_method "#{rel_name.to_s}" do |**conditions|
10
- AbsorbApi::Api.new.connection.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}", conditions).body.map! do |attributes|
11
- "AbsorbApi::#{klass.to_s.classify}".constantize.new(attributes)
12
- end
13
- end
12
+ define_has_many_method(rel_name, klass)
13
+ define_has_many_finder_method(rel_name, klass)
14
+ define_has_many_ids_method(rel_name)
15
+ end
14
16
 
15
- define_method "find_#{rel_name.to_s.singularize}" do |child_id|
16
- response = AbsorbApi::Api.new.connection.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}/#{child_id}")
17
- if response.status == 400
18
- raise ResourceNotFound
19
- else
20
- "AbsorbApi::#{klass.to_s.classify}".constantize.new(response.body)
21
- end
22
- end
17
+ def with_one(rel_name, klass = nil)
18
+ klass ||= rel_name
19
+ klass = klass.to_s
23
20
 
24
- define_method "#{rel_name.to_s.singularize}_ids" do
25
- AbsorbApi::Api.new.connection.get("#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name.to_s}").body.map! do |attributes|
26
- "AbsorbApi::#{klass.to_s.classify}".constantize.new(attributes)
27
- end.map(&:id)
21
+ define_method rel_name.to_s do
22
+ path = "#{klass.pluralize}/" + send(rel_name.to_s + "_id")
23
+
24
+ response = get(path, ignore_resource_not_found: true)
25
+ return if response.blank?
26
+
27
+ "AbsorbApi::#{klass.classify}".constantize.new(response)
28
28
  end
29
29
  end
30
30
 
31
- def has_one(rel_name, klass = nil)
32
- klass ||= rel_name
31
+ private
33
32
 
34
- define_method "#{rel_name.to_s}" do
35
- "AbsorbApi::#{klass.to_s.classify}".constantize.new(AbsorbApi::Api.new.connection.get("#{klass.to_s.pluralize}/"+ send(rel_name.to_s + "_id")).body)
33
+ def define_has_many_method(rel_name, klass)
34
+ define_method rel_name.to_s do |**conditions|
35
+ get(
36
+ "#{self.class.to_s.demodulize.pluralize}/#{id}/#{rel_name}",
37
+ conditions.merge(ignore_resource_not_found: true)
38
+ ).map do |attrs|
39
+ "AbsorbApi::#{klass.classify}".constantize.new(attrs)
40
+ end.compact
36
41
  end
37
42
  end
38
43
 
39
- def where(**conditions)
40
- Collection.new( AbsorbApi::Api.new.connection.get("#{to_s.demodulize.pluralize}", conditions).body.map! do |attributes|
41
- new(attributes)
42
- end, {klass: to_s.demodulize } )
44
+ def define_has_many_finder_method(rel_name, klass)
45
+ define_method "find_#{rel_name.to_s.singularize}" do |child_id|
46
+ response = get(
47
+ "#{self.class.to_s.demodulize.pluralize}/#{id}/"\
48
+ "#{rel_name}/#{child_id}"
49
+ )
50
+
51
+ return if response.blank?
52
+
53
+ "AbsorbApi::#{klass.classify}".constantize.new(response)
54
+ end
43
55
  end
44
56
 
45
- def create(attributes = [], &block)
46
- object = to_s.classify.constantize.new(attributes)
47
- yield object if block_given?
48
- attrs = JSON.parse(object.to_json)
49
- attrs.keys.each { |k| attrs[ k.camelize ] = attrs.delete(k) }
50
- response = AbsorbApi::Api.new.connection.post("#{to_s.demodulize.pluralize}", attrs)
51
- if response.status == 500
52
- raise ValidationError
53
- elsif response.status == 405
54
- raise RouteNotFound
55
- else
56
- object.id = response.body["Id"]
57
- object
57
+ def define_has_many_ids_method(rel_name)
58
+ define_method "#{rel_name.to_s.singularize}_ids" do
59
+ send(rel_name.to_s).map(&:id)
58
60
  end
59
61
  end
60
62
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
- class Resource < Base
4
+ class Resource < Record
3
5
  attr_accessor :id, :name, :file, :module_id
4
6
  end
5
7
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
- class Role < Base
4
+ class Role < Record
3
5
  attr_accessor :id, :name, :description
4
6
  end
5
7
  end
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
- class SessionSchedule < Base
3
- attr_accessor :id, :session_id, :venue_id, :venue_type, :venue_name, :date_start, :date_end, :time_zone_id, :meeting_id, :meeting_username, :meeting_password
4
+ class SessionSchedule < Record
5
+ attr_accessor :id, :session_id, :venue_id, :venue_type, :venue_name,
6
+ :date_start, :date_end, :time_zone_id, :meeting_id,
7
+ :meeting_username, :meeting_password
4
8
  end
5
9
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
- class Tag < Base
3
- include Relations
4
-
4
+ class Tag < Record
5
+ with_relationships
6
+ can_create
7
+
5
8
  attr_accessor :id, :name
6
9
  end
7
10
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
- class User < Base
3
- include Relations
4
+ class User < Record
5
+ with_relationships
6
+ can_create
7
+ can_search
4
8
 
5
9
  attr_accessor :id, :department_id, :first_name, :middle_name, :last_name,
6
10
  :username, :password, :email_address, :cc_email_addresses,
@@ -12,38 +16,18 @@ module AbsorbApi
12
16
  :is_instructor, :external_id, :supervisor_id, :decimal2,
13
17
  :string1, :decimal1, :string2, :decimal3, :job_title
14
18
 
15
- has_many :courses
16
- has_many :enrollments, klass: :course_enrollment
17
- has_many :certificates
18
- has_many :resources
19
+ with_many :courses
20
+ with_many :enrollments, :course_enrollment
21
+ with_many :certificates
22
+ with_many :resources
19
23
 
20
24
  def update(attrs)
21
- attrs.keys.each { |k| attrs[k.to_s.camelize] = attrs.delete(k) }
22
- attrs['Username'] = username
25
+ attrs = attrs.with_indifferent_access.transform_keys(&:camelize)
26
+ attrs["Username"] = username
23
27
 
24
- response = AbsorbApi::Api.new.connection.put("users/#{id}", attrs)
25
- raise ValidationError if response.status == 500
26
- raise RouteNotFound if response.status == 405
28
+ put("users/#{id}", attrs)
27
29
 
28
30
  self
29
31
  end
30
-
31
- # gets all associated courses given a collection of users
32
- # all calls are called in parallel
33
- # users are chunked in groups of 105 to keep typhoeus from bogging down
34
- def self.courses_from_collection(users)
35
- courses = []
36
- connection = AbsorbApi::Api.new.connection
37
- users.each_slice(105) do |user_slice|
38
- connection.in_parallel do
39
- user_slice.each do |user|
40
- courses << connection.get("users/#{user.id}/courses")
41
- end
42
- end
43
- end
44
- courses.map do |response|
45
- response.body.map { |body| Course.new(body) }
46
- end.flatten
47
- end
48
32
  end
49
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbsorbApi
2
- VERSION = "0.2.0"
4
+ VERSION = "0.9.1"
3
5
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbsorbApi
4
+ module Where
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def where(**conditions)
9
+ objs = api.get(to_s.demodulize.pluralize, conditions).map do |attrs|
10
+ new(attrs)
11
+ end
12
+
13
+ Collection.new(objs, klass: to_s.demodulize)
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,15 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absorb_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - npezza
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2017-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
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: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: typhoeus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
13
111
  - !ruby/object:Gem::Dependency
14
112
  name: bundler
15
113
  requirement: !ruby/object:Gem::Requirement
@@ -38,8 +136,22 @@ dependencies:
38
136
  - - "~>"
39
137
  - !ruby/object:Gem::Version
40
138
  version: '10.0'
41
- description: This gem provides a ruby wrapper for Absorb's Learning Management System
42
- API. \n\n
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: This gem provides a ruby wrapper for Absorb's LearningManagement System
154
+ API.
43
155
  email:
44
156
  - npezza93@gmail.com
45
157
  executables: []
@@ -47,6 +159,9 @@ extensions: []
47
159
  extra_rdoc_files: []
48
160
  files:
49
161
  - ".gitignore"
162
+ - ".rubocop.yml"
163
+ - ".ruby-version"
164
+ - CODE_OF_CONDUCT.md
50
165
  - Gemfile
51
166
  - LICENSE.txt
52
167
  - README.md
@@ -55,6 +170,8 @@ files:
55
170
  - bin/console
56
171
  - bin/setup
57
172
  - doc/AbsorbApi.html
173
+ - doc/AbsorbApi/Api.html
174
+ - doc/AbsorbApi/Authorize.html
58
175
  - doc/AbsorbApi/Base.html
59
176
  - doc/AbsorbApi/Category.html
60
177
  - doc/AbsorbApi/Certificate.html
@@ -63,13 +180,16 @@ files:
63
180
  - doc/AbsorbApi/Configuration.html
64
181
  - doc/AbsorbApi/Course.html
65
182
  - doc/AbsorbApi/CourseEnrollment.html
183
+ - doc/AbsorbApi/Create.html
66
184
  - doc/AbsorbApi/Curriculum.html
67
185
  - doc/AbsorbApi/Department.html
68
186
  - doc/AbsorbApi/Lesson.html
69
187
  - doc/AbsorbApi/LessonEnrollment.html
70
188
  - doc/AbsorbApi/Orm.html
71
189
  - doc/AbsorbApi/Prerequisite.html
190
+ - doc/AbsorbApi/Record.html
72
191
  - doc/AbsorbApi/Relations.html
192
+ - doc/AbsorbApi/Relations/ClassMethods.html
73
193
  - doc/AbsorbApi/Resource.html
74
194
  - doc/AbsorbApi/ResourceNotFound.html
75
195
  - doc/AbsorbApi/Role.html
@@ -78,9 +198,13 @@ files:
78
198
  - doc/AbsorbApi/Tag.html
79
199
  - doc/AbsorbApi/User.html
80
200
  - doc/AbsorbApi/ValidationError.html
201
+ - doc/AbsorbApi/Where.html
202
+ - doc/CODE_OF_CONDUCT_md.html
81
203
  - doc/Gemfile.html
82
204
  - doc/Gemfile_lock.html
205
+ - "doc/Icon\r.html"
83
206
  - doc/LICENSE_txt.html
207
+ - doc/Object.html
84
208
  - doc/README_md.html
85
209
  - doc/Rakefile.html
86
210
  - doc/absorb_api_gemspec.html
@@ -133,7 +257,6 @@ files:
133
257
  - lib/absorb_api.rb
134
258
  - lib/absorb_api/api.rb
135
259
  - lib/absorb_api/authorize.rb
136
- - lib/absorb_api/base.rb
137
260
  - lib/absorb_api/category.rb
138
261
  - lib/absorb_api/certificate.rb
139
262
  - lib/absorb_api/chapter.rb
@@ -141,12 +264,13 @@ files:
141
264
  - lib/absorb_api/configuration.rb
142
265
  - lib/absorb_api/course.rb
143
266
  - lib/absorb_api/course_enrollment.rb
267
+ - lib/absorb_api/create.rb
144
268
  - lib/absorb_api/curriculum.rb
145
269
  - lib/absorb_api/department.rb
146
270
  - lib/absorb_api/lesson.rb
147
271
  - lib/absorb_api/lesson_enrollment.rb
148
- - lib/absorb_api/orm.rb
149
272
  - lib/absorb_api/prerequisite.rb
273
+ - lib/absorb_api/record.rb
150
274
  - lib/absorb_api/relations.rb
151
275
  - lib/absorb_api/resource.rb
152
276
  - lib/absorb_api/role.rb
@@ -154,6 +278,7 @@ files:
154
278
  - lib/absorb_api/tag.rb
155
279
  - lib/absorb_api/user.rb
156
280
  - lib/absorb_api/version.rb
281
+ - lib/absorb_api/where.rb
157
282
  homepage: https://github.com/npezza93/absorb_api
158
283
  licenses:
159
284
  - MIT
@@ -174,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
299
  version: '0'
175
300
  requirements: []
176
301
  rubyforge_project:
177
- rubygems_version: 2.5.1
302
+ rubygems_version: 2.6.12
178
303
  signing_key:
179
304
  specification_version: 4
180
305
  summary: API wrapper for Absorb LMS