integration_pal 0.1.0 → 0.1.1

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: 17225c001e18da68a033fa8b20b7aa96c568dbd2
4
- data.tar.gz: 4823be875bf24dc9e2ce83dea646ba408de6955b
3
+ metadata.gz: 280b4edff89cc46a952f3f285598cd653e30302e
4
+ data.tar.gz: b901792e8bd9b9c4b0a15f00ed417b63f37ef22c
5
5
  SHA512:
6
- metadata.gz: 693d29af95a8abdddee204db1d077ea7beca1dfa72b0e6a8ac16934e1cb118072e7df5b07b954603a48b6b18cbfc8165694ce0366589be3b99b79ec807a04c24
7
- data.tar.gz: 6c68c5f63f781834340731bcf12387e5f814ea5050044468f84dde823be3dff3f9f1037ab7c113fe0ae3c9faeca715ffacb4a8ec4677ad2e7fdf459f2b64501f
6
+ metadata.gz: 0af7e88b02c0ff73a2b14bf00b49613a056d600e95d9e0c574e5657685f62b7d30a4f5526c2abd0a5c6b7e563534bfaf4d1a9330b71a251cf95320272542c4ce
7
+ data.tar.gz: 8ba3b65e035a8b837c8280a39fa3fe12037d79a92468e5ec4e5c3af15b1755e4f6c24bd7cc2389b3d1a14ef909388af68240caf0f1dc16ab93c0cd1b73704aa7
@@ -1,4 +1,6 @@
1
- jobs = Dir.glob("#{Rails.root}/app/jobs/*.rb")
2
- job_types = jobs.map{ |job| File.basename(job).to_s.gsub('.rb', '').camelcase }
3
- job_types.delete('ApplicationJob')
4
- JOB_TYPES = job_types
1
+ jobs = Dir.glob("#{Rails.root}/app/jobs/**/*.rb")
2
+ jobs = jobs.map{ |job| job.gsub("#{Rails.root}/app/jobs/", '') }
3
+ jobs = jobs.map{ |job| job.gsub(".rb", '') }
4
+ jobs = jobs.map{ |job| job.split("/").map{ |j| j.camelcase }.join('::') }
5
+ jobs.delete('ApplicationJob')
6
+ JOB_TYPES = jobs
@@ -0,0 +1,24 @@
1
+ require 'httmultiparty'
2
+
3
+ module Canvas
4
+ class Client
5
+ include ::HTTMultiParty
6
+
7
+ attr_accessor :token, :canvas_url
8
+
9
+ def initialize(canvas_url, token)
10
+ self.class.base_uri(canvas_url)
11
+ @canvas_url = canvas_url
12
+ @token = token
13
+ end
14
+
15
+ def post_sis_zip_to_canvas(account_id, *params)
16
+ path = "/api/v1/accounts/#{account_id}/sis_imports"
17
+ params_hash = params.first
18
+ query = {attachment: File.open(params_hash.delete(:attachment))}
19
+ query.merge!(params_hash)
20
+ self.class.post(path, query: query, headers: {'Authorization' => "Bearer #{token}", 'Content-Type' => 'application/zip'})
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class Account < BaseModel
3
+ validates :sis_id, :name, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted)}
5
+ attr_accessor :sis_id, :parent_sis_id, :name, :status
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module Canvas::Models
2
+ class BaseModel
3
+ include ::ActiveModel::Validations
4
+ include ::ActiveModel::Serialization
5
+
6
+ def initialize(attributes = {})
7
+ attributes.each do |name, value|
8
+ send("#{name}=", value)
9
+ end
10
+
11
+ after_initialize
12
+ end
13
+
14
+ def after_initialize
15
+ # this method should be overwritten in subclass
16
+ end
17
+
18
+ def ==(other)
19
+ to_json == other.to_json
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class Course < BaseModel
3
+ validates :sis_id, :short_name, :long_name, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted completed)}
5
+ attr_accessor :sis_id, :account_sis_id, :term_sis_id, :short_name, :long_name, :status, :start_date, :end_date
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module Canvas::Models
2
+ class Enrollment < BaseModel
3
+ validates :user_sis_id, :role, presence: true
4
+ validates :role, inclusion: {in: ['student', 'teacher', 'ta', 'observer', 'designer', 'Pending Orientation']}
5
+ validates :status, inclusion: {in: %w(active deleted completed)}
6
+ validate :course_or_section
7
+ attr_accessor :course_sis_id, :user_sis_id, :role, :section_sis_id, :status, :associated_user_sis_id
8
+
9
+ def course_or_section
10
+ errors.add(:id, 'An enrollment must have either a course_id or a section_id') unless @course_sis_id || @section_sis_id
11
+ end
12
+
13
+ def after_initialize
14
+ self.status ||= 'active'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Canvas::Models
2
+ class File < BaseModel
3
+ attr_accessor :size, :content_type, :url, :id, :display_name, :created_at, :updated_at, :unlock_at, :locked,
4
+ :hidden, :lock_at, :locked_for_user, :hidden_for_user
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Canvas::Models
2
+ class Folder < BaseModel
3
+ attr_accessor :context_type, :context_id, :files_count, :position, :updated_at, :folders_url, :files_url,
4
+ :full_name, :lock_at, :id, :folders_count, :name, :parent_folder_id, :created_at, :unlock_at,
5
+ :hidden, :hidden_for_user, :locked, :locked_for_user
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class Group < BaseModel
3
+ validates :sis_id, :name, presence: true
4
+ validates :status, inclusion: {in: %w(available closed completed deleted)}
5
+ attr_accessor :sis_id, :account_sis_id, :name, :status
6
+
7
+ def after_initialize
8
+ self.status ||= 'available'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class GroupMembership < BaseModel
3
+ validates :user_sis_id, :group_sis_id, presence: true
4
+ validates :status, inclusion: {in: %w(accepted deleted)}
5
+ attr_accessor :group_sis_id, :user_sis_id, :status
6
+
7
+ def after_initialize
8
+ self.status ||= 'accepted'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class Section < BaseModel
3
+ validates :sis_id, :course_sis_id, :name, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted)}
5
+ attr_accessor :sis_id, :course_sis_id, :account_sis_id, :name, :status, :start_date, :end_date
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class Term < BaseModel
3
+ validates :sis_id, :name, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted)}
5
+ attr_accessor :sis_id, :name, :status, :start_date, :end_date
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class User < BaseModel
3
+ validates :sis_id, :login_id, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted)}
5
+ attr_accessor :sis_id, :login_id, :password, :first_name, :last_name, :email, :status, :avatar_url
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class UserObserver < BaseModel
3
+ validates :observer_id, :student_id, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted)}
5
+ attr_accessor :observer_id, :student_id, :status
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Canvas::Models
2
+ class XList < BaseModel
3
+ validates :section_sis_id, :xlist_course_sis_id, presence: true
4
+ validates :status, inclusion: {in: %w(active deleted)}
5
+ attr_accessor :xlist_course_sis_id, :section_sis_id, :status
6
+
7
+ def after_initialize
8
+ self.status ||= 'active'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'csv'
2
+
3
+ module Canvas::Utils
4
+ class Csv
5
+
6
+ def self.hash_csv(csv_string)
7
+ CSV.parse(csv_string, {:headers => true, :return_headers => false, :header_converters => :symbol} )
8
+ end
9
+
10
+ def self.hash_csv_file(file_path)
11
+ CSV.read(file_path, {:headers => true, :return_headers => false, :header_converters => :symbol} )
12
+ end
13
+
14
+ def self.create_csv(models, headers)
15
+ CSV.generate do |csv|
16
+ csv << headers.map do |header|
17
+ header.instance_of?(Hash) ? header.values.first.to_s : header.to_s
18
+ end
19
+ models.each do |model|
20
+ csv << headers.map do |header|
21
+ const = header.instance_of?(Hash) ? header.keys.first : header
22
+ model.respond_to?(const) ? model.send(const) : nil
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.unzip_csv(zip)
29
+ {}.tap do |h|
30
+ Zip::InputStream.open(StringIO.new(zip)) do |archive|
31
+ while entry = archive.get_next_entry
32
+ h[entry.name] = self.hash_csv(archive.read)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,71 @@
1
+ require 'zip'
2
+
3
+ module Canvas::Utils
4
+ class Sis
5
+ class << self
6
+ Headers = {
7
+ user: [{sis_id: 'user_id'}, :login_id, :password, :first_name, :last_name, :email, :status],
8
+ account: [{sis_id: 'account_id'}, {parent_sis_id: 'parent_account_id'}, :name, :status],
9
+ term: [{sis_id: 'term_id'}, :name, :status, :start_date, :end_date],
10
+ course: [{sis_id: 'course_id'}, :short_name, :long_name, {account_sis_id: 'account_id'}, {term_sis_id: 'term_id'}, :status, :start_date, :end_date],
11
+ section: [{sis_id: 'section_id'}, {course_sis_id: 'course_id'}, :name, :status, :start_date, :end_date, {account_sis_id: 'account_id'}],
12
+ enrollment: [{course_sis_id: 'course_id'}, {user_sis_id: 'user_id'}, :role, {section_sis_id: 'section_id'}, :status, {associated_user_sis_id: 'associated_user_id'}],
13
+ group: [{sis_id: 'group_id'}, {account_sis_id: 'account_id'}, :name, :status],
14
+ group_membership: [{group_sis_id: 'group_id'}, {user_sis_id: 'user_id'}, :status],
15
+ xlist: [{xlist_course_sis_id: 'xlist_course_id'}, {section_sis_id: 'section_id'}, :status],
16
+ user_observer: [:observer_id, :student_id, :status]
17
+ }
18
+
19
+ def create_csv(type, models)
20
+ Canvas::Utils::Csv.create_csv(models, Headers[type.to_sym])
21
+ end
22
+
23
+ def write_zip(filename, *models)
24
+ Zip::OutputStream.open(filename) {|zip| generate_zip_data zip, models }
25
+ end
26
+
27
+ def zip_string(*models)
28
+ stringIO = Zip::ZipOutputStream::write_buffer {|zip| generate_zip_data zip, models }
29
+ stringIO.rewind
30
+ stringIO.string.bytes.to_a.pack("C*")
31
+ end
32
+
33
+ def generate_zip_data(zip, models)
34
+ map_data(models).each do |key, value|
35
+ zip.put_next_entry("#{key}s.csv")
36
+ zip.write create_csv(key, value)
37
+ end
38
+ end
39
+
40
+ def map_data(data)
41
+ models = {}
42
+ data.flatten.each do |model|
43
+ case model
44
+ when Canvas::Models::Account
45
+ (models[:account] ||= []) << model
46
+ when Canvas::Models::Course
47
+ (models[:course] ||= []) << model
48
+ when Canvas::Models::Enrollment
49
+ (models[:enrollment] ||= []) << model
50
+ when Canvas::Models::Group
51
+ (models[:group] ||= []) << model
52
+ when Canvas::Models::GroupMembership
53
+ (models[:group_membership] ||= []) << model
54
+ when Canvas::Models::Section
55
+ (models[:section] ||= []) << model
56
+ when Canvas::Models::Term
57
+ (models[:term] ||= []) << model
58
+ when Canvas::Models::User
59
+ (models[:user] ||= []) << model
60
+ when Canvas::Models::XList
61
+ (models[:xlist] ||= []) << model
62
+ when Canvas::Models::UserObserver
63
+ (models[:user_observer] ||= []) << model
64
+ end
65
+ end
66
+ return models
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -1,6 +1,7 @@
1
1
  module IntegrationPal
2
2
  class Engine < ::Rails::Engine
3
3
  require 'api-auth'
4
+ require 'rack-cas'
4
5
  require 'rack-cas-rails'
5
6
  require 'attr_encrypted'
6
7
 
@@ -1,3 +1,3 @@
1
1
  module IntegrationPal
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: integration_pal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Tanner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.5.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: httmultiparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.16
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.16
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pg
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +206,22 @@ files:
192
206
  - config/routes.rb
193
207
  - db/migrate/20170524203831_create_integration_pal_workers.rb
194
208
  - db/migrate/20170525153603_create_integration_pal_jobs.rb
209
+ - lib/canvas/client.rb
210
+ - lib/canvas/models/account.rb
211
+ - lib/canvas/models/base_model.rb
212
+ - lib/canvas/models/course.rb
213
+ - lib/canvas/models/enrollment.rb
214
+ - lib/canvas/models/file.rb
215
+ - lib/canvas/models/folder.rb
216
+ - lib/canvas/models/group.rb
217
+ - lib/canvas/models/group_membership.rb
218
+ - lib/canvas/models/section.rb
219
+ - lib/canvas/models/term.rb
220
+ - lib/canvas/models/user.rb
221
+ - lib/canvas/models/user_observer.rb
222
+ - lib/canvas/models/x_list.rb
223
+ - lib/canvas/utils/csv.rb
224
+ - lib/canvas/utils/sis.rb
195
225
  - lib/integration_pal.rb
196
226
  - lib/integration_pal/engine.rb
197
227
  - lib/integration_pal/version.rb
@@ -244,8 +274,6 @@ files:
244
274
  - spec/dummy/config/secrets.yml
245
275
  - spec/dummy/config/spring.rb
246
276
  - spec/dummy/db/schema.rb
247
- - spec/dummy/log/development.log
248
- - spec/dummy/log/test.log
249
277
  - spec/dummy/package.json
250
278
  - spec/dummy/public/404.html
251
279
  - spec/dummy/public/422.html
@@ -331,8 +359,6 @@ test_files:
331
359
  - spec/dummy/config/spring.rb
332
360
  - spec/dummy/config.ru
333
361
  - spec/dummy/db/schema.rb
334
- - spec/dummy/log/development.log
335
- - spec/dummy/log/test.log
336
362
  - spec/dummy/package.json
337
363
  - spec/dummy/public/404.html
338
364
  - spec/dummy/public/422.html
@@ -1,38 +0,0 @@
1
-  (21.9ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
2
-  (4.3ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
3
-  (0.2ms) SELECT pg_try_advisory_lock(3791006887383934680);
4
-  (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
5
- Migrating to CreateIntegrationPalWorkers (20170524203831)
6
-  (0.1ms) BEGIN
7
-  (5.0ms) CREATE TABLE "integration_pal_workers" ("id" bigserial primary key, "name" character varying, "access_id" character varying, "secret_key" character varying, "job_type" character varying, "encrypted_settings" text, "encrypted_settings_iv" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
8
- SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20170524203831"]]
9
-  (0.4ms) COMMIT
10
- Migrating to CreateIntegrationPalJobs (20170525153603)
11
-  (0.2ms) BEGIN
12
-  (6.3ms) CREATE TABLE "integration_pal_jobs" ("id" bigserial primary key, "job_params" text, "status" character varying, "started_at" timestamp, "finished_at" timestamp, "progress" character varying, "worker_id" integer, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
13
- SQL (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20170525153603"]]
14
-  (0.5ms) COMMIT
15
- ActiveRecord::InternalMetadata Load (1.9ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
16
-  (0.2ms) BEGIN
17
- SQL (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2017-05-25 21:27:34.579475"], ["updated_at", "2017-05-25 21:27:34.579475"]]
18
-  (0.4ms) COMMIT
19
-  (0.3ms) SELECT pg_advisory_unlock(3791006887383934680)
20
-  (0.2ms) SELECT pg_try_advisory_lock(3791006887383934680);
21
-  (1.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
22
- ActiveRecord::InternalMetadata Load (1.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
23
-  (0.2ms) BEGIN
24
-  (0.1ms) COMMIT
25
-  (0.3ms) SELECT pg_advisory_unlock(3791006887383934680)
26
-  (0.2ms) SELECT pg_try_advisory_lock(3791006887383934680);
27
-  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
28
- ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
29
-  (0.1ms) BEGIN
30
-  (0.1ms) COMMIT
31
-  (0.2ms) SELECT pg_advisory_unlock(3791006887383934680)
32
-  (0.2ms) SELECT pg_try_advisory_lock(3791006887383934680);
33
-  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
34
- ActiveRecord::InternalMetadata Load (1.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
35
-  (0.1ms) BEGIN
36
-  (0.1ms) COMMIT
37
-  (0.2ms) SELECT pg_advisory_unlock(3791006887383934680)
38
-  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC