haiku_grades 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdbd73188250edd455c807d94da8e130c6b4b41b
4
+ data.tar.gz: a6859d26ec24d7175f30ec333ae912f971331d92
5
+ SHA512:
6
+ metadata.gz: dd0dcc3bddbe411c27b820faa1cd5bf6db13182e191227b9c57599013ce9c4bccb4d75a239ab9a64aec546cee481c2406b2face73935a03edbdb3a49b8fc8ef4
7
+ data.tar.gz: cba863912853fda1c038722ec927a664bc62656437dc64763cfe38c04308f994082e1fde826a0b1bddd7b3c9d4226348787415592e7e0c0afb0463e91b967963
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ config/*.yml
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem "hapi-client", git: "git@github.com:haikulearning/hapi-client.git"
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Haiku Grades
2
+
3
+ This Ruby Gem allows you to connect to your Haiku Learning domain and export grades for a specific teacher into csv format.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Application's Gemfile:
8
+
9
+ `gem 'haiku_grades'`
10
+
11
+ And then execute:
12
+
13
+ `$ bundle`
14
+
15
+ Or install it yourself as:
16
+
17
+ `$ gem install haiku_grades`
18
+
19
+ ## Usage
20
+
21
+ Rename the authentication.yml.sample file to authentication.yml, adding in your domain's details, before running.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it!
26
+ 2. Create your feature branch: `git checkout -b my-new-feature`
27
+ 3. Commit your changes: `git commit -am 'Add some feature'`
28
+ 4. Push to the branch: `git push origin my-new-feature`
29
+ 5. Submit a pull request :D
30
+
31
+ ## History
32
+
33
+ TODO: Write history
34
+
35
+ ## Credits
36
+
37
+ TODO: Write credits
38
+
39
+ ## License
40
+
41
+ Copyright (c) 2015 Haiku Learning
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining a copy
44
+ of this software and associated documentation files (the "Software"), to deal
45
+ in the Software without restriction, including without limitation the rights
46
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
47
+ copies of the Software, and to permit persons to whom the Software is
48
+ furnished to do so, subject to the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be included in
51
+ all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
59
+ THE SOFTWARE.
data/class_list.csv ADDED
@@ -0,0 +1,3 @@
1
+ id,name,code,term,year,end_date,shortname,start_date,description,for_student_only,term_schedule_id,external_id,portal_color_selected,portal_color_unselected,allow_student_to_student_messages,teacher,sections,links
2
+ 5198679,Intro to English,ENG101,,2015-2016,,introtoenglish,,An Introduction to English,true,,eng101-2015,#bf3232,#e53939,false,"{""id""=>8974365, ""login""=>""andrew"", ""email""=>""Andrew@examplevillehs.com"", ""enabled""=>true, ""last_name""=>""Newman"", ""full_name""=>""Sketch Newman"", ""user_type""=>""Teacher"", ""domain_id""=>5677, ""display_id""=>""S233"", ""first_name""=>""Andrew"", ""avatar_url""=>""https://www.myhaikuclass.com/images/haiku_avatar_4.png"", ""display_login""=>""andrew"", ""time_zone_name""=>""Eastern Time (US & Canada)"", ""google_email_address""=>"""", ""external_id""=>""23986"", ""grade_levels""=>[]}",[],"[{""rel""=>""web_ui"", ""href""=>""https://no-real-data.haikulearning.com/andrew/introtoenglish""}]"
3
+ 5401925,Intro to English - Manually Added,"",,2015-2016,,introtoenglish-manuallyadded,,"",true,,,#bfab32,#ccba33,false,"{""id""=>8974365, ""login""=>""andrew"", ""email""=>""Andrew@examplevillehs.com"", ""enabled""=>true, ""last_name""=>""Newman"", ""full_name""=>""Sketch Newman"", ""user_type""=>""Teacher"", ""domain_id""=>5677, ""display_id""=>""S233"", ""first_name""=>""Andrew"", ""avatar_url""=>""https://www.myhaikuclass.com/images/haiku_avatar_4.png"", ""display_login""=>""andrew"", ""time_zone_name""=>""Eastern Time (US & Canada)"", ""google_email_address""=>"""", ""external_id""=>""23986"", ""grade_levels""=>[]}","[{""id""=>1320339, ""grouping_id""=>298266, ""name""=>""A""}, {""id""=>1320340, ""grouping_id""=>298266, ""name""=>""B""}]","[{""rel""=>""web_ui"", ""href""=>""https://no-real-data.haikulearning.com/andrew/introtoenglish-manuallyadded""}]"
@@ -0,0 +1,5 @@
1
+ # Edit this file to enter your details
2
+
3
+ haikugrades:
4
+ domain: no-real-data.haikulearning.com
5
+ api_key: 05378d310dc85a492df2200be254be7f # Replace this with your API key found in Manage Domain -> Settings -> Import API
data/entries_.csv ADDED
@@ -0,0 +1,2 @@
1
+ id,points,user_id,comment,finalized,created_at,updated_at,sticky_note,entered_score,displayed_percent_score,displayed_score,displayed_points,displayed_letter_notation,eclass_user_id,gradebook_entry_id,special_score_notation_id
2
+ 88246478,98.0,8974327,,,2015-08-13T18:59:32Z,2015-08-13T18:59:32Z,,98.00,98.00,98.00,,A,147908846,6150046,
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'haiku_grades/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "haiku_grades"
7
+ spec.version = HaikuGrades::VERSION
8
+ spec.authors = ["Sam"]
9
+ spec.email = ["samf@haikulearning.com"]
10
+ spec.summary = %q{Pulls grades and exports them from a teacher within a Haiku Learning domain.}
11
+ spec.description = %q{Pulls grades and exports them from a teacher within a Haiku Learning domain.}
12
+ spec.homepage = "http://rubygems.org/gems/haiku_grades"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency 'rubocop'
22
+ spec.add_dependency 'hapi-client' # , git: 'git@github.com:haikulearning/hapi-client.git'
23
+ spec.add_dependency 'highline'
24
+ end
@@ -0,0 +1,27 @@
1
+ class ClassExport
2
+ def self.class_list(client)
3
+ hash = client.user.eclasses_teaching['items']
4
+
5
+ # Pulls just the keys of the hash (the first values) to be used as
6
+ # column names
7
+ column_names = hash.first.keys
8
+
9
+ # Sets variable s to be a CSV, starts a loop
10
+ s = CSV.generate do |csv|
11
+ # For each item csv, adds a row (which is what '<<' does) with
12
+ # column_names (so one row)
13
+ csv << column_names
14
+ # For each item in hash (which is the list above that contains items
15
+ # within the classes the user teaches)
16
+ hash.each do |x|
17
+ # Add the values (remember, key-value pair in a hash) to a new row
18
+ # underneath the column headers
19
+ csv << x.values
20
+ end
21
+ end
22
+ # Writes the data (s) to a new file called "data.csv"
23
+ File.write('class_list.csv', s)
24
+ puts 'List exported to working directory.'
25
+ puts ''
26
+ end
27
+ end
data/lib/full_grade.rb ADDED
@@ -0,0 +1,36 @@
1
+ class FullGrade
2
+
3
+ def self.full_list(client)
4
+ entries_columns = ''
5
+ gradebook_entries = ''
6
+ class_selection = ''
7
+ client.user.eclasses_teaching['items'].each do |eclass|
8
+ # Starts a loop to go through each element of the "items" hash within the client.user.eclasses_teaching method in the API
9
+ client.user.eclasses_teaching['items'].each do |eclass|
10
+ # Sets variable gradebooks equal to all gradebooks, accepts argument that says the eclass_id is equal to an "id" within "items" - in other words, it loops through and grabs gradebooks from each class belonging to the user
11
+ gradebooks = client.gradebooks.all(eclass_id: eclass['id'])
12
+ # Now that we have a list of gradebooks from all classes, go through the items hash in those gradebooks
13
+ gradebooks['items'].each do |gradebook|
14
+ # And, for each one, define entries within
15
+ gradebook_entries = client.gradebooks.entries(eclass_id: eclass['id'], gradebook_id: gradebook['id'], include_scores: true)
16
+ # Now we want to go through each entry and look int he items hash
17
+ gradebook_entries['items'].each do |entry|
18
+ # And we want to define columns (for use in a csv) as the keys for gradebook_entries - items, in the first array, then in the gradebook_entry_scores hash, then in the first array within that hash (since we just need column names)
19
+ entries_columns = gradebook_entries['items'][0]['gradebook_entry_scores'][0].keys
20
+ end
21
+ end
22
+ end
23
+ # Now, we need to make a csv for entries - we are using the shortname of the class to name the file so the same file is not overwritten each time,
24
+ # instead, a new file is created for each class
25
+ CSV.open("entries_.csv", 'wb') do |csv|
26
+ # Add a row for the column names defined above
27
+ csv << entries_columns
28
+ gradebook_entries['items'].each do |y|
29
+ y['gradebook_entry_scores'].each do |y|
30
+ csv << y.values
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module HaikuGrades
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,87 @@
1
+ $LOAD_PATH << '.'
2
+
3
+ require 'hapi-client'
4
+ require 'csv'
5
+ require 'highline/import'
6
+ require 'yaml'
7
+ require_relative 'full_grade'
8
+ require_relative 'partial_grade'
9
+ require_relative 'class_export'
10
+
11
+ # Authentication information
12
+ # USERNAME = 'andrew'
13
+ # PASSWORD = 'test1234'
14
+
15
+ # Commenting out for testing purposes
16
+ # puts "Enter your domain URL without www or https://
17
+ # (for example, test.haikulearning.com)"
18
+ # input_domain = gets.chomp
19
+
20
+ # puts "What is your API key?"
21
+ # input_apikey = gets.chomp
22
+
23
+ class HaikuGrades
24
+
25
+ attr_writer :config
26
+
27
+ def initialize
28
+ # path can be either from root or for debugging from the curent class
29
+ if File.exists?('../../config/authentication.yml')
30
+ @config = YAML.load(File.open('../../config/authentication.yml'))
31
+ elsif File.exists?('./config/authentication.yml')
32
+ @config = YAML.load(File.open('./config/authentication.yml'))
33
+ else
34
+ raise StandardError, 'Cannot find configuration file. Please make sure you have edited authentication.yml.'
35
+ end
36
+ end
37
+
38
+ input_domain = @config['haikugrades']['domain']
39
+ input_apikey = @config['haikugrades']['api_key']
40
+
41
+ puts 'What is your Haiku Learning username?'
42
+ input_username = gets.chomp
43
+
44
+ input_password = ask('What is your Haiku Learning password? ' + "\n") { |q| q.echo = false }
45
+
46
+ begin
47
+ # Instantiate a client using the information above
48
+ client = HapiClient::Client.new(api_key: input_apikey,
49
+ base_endpoint: "https://#{input_domain}", debug: 'true')
50
+ rescue
51
+ raise 'You entered an incorrect API key or domain name - please try again!'
52
+ end
53
+
54
+ begin
55
+ # Login as a single user
56
+ session = client.login_as(username: input_username,
57
+ password: input_password)
58
+ rescue
59
+ raise 'You entered an incorrect username or password - please try again!' if session.nil?
60
+ end
61
+
62
+ puts 'Would you like a list of your classes exported to csv? (y/n)'
63
+ export = gets.chomp
64
+ if export == 'y'
65
+ ClassExport.class_list(client)
66
+ else
67
+ puts ''
68
+ end
69
+
70
+ # Ask user which class they want grades for
71
+ puts "Your classes are: " + "\n"
72
+ client.user.eclasses_teaching['items'].each do |eclass|
73
+ puts "#{eclass['name']}" + " : #{eclass['id']} (id)"
74
+ end
75
+
76
+ puts ""
77
+ puts "Please enter the id of the class whose grade entries you'd like exported to CSV. If you'd like all classes, simply type 'all', without the single quotation marks."
78
+ class_selection = gets.chomp
79
+
80
+ if class_selection == 'all'
81
+ FullGrade.full_list(client)
82
+ else
83
+ PartialGrade.partial_list(class_selection, client)
84
+ end
85
+
86
+ puts 'Ran successfully.'
87
+ end
@@ -0,0 +1,37 @@
1
+ class PartialGrade
2
+
3
+ def self.partial_list(class_selection, client)
4
+ entries_columns = ''
5
+ gradebook_entries = ''
6
+ # class_selection = ''
7
+ # partial_list - eventually will just be a method
8
+ # client.user.eclasses_teaching["items"].each do |eclass|
9
+ # Starts a loop to go through each element of the "items"
10
+ # hash within the client.user.eclasses_teaching method in the API
11
+ # client.user.eclasses_teaching["items"].each do |eclass|
12
+ # Sets variable gradebooks equal to all gradebooks, accepts argument
13
+ # that says the eclass_id is equal to an "id" within "items" - in other words, it loops through and grabs gradebooks from each class belonging to the user
14
+ gradebooks = client.gradebooks.all(eclass_id: class_selection)
15
+ gradebooks['items'].to_a.each do |gradebook|
16
+ # And, for each one, define entries within
17
+ gradebook_entries = client.gradebooks.entries(eclass_id: class_selection, gradebook_id: gradebook['id'], include_scores: true)
18
+ # Still 4 entries at this point
19
+ # Now we want to go through each entry and look int he items hash
20
+ gradebook_entries['items'].each do |entry|
21
+ # And we want to define columns (for use in a csv) as the keys for gradebook_entries - items, in the first array, then in the gradebook_entry_scores hash, then in the first array within that hash (since we just need column names)
22
+ entries_columns = gradebook_entries['items'][0]['gradebook_entry_scores'][0].keys
23
+ end
24
+ end
25
+ # Now, we need to make a csv for entries - we are using the shortname of the class to name the file so the same file is not overwritten each time,
26
+ # instead, a new file is created for each class
27
+ CSV.open("entries_#{class_selection}.csv", 'wb') do |csv|
28
+ # Add a row for the column names defined above
29
+ csv << entries_columns
30
+ gradebook_entries['items'].each do |y|
31
+ y['gradebook_entry_scores'].each do |y|
32
+ csv << y.values
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haiku_grades
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: hapi-client
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: highline
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
+ description: Pulls grades and exports them from a teacher within a Haiku Learning
70
+ domain.
71
+ email:
72
+ - samf@haikulearning.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - class_list.csv
81
+ - config/authentication.yml.sample
82
+ - entries_.csv
83
+ - haiku_grades.gemspec
84
+ - lib/class_export.rb
85
+ - lib/full_grade.rb
86
+ - lib/haiku_grades.rb
87
+ - lib/haiku_grades/version.rb
88
+ - lib/partial_grade.rb
89
+ homepage: http://rubygems.org/gems/haiku_grades
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Pulls grades and exports them from a teacher within a Haiku Learning domain.
113
+ test_files: []