bobross 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ class CanvasAccount < CanvasObject
2
+
3
+ attr_reader :name, :uid, :parent_uid, :root_uid, :time_zone, :sis_id, :workflow
4
+
5
+ def to_s
6
+ string = "#{name}, #{uid}, #{parent_uid}, #{root_uid}, #{time_zone}, #{sis_id}, #{workflow}"
7
+ end
8
+
9
+ def to_csv
10
+ row = [uid, parent_uid, name, 'active', nil]
11
+ end
12
+
13
+ # future relase: Make fields reuired by canvas required here
14
+ def initialize(opts = {})
15
+ @name = opts[:name] if opts[:name]
16
+ @uid = opts[:uid] if opts[:uid]
17
+ @parent_id = opts[:parent] if opts[:parent]
18
+ @root_id = opts[:root] if opts[:root]
19
+ @time_zone = opts[:time_zone] if opts[:time_zone]
20
+ @sis_id = opts[:sis] if opts[:sis]
21
+ @workflow = opts[:workflow] if opts[:workflow]
22
+ end
23
+
24
+ def self.random (parent_id = 1 , root_id = 1)
25
+ a = Forgery('name').company_name
26
+ CanvasAccount.new(
27
+ {
28
+ name: a,
29
+ uid: "#{a}-#{rand(10_000)}",
30
+ parent: parent_id,
31
+ root: root_id,
32
+ time_zone: Forgery('time').zone,
33
+ sis_id: (10_000+rand(10_000_000)),
34
+ workflow: 'active'
35
+ }
36
+ )
37
+ end
38
+
39
+ def self.gen_file(opts = {})
40
+ opts[:rows] ? rows = opts[:rows] : rows = 0
41
+ opts[:parent] ? parent = opts[:parent] : parent = 1
42
+ opts[:root] ? root = opts[:root] : root = 1
43
+ accounts = []
44
+ if(opts[:rows])
45
+ rows.times do |x|
46
+ accounts.push(CanvasAccount.random(parent, root))
47
+ end
48
+ end
49
+ header = %w[account_id parent_account_id name status integration_id]
50
+ CSV.open('./accounts.csv', 'wb', write_headers: true, headers: header) do |csv|
51
+ accounts.each do |acc|
52
+ csv << acc.to_csv
53
+ end
54
+ end
55
+ return accounts
56
+ end
57
+
58
+ end
@@ -0,0 +1,56 @@
1
+ class CanvasAssignment < CanvasObject
2
+ attr_reader :name, :description, :course_uid, :assignment_group
3
+ attr_accessor :due_at, :lock_at, :host_info
4
+
5
+ def to_s
6
+ string = "#{name}, #{description}, #{due_at}, #{lock_at}, #{course_uid}, #{assignment_group}"
7
+ end
8
+
9
+ def to_csv
10
+ row = [name, description, due_at, lock_at, course_uid, assignment_group]
11
+ end
12
+
13
+ def initialize(opts = {})
14
+ @name = opts[:name] if opts[:name]
15
+ @description = opts[:description] if opts[:description]
16
+ @due_at = opts[:due_at] if opts[:due_at]
17
+ @lock_at = opts[:lock_at] if opts[:lock_at]
18
+ @course_uid = opts[:course_uid] if opts[:course_uid]
19
+ @assignment_group = opts[:assignment_group] if opts[:assignment_group]
20
+ end
21
+
22
+ def self.random (course = 1, group = 1)
23
+ d = Forgery('date').date
24
+ CanvasAssignment.new(
25
+ {
26
+ name: "What #{Forgery('name').job_title} #{Forgery('name').full_name} said about #{Forgery('name').industry}",
27
+ description: "#{Forgery('lorem_ipsum').paragraphs}",
28
+ due_at: d,
29
+ lock_at: d+10.days,
30
+ course_uid: course,
31
+ assignment_group: group
32
+ }
33
+ )
34
+ end
35
+
36
+ def self.gen_file(opts = {})
37
+ course, group = 1
38
+ opts[:rows] ? rows = opts[:rows] : rows = 0
39
+ course = opts[:course] if opts[:course]
40
+ group = opts[:group] if opts[:group]
41
+ assignments = []
42
+ if(opts[:rows])
43
+ rows.times do |x|
44
+ assignments.push(CanvasAssignment.random(course, group))
45
+ end
46
+ end
47
+ header = %w[name description due_at lock_at course_id assignment_group]
48
+ CSV.open('./assignments.csv', 'wb', write_headers: true, headers: header) do |csv|
49
+ assignments.each do |acc|
50
+ csv << acc.to_csv
51
+ end
52
+ end
53
+ return assignments
54
+ end
55
+
56
+ end
@@ -0,0 +1,9 @@
1
+ class CanvasAssignmentGrade < Forgery
2
+
3
+ def to_s
4
+ string = ''
5
+ end
6
+
7
+ def self.random
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CanvasAssignmentGroup < Forgery
2
+
3
+ def to_s
4
+ string = ''
5
+ end
6
+
7
+ def self.random
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AssignmentSubmission < Forgery
2
+
3
+ def to_s
4
+ string = ''
5
+ end
6
+
7
+ def self.random
8
+ end
9
+ end
@@ -0,0 +1,72 @@
1
+ class CanvasCourse < CanvasObject
2
+ attr_reader :name, :uid, :sis_id, :description, :account_id, :term_id, :start_date, :end_date
3
+ @@local_dictionaries = $LOAD_PATH.grep(/bobross.*lib/).first
4
+
5
+ def initialize(opts = {})
6
+ @name = opts[:name] if opts[:name]
7
+ @uid = opts[:uid] if opts[:uid]
8
+ @sis_id = "#{opts[:sis]}" if opts[:sis]
9
+ @description = opts[:desc] if opts[:desc]
10
+ @account_id = opts[:account] if opts[:account]
11
+ @term_id = opts[:term] if opts[:term]
12
+ @start_date = opts[:start] if opts[:start]
13
+ @end_date = opts[:end] if opts[:end]
14
+ end
15
+
16
+ def to_s
17
+ s = "#{name}, #{uid}, #{sis_id}, #{description}"
18
+ end
19
+
20
+ def to_csv
21
+ row = [sis_id, uid, name, account_id, term_id, 'active', nil, start_date, end_date, 'online', nil]
22
+ end
23
+
24
+ def self.set_prefix prefix
25
+ @@prefix = prefix
26
+ end
27
+
28
+ def self.random
29
+ CanvasCourse.new(
30
+ {
31
+ name: CanvasCourse.course_name,
32
+ uid: CanvasCourse.course_code,
33
+ sis: (12_000+rand(1_000_000)).to_s,
34
+ desc: CanvasCourse.description
35
+ }
36
+ )
37
+ end
38
+
39
+ def self.course_code
40
+ Forgery.load_from!(@@local_dictionaries)
41
+ dictionaries[:course_codes][@@row]
42
+ end
43
+
44
+ def self.course_name
45
+ Forgery.load_from!(@@local_dictionaries)
46
+ name_count = Forgery.dictionaries[:course_names].count
47
+ @@row = rand(name_count)
48
+ dictionaries[:course_names][@@row]
49
+ end
50
+
51
+ def self.description
52
+ Forgery(:lorem_ipsum).words(2+rand(30))
53
+ end
54
+
55
+ def self.gen_file(opts = {})
56
+ opts[:rows] ? rows = opts[:rows] : rows = 0
57
+ courses = []
58
+ if(opts[:rows])
59
+ rows.times do |x|
60
+ courses.push(CanvasCourse.random)
61
+ end
62
+ end
63
+ header = %w[course_id short_name long_name account_id term_id status integration_id start_date end_date course_format blueprint_course_id]
64
+ CSV.open('./courses.csv', 'wb', write_headers: true, headers: header) do |csv|
65
+ courses.each do |acc|
66
+ csv << acc.to_csv
67
+ end
68
+ end
69
+ return courses
70
+ end
71
+
72
+ end
@@ -0,0 +1,9 @@
1
+ class CanvasGroupInAccount < Forgery
2
+
3
+ def to_s
4
+ string = ''
5
+ end
6
+
7
+ def self.random
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CanvasGroupInCourse < Forgery
2
+
3
+ def to_s
4
+ string = ''
5
+ end
6
+
7
+ def self.random
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ class CanvasObject < Forgery
2
+
3
+ def self.push_csv_to_canvas(opts={})
4
+ if(opts.nil? || opts[:host].nil? || opts[:token].nil?)
5
+ raise 'Please provide options hash with both :host and :token'
6
+ end
7
+ if(!File.file?(opts[:file]))
8
+ raise 'Please gen_file before trying to push to canvas'
9
+ end
10
+ uri = URI.parse("https://#{opts[:host]}/api/v1/accounts/self/sis_imports.json?import_type=instructure_csv")
11
+ request = Net::HTTP::Post.new(uri)
12
+ request.content_type = 'text/csv'
13
+ request['Authorization'] = "Bearer #{opts[:token]}"
14
+ request.body = ''
15
+ request.body << File.read(opts[:file])
16
+
17
+ req_options = {
18
+ use_ssl: uri.scheme == 'https',
19
+ }
20
+
21
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
22
+ http.request(request)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ class CanvasSection < CanvasObject
2
+ attr_reader :name, :sis_id, :start_date, :end_date
3
+ attr_accessor :course_uid, :course_sis_id
4
+
5
+ def to_csv
6
+ row = [sis_id, course_sis_id, name, 'active', nil, start_date, end_date]
7
+ end
8
+
9
+ def initialize(opts = {})
10
+ @name = opts[:name] if opts[:name]
11
+ @sis_id = opts[:sis_id] if opts[:sis_id]
12
+ @course_id = opts[:course] if opts[:course]
13
+ @start_date = opts[:start_at] if opts[:start_at]
14
+ @end_date = opts[:end_at] if opts[:end_at]
15
+ end
16
+
17
+ def self.random(course=1)
18
+ d = Forgery('date').date
19
+ CanvasSection.new(
20
+ {
21
+ name: "#{Forgery('address').country} #{Forgery('basic').color}",
22
+ sis_id: (21000+rand(1000000)),
23
+ course: course,
24
+ start_date: d,
25
+ end_date: d+90.days
26
+ }
27
+ )
28
+ end
29
+
30
+ def self.gen_file(opts = {})
31
+ opts[:rows] ? rows = opts[:rows] : rows = 0
32
+ sections = []
33
+ if(opts[:rows])
34
+ rows.times do |x|
35
+ sections.push(CanvasSection.random)
36
+ end
37
+ end
38
+
39
+ header = %w[section_id course_id name status integration_id start_date end_date]
40
+ CSV.open('./sections.csv', 'wb', write_headers: true, headers: header) do |csv|
41
+ sections.each do |acc|
42
+ csv << acc.to_csv
43
+ end
44
+ end
45
+ return sections
46
+ end
47
+
48
+ end
@@ -0,0 +1,60 @@
1
+ class CanvasUser < CanvasObject
2
+ attr_reader :name, :sis_id, :login_id, :email, :time_zone
3
+
4
+ def to_s
5
+ string = "#{name}, #{sis_id}, #{login_id}, #{email}, #{time_zone}"
6
+ end
7
+
8
+ def to_csv
9
+ names = name.split(' ')
10
+ row = [sis_id, nil, login_id, nil, nil, nil, names.first, names.last, name, "#{names.last}, #{names.first}", "#{names.first[0].downcase}#{names.last.downcase}", email, 'active']
11
+ end
12
+
13
+ def initialize (opts = {})
14
+ @name = opts[:name] if opts[:name]
15
+ @sis_id = opts[:sis] if opts[:sis]
16
+ @login_id = opts[:login] if opts[:login]
17
+ @email = opts[:email] if opts[:email]
18
+ @time_zone = opts[:time_zone] if opts[:time_zone]
19
+ end
20
+
21
+ def self.random (opts = {})
22
+ fn = Forgery('name').first_name
23
+ ln = Forgery('name').last_name
24
+ domain = 'instructure.com'
25
+ if opts
26
+ opts[:email_prefix] ? epre = "#{opts[:email_prefix]}+" : epre = ''
27
+ opts[:sis_prefix] ? sispre = "#{opts[:sis_prefix]}_" : sispre = ''
28
+ opts[:domain] ? domain = opts[:domain] : domain = 'instructure.com'
29
+ end
30
+ e = "#{epre}#{fn}.#{ln}@#{domain}"
31
+ CanvasUser.new(
32
+ {
33
+ name: "#{fn} #{ln}",
34
+ sis: "#{sispre}#{(3_000+rand(1_000_000))}",
35
+ login: e,
36
+ email: e,
37
+ time_zone: Forgery('time').zone
38
+ }
39
+ )
40
+ end
41
+
42
+ def self.gen_file(opts = {})
43
+ opts[:rows] ? rows = opts[:rows] : rows = 0
44
+ opts[:settings] ? settings = opts[:settings] : settings = nil
45
+ users = []
46
+ if(opts[:rows])
47
+ rows.times do |x|
48
+ users.push(CanvasUser.random(settings))
49
+ end
50
+ end
51
+ header = %w[user_id integration_id login_id password ssha_password authentication_provider_id first_name last_name full_name sortable_name short_name email status]
52
+ CSV.open('./users.csv', 'wb', write_headers: true, headers: header) do |csv|
53
+ users.each do |acc|
54
+ csv << acc.to_csv
55
+ end
56
+ end
57
+ return users
58
+ end
59
+
60
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bobross
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.13
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Slack
8
+ - Trevor Byington
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-07-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bearcat
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.4.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.4
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 2.1.4
42
+ - !ruby/object:Gem::Dependency
43
+ name: forgery
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.7.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.7.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 13.0.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 13.0.1
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.9'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.9'
84
+ description: Generates data to put in your canvas instance. Data can be exported as
85
+ CSV for uploading or sent directly via api call
86
+ email:
87
+ - jacobs@instructure.com
88
+ - tbyington@instructure.com
89
+ - tabyington@gmail.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".DS_Store"
95
+ - ".gitignore"
96
+ - ".rbenv-gemsets"
97
+ - ".rspec"
98
+ - ".ruby-version"
99
+ - ".travis.yml"
100
+ - ".vscode/settings.json"
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - bin/console
107
+ - bin/setup
108
+ - bobross.gemspec
109
+ - lib/bobross.rb
110
+ - lib/bobross/version.rb
111
+ - lib/dictionaries/course_codes
112
+ - lib/dictionaries/course_names
113
+ - lib/models/canvas_account.rb
114
+ - lib/models/canvas_assignment.rb
115
+ - lib/models/canvas_assignment_grade.rb
116
+ - lib/models/canvas_assignment_group.rb
117
+ - lib/models/canvas_assignment_submission.rb
118
+ - lib/models/canvas_course.rb
119
+ - lib/models/canvas_group_in_account.rb
120
+ - lib/models/canvas_group_in_course.rb
121
+ - lib/models/canvas_object.rb
122
+ - lib/models/canvas_section.rb
123
+ - lib/models/canvas_user.rb
124
+ homepage: https://rubygems.org/gems/bobross
125
+ licenses:
126
+ - MIT
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
129
+ homepage_uri: https://rubygems.org/gems/bobross
130
+ source_code_uri: https://github.com/instructurecustomdevqa/bobross
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.1.2
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Generates data to put in your canvas instance.
150
+ test_files: []