canvas_sync 0.2.3 → 0.2.4

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: 430c8ec60a8869bd4c7ed65b24057496793115af
4
- data.tar.gz: cde2e6c7f4016df8b4d2c225e35469e750f3f4d3
3
+ metadata.gz: 23899e5c41cb63d0267eb031be38b7810e84f58e
4
+ data.tar.gz: 7e6c5093980d7e07d271a85a330c2fcae8d52b54
5
5
  SHA512:
6
- metadata.gz: '08ca7f817cbcf1ce58cf0c0c8fee4fe4afe9c1f09fbc2b89859f4fdc0332f9430d02c8ee800caf30caecd06a4a8e8a42db31bdf0d6016c7ece0cad344da0287c'
7
- data.tar.gz: 3c7528cad8053d81c6e95f6e8126d872e1334cb8793521cf1b9027a5eadc16962504a4db78d1470a780ce752e683165b2d136e252c6b85ea9c9a878e4470b900
6
+ metadata.gz: 32803f19bc38b505ab67abcdbcc55b3b283a00b79541942fea14142306ce6e569ba1746efc2d6a1d55c6eccd2b6cf7046a4f1f200e9cda9a4cd01f749f22b839
7
+ data.tar.gz: 83b5c340093e644dc26faf58ae297f937f207b0457c32b0991fad1c2194c773e49f0dff929aa0d9f4f39f6f2eafd028e1f6afc039bd240648e7b478ff03e141e
@@ -19,7 +19,7 @@ module CanvasSync
19
19
  # This can be used if you need to filter or massage the data in any way.
20
20
  def self.import(report_file_path, mapping, klass, conflict_target, exclude_duplicates=false)
21
21
  csv_column_names = mapping.keys
22
- database_column_names = mapping.values
22
+ database_column_names = mapping.values.map{ |value| value[:database_column_name] }
23
23
  rows = []
24
24
  row_ids = {}
25
25
 
@@ -32,7 +32,13 @@ module CanvasSync
32
32
  row_ids[row[conflict_target]] = true
33
33
  end
34
34
 
35
- rows << csv_column_names.map { |column| row[column] }
35
+ rows << csv_column_names.map do |column|
36
+ if mapping[column][:type] == :datetime
37
+ DateTime.parse(row[column]).utc if row[column].present?
38
+ else
39
+ row[column]
40
+ end
41
+ end
36
42
 
37
43
  if rows.length >= batch_size
38
44
  perform_import(klass, database_column_names, rows, conflict_target)
@@ -8,55 +8,166 @@ module CanvasSync
8
8
  # Used by the {CanvasSync::Importers::BulkImporter bulk importer}. The keys are
9
9
  # CSV columns and the values are the database columns.
10
10
  USERS_CSV_MAPPING = {
11
- canvas_user_id: :canvas_user_id,
12
- user_id: :sis_id,
13
- email: :email,
14
- first_name: :first_name,
15
- last_name: :last_name,
16
- status: :status,
17
- login_id: :login_id
11
+ canvas_user_id: {
12
+ database_column_name: :canvas_user_id,
13
+ type: :integer
14
+ },
15
+ user_id: {
16
+ database_column_name: :sis_id,
17
+ type: :string
18
+ },
19
+ email: {
20
+ database_column_name: :email,
21
+ type: :string
22
+ },
23
+ first_name: {
24
+ database_column_name: :first_name,
25
+ type: :string
26
+ },
27
+ last_name: {
28
+ database_column_name: :last_name,
29
+ type: :string
30
+ },
31
+ status: {
32
+ database_column_name: :status,
33
+ type: :string
34
+ },
35
+ login_id: {
36
+ database_column_name: :login_id,
37
+ type: :string
38
+ }
18
39
  }
19
40
 
20
41
  COURSES_CSV_MAPPING = {
21
- canvas_course_id: :canvas_course_id,
22
- course_id: :sis_id,
23
- short_name: :short_name,
24
- long_name: :long_name,
25
- canvas_account_id: :canvas_account_id,
26
- canvas_term_id: :canvas_term_id,
27
- term_id: :term_sis_id,
28
- start_date: :start_date,
29
- end_date: :end_date,
30
- status: :status
42
+ canvas_course_id: {
43
+ database_column_name: :canvas_course_id,
44
+ type: :integer
45
+ },
46
+ course_id: {
47
+ database_column_name: :sis_id,
48
+ type: :string
49
+ },
50
+ short_name: {
51
+ database_column_name: :short_name,
52
+ type: :string
53
+ },
54
+ long_name: {
55
+ database_column_name: :long_name,
56
+ type: :string
57
+ },
58
+ canvas_account_id: {
59
+ database_column_name: :canvas_account_id,
60
+ type: :integer
61
+ },
62
+ canvas_term_id: {
63
+ database_column_name: :canvas_term_id,
64
+ type: :integer
65
+ },
66
+ term_id: {
67
+ database_column_name: :term_sis_id,
68
+ type: :string
69
+ },
70
+ start_date: {
71
+ database_column_name: :start_date,
72
+ type: :datetime
73
+ },
74
+ end_date: {
75
+ database_column_name: :end_date,
76
+ type: :datetime
77
+ },
78
+ status: {
79
+ database_column_name: :status,
80
+ type: :integer
81
+ }
31
82
  }
32
83
 
33
84
  ENROLLMENTS_CSV_MAPPING = {
34
- canvas_enrollment_id: :canvas_enrollment_id,
35
- canvas_course_id: :canvas_course_id,
36
- course_id: :course_sis_id,
37
- canvas_user_id: :canvas_user_id,
38
- user_id: :user_sis_id,
39
- role: :role,
40
- role_id: :role_id,
41
- canvas_section_id: :canvas_section_id,
42
- section_id: :section_sis_id,
43
- status: :status,
44
- base_role_type: :base_role_type
85
+ canvas_enrollment_id: {
86
+ database_column_name: :canvas_enrollment_id,
87
+ type: :integer
88
+ },
89
+ canvas_course_id: {
90
+ database_column_name: :canvas_course_id,
91
+ type: :integer
92
+ },
93
+ course_id: {
94
+ database_column_name: :course_sis_id,
95
+ type: :string
96
+ },
97
+ canvas_user_id: {
98
+ database_column_name: :canvas_user_id,
99
+ type: :integer
100
+ },
101
+ user_id: {
102
+ database_column_name: :user_sis_id,
103
+ type: :string
104
+ },
105
+ role: {
106
+ database_column_name: :role,
107
+ type: :string
108
+ },
109
+ role_id: {
110
+ database_column_name: :role_id,
111
+ type: :integer
112
+ },
113
+ canvas_section_id: {
114
+ database_column_name: :canvas_section_id,
115
+ type: :integer
116
+ },
117
+ section_id: {
118
+ database_column_name: :section_sis_id,
119
+ type: :string
120
+ },
121
+ status: {
122
+ database_column_name: :status,
123
+ type: :string
124
+ },
125
+ base_role_type: {
126
+ database_column_name: :base_role_type,
127
+ type: :string
128
+ }
45
129
  }
46
130
 
47
131
  SECTIONS_CSV_MAPPING = {
48
- canvas_section_id: :canvas_section_id,
49
- section_id: :sis_id,
50
- canvas_course_id: :canvas_course_id,
51
- name: :name,
52
- status: :status,
53
- start_date: :start_date,
54
- end_date: :end_date
132
+ canvas_section_id: {
133
+ database_column_name: :canvas_section_id,
134
+ type: :integer
135
+ },
136
+ section_id: {
137
+ database_column_name: :sis_id,
138
+ type: :string
139
+ },
140
+ canvas_course_id: {
141
+ database_column_name: :canvas_course_id,
142
+ type: :integer
143
+ },
144
+ name: {
145
+ database_column_name: :name,
146
+ type: :string
147
+ },
148
+ status: {
149
+ database_column_name: :status,
150
+ type: :string
151
+ },
152
+ start_date: {
153
+ database_column_name: :start_date,
154
+ type: :datetime
155
+ },
156
+ end_date: {
157
+ database_column_name: :end_date,
158
+ type: :datetime
159
+ }
55
160
  }
56
161
 
57
162
  XLIST_CSV_MAPPING = {
58
- canvas_section_id: :canvas_section_id,
59
- canvas_nonxlist_course_id: :canvas_nonxlist_course_id
163
+ canvas_section_id: {
164
+ database_column_name: :canvas_section_id,
165
+ type: :integer
166
+ },
167
+ canvas_nonxlist_course_id: {
168
+ database_column_name: :canvas_nonxlist_course_id,
169
+ type: :integer
170
+ }
60
171
  }
61
172
 
62
173
  # Processes a provisioning report using the bulk importer.
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -14,6 +14,9 @@ RSpec.describe CanvasSync::Processors::ProvisioningReportProcessor do
14
14
  expect {
15
15
  subject.process('spec/support/fixtures/reports/courses.csv', { models: ['courses'] })
16
16
  }.to change { Course.count }.by(2)
17
+ course = Course.first
18
+ expect(course.start_date).to eq DateTime.parse("2017-03-27 21:53:18")
19
+ expect(course.end_date).to eq DateTime.parse("2017-04-27 12:21:18")
17
20
  end
18
21
 
19
22
  it 'processes enrollments' do
@@ -26,6 +29,9 @@ RSpec.describe CanvasSync::Processors::ProvisioningReportProcessor do
26
29
  expect {
27
30
  subject.process('spec/support/fixtures/reports/sections.csv', { models: ['sections'] })
28
31
  }.to change { Section.count }.by(2)
32
+ section = Section.first
33
+ expect(section.start_date).to eq DateTime.parse("2017-03-27 21:53:18")
34
+ expect(section.end_date).to eq DateTime.parse("2017-03-27 21:53:18")
29
35
  end
30
36
 
31
37
  it 'processes xlist' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Collings
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler