common_tools 0.1.1 → 0.1.2

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: b2a95d74e5f492d7ceb125c348f2655fd419c312
4
- data.tar.gz: 9d5ce6bd8169aed65d8c1fda6602c0d0dc954cda
3
+ metadata.gz: 32d15df00510dd6daa5eb7d0e2265333d4372df1
4
+ data.tar.gz: e9bedae78696baf4936d23ba8f7599faeb7e9def
5
5
  SHA512:
6
- metadata.gz: 5714ec808ddd6e4449aecaa335e7d339c14184ac11126f302195407833aacb3a4ee212634e2e667fd1935abb3b77e748ca3ded327d4431151279f403b0e2461e
7
- data.tar.gz: 307f7b03346ebc080cc6f2ce7e9ccd62f73d3b6b3a3f31ac82fdb76232f74a257f2ebe424639b694799afa183e3cc26e96710bbd29538579be504d31d6f76470
6
+ metadata.gz: 294d4912767ccf1a2d7c7121e70e99d40bfab4630b1af16171e6cd8f1beedb93a6401006b21cf6f4716836e572d57304344f7afb40fe8bef9c64b03b21bbdca2
7
+ data.tar.gz: f9eb17609998102eae12fdd5c7d7c4fe237d5cc6d85dfc3d2d1f9eb42d9b5914ff331045ff2fd147465fd355222da124025cbc520e4e9d5b49678f26bc77d4fd
data/README.md CHANGED
@@ -1,28 +1,55 @@
1
1
  # Instructor Tools: Common Tools
2
2
 
3
- Welcome to the instructor tools Common Tools gem. This gem will exist as a dependency of [Instructor-Tools](https://github.com/flatiron-labs/Instructor-tools-gem).
3
+ Welcome to the instructor tools Common Tools gem. This gem will exist as a dependency of [Instructor-Tools](https://github.com/flatiron-labs/Instructor-tools-gem).
4
4
 
5
- The purpose of this gem is to provide instructors with a resource for commonly used tools (parsing a batch csv into student objects) that can be required as a dependency instead of re-writing the same code.
5
+ The purpose of this gem is to provide instructors with a resource for commonly used tools, for example:
6
6
 
7
- ##Instructions
7
+ - Building Cohort Data
8
+ - Building Student Data
8
9
 
9
- To include this gem add the below line to your projects gemfile:
10
+ Instead of instructors re-writing the same code in their projects, `CommonTools` gem can be required as a dependency in projects that need these common functionalities.
10
11
 
11
- ```
12
- gem 'instructor-tools-common-tools'
13
- ```
12
+ The Gem sends a request to Learn API endpoint of the given batch, parses string payload into a array of student hashes.
13
+
14
+ You will be asked for your github credentials the first time you run the gem. Your Github credentials is stored in a `client.yml`, which is in the gem's lib directory and git-ignored.
15
+
16
+
17
+ ##Using the gem in another project
18
+ Public-facing code is the `CommonTools` module.
19
+
20
+
21
+ #####For inclusion in a gem:
22
+
23
+ - add "common_tools" as a dependency in gemspec file
24
+
25
+
26
+ #####For inclusion in a Rails app:
27
+ - add `gem 'common_tools'` to project gemfile
28
+
29
+
30
+ ##Functionality
31
+ This gem contains several functions. Specific details are listed below:
32
+
33
+ - `batch_id` refers to the last 2 or more digits in the learn-url of a batch. For example: The url for Web-1115 is `https://learn.co/batches/168`. Therefore `batch-id` for Web-115 is 168
34
+
35
+ #### Two ways to run the gem:
36
+ - `bin/console`
37
+ - This drops you into an interactive irb session.
38
+ - The command `CommonTools::Generator.get_batch(batch_id)` return an array of student hashes. You can use this data to build your own student or batch objects
39
+
40
+
41
+ - `exe/common-tools batch_id`
42
+ - will return an array of student hashes
43
+ - receives batch-id as an argument and returns an array of student hashes.
44
+
45
+ ##Testing
46
+ Make sure all new features are built TDD first.
14
47
 
15
- ###Functionality
16
- This gem contains several functions see below for specific details
17
48
 
18
- * CSV to JSON Parser
19
- * `CommonTools.parse_csv('complete/path/to/file')`
20
- * This will parse your csv file into a JSON string
21
-
22
49
  ## Contributing
23
- To contribute to this gem:
50
+ To contribute to this gem:
24
51
 
25
52
  * Fork the [repo](https://github.com/flatiron-labs/instructor-tools-common-tools)
26
53
  * Make your contributions and set up whatever tests are necessary
27
54
  * Wrap any new functionality in `CommonTools` class methods
28
- * Submit a pull request
55
+ * Submit a pull request
data/bin/console CHANGED
File without changes
data/common_tools.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'common_tools/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "common_tools"
8
8
  spec.version = CommonTools::VERSION
9
- spec.authors = ["BenjaGross"]
10
- spec.email = ["ben@flatironschool.com"]
9
+ spec.authors = ["MsUzoAgu", "BenjaGross", "SophieDeBenedetto"]
10
+ spec.email = ["uzo@flatironschool.com", "ben@flatironschool.com", "sophie.debenedetto@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Common Tools and scripts for Flatiron School Instructors}
13
13
  spec.description = %q{Includes often used scripts to help Flatiron School instructors}
@@ -18,6 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.8"
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "mechanize"
23
28
  end
data/exe/common-tools ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ require_relative '../lib/common_tools'
5
+
6
+ if ARGV.length >=1
7
+ PP.pp CommonTools::Generator.get_batch(ARGV[0].to_i)
8
+ elsif ARGV.include?("--help")
9
+ CommonTools::Generator.new.help
10
+ else
11
+ puts "please use common_tools --help for a list of options"
12
+ end
@@ -0,0 +1,2 @@
1
+ class BatchGenerator
2
+ end
File without changes
@@ -0,0 +1,43 @@
1
+ class DataFetcher
2
+
3
+ attr_accessor :batch_id, :keys, :client
4
+
5
+ def initialize(batch_id=nil)
6
+ @batch_id = batch_id
7
+ end
8
+
9
+ def parse_roster
10
+ roster = get_roster
11
+ Parser.parse_roster(roster)
12
+ end
13
+
14
+
15
+ def get_roster
16
+ configure_keys
17
+ configure_credentials
18
+ @client.csv_for(self.batch_id)
19
+ end
20
+
21
+ private
22
+
23
+
24
+ def get_and_store_github_credentials
25
+ puts "Please enter your github username:"
26
+ username = STDIN.gets.chomp
27
+ puts "Please enter your github password:"
28
+ password = STDIN.gets.chomp
29
+ self.keys = {"GITHUB_USERNAME" => username, "GITHUB_PASSWORD" => password}
30
+ File.open(File.expand_path(File.dirname(__FILE__)) + '/credentials.yml', 'w') {|f| f.write self.keys.to_yaml }
31
+ end
32
+
33
+ def configure_keys
34
+ keys = YAML.load_file(File.expand_path(File.dirname(__FILE__)) + '/credentials.yml')
35
+ get_and_store_github_credentials unless keys
36
+ end
37
+
38
+ def configure_credentials
39
+ keys = YAML.load_file(File.expand_path(File.dirname(__FILE__)) + '/credentials.yml')
40
+ credentials = LearnProxy::Credentials.new(keys['GITHUB_USERNAME'], keys['GITHUB_PASSWORD'])
41
+ @client = LearnProxy::Client.new(credentials)
42
+ end
43
+ end
@@ -0,0 +1,64 @@
1
+ require 'pry'
2
+ require "mechanize"
3
+
4
+
5
+ module LearnProxy
6
+ class Client
7
+ CSV_URL = -> (batch_id) {"https://learn.co/batches/#{batch_id}/students.csv"}
8
+
9
+ def initialize(credentials)
10
+ @credentials = credentials
11
+ end
12
+
13
+ def csv_for(batch_id)
14
+ connection.get(CSV_URL[batch_id]).body
15
+ end
16
+
17
+ private
18
+ attr_reader :credentials
19
+
20
+ def connection
21
+ @connection ||= Connection.new(credentials)
22
+ end
23
+ end
24
+
25
+ class Connection
26
+ extend Forwardable
27
+ def_delegator :@session, :get
28
+
29
+ def initialize(credentials)
30
+ @credentials = credentials
31
+ connect!
32
+ end
33
+
34
+ private
35
+ attr_reader :credentials
36
+ def connect!
37
+ @session ||= begin
38
+ Mechanize.new.tap do |client|
39
+ client.get('https://learn.co/sign_in/github?sign_in=true')
40
+ form = client.page.form_with!(action: "/session")
41
+ GithubForm.submit(form, credentials)
42
+ client.page.link_with!(href: /learn\.co/).click
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ module GithubForm
49
+ def self.submit(form, credentials)
50
+ form['login'] = credentials.username
51
+ form['password'] = credentials.password
52
+ form.submit
53
+ end
54
+ end
55
+
56
+ class Credentials
57
+ attr_accessor :username, :password
58
+ def initialize(username, password)
59
+ @username = username
60
+ @password = password
61
+ end
62
+ end
63
+ end
64
+
@@ -1,19 +1,20 @@
1
- require 'csv'
2
- require 'json'
3
- require 'pry'
4
- require_relative 'student'
5
-
6
1
  class Parser
7
2
 
8
- def self.build_batch(file)
9
- headers = CSV.read(file, headers: true).headers
10
- Student.build_attributes(headers)
11
- CSV.foreach(file, headers: true).map do |row|
12
- make_student_attributes(row) unless row[0] == "first_name" || row[0].nil?
13
- end.to_json
3
+ def self.build_attributes(roster)
4
+ attributes_string = roster.split(/\n/).reject(&:empty?).delete_at(0)
5
+ attributes_array = attributes_string.split(/\n/).first.split(',').collect {|attribute| attribute.to_sym}
14
6
  end
15
7
 
16
- def self.make_student_attributes(row)
17
- Student.new(row.to_h)
8
+ def self.parse_roster(roster)
9
+ attributes_array = build_attributes(roster)
10
+ student_strings = roster.split(/\n/).reject(&:empty?).drop(1)
11
+ array_of_student_hashes = []
12
+
13
+ array_of_students = student_strings.collect { |student_string| student_string.split(',') }
14
+
15
+ array_of_students.each_with_object(attributes_array) do |student_array, attribute_hash|
16
+ array_of_student_hashes << [attribute_hash, student_array].transpose.to_h
17
+ end
18
+ array_of_student_hashes
18
19
  end
19
20
  end
@@ -1,3 +1,3 @@
1
- class CommonTools
2
- VERSION = "0.1.1"
1
+ module CommonTools
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/common_tools.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require_relative "common_tools/version"
2
- require_relative "common_tools/say_hello"
2
+ require_relative "common_tools/learn_proxy"
3
+ require_relative "common_tools/batch_generator"
4
+ require_relative "common_tools/data_fetcher"
3
5
  require_relative "common_tools/parser"
4
6
 
7
+ module CommonTools
5
8
 
6
- class CommonTools
7
- extend SayHello
8
-
9
- def self.parse_csv(csv_file)
10
- Parser.build_batch(csv_file)
9
+ class Generator
10
+ def self.get_batch(batch_id)
11
+ batch= DataFetcher.new(batch_id).get_roster
12
+ Parser.parse_roster(batch)
13
+ end
11
14
  end
12
-
13
15
  end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: common_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
+ - MsUzoAgu
7
8
  - BenjaGross
9
+ - SophieDeBenedetto
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
13
+ date: 2016-03-22 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: bundler
@@ -16,14 +18,14 @@ dependencies:
16
18
  requirements:
17
19
  - - "~>"
18
20
  - !ruby/object:Gem::Version
19
- version: '1.8'
21
+ version: '1.11'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - "~>"
25
27
  - !ruby/object:Gem::Version
26
- version: '1.8'
28
+ version: '1.11'
27
29
  - !ruby/object:Gem::Dependency
28
30
  name: rake
29
31
  requirement: !ruby/object:Gem::Requirement
@@ -38,10 +40,83 @@ dependencies:
38
40
  - - "~>"
39
41
  - !ruby/object:Gem::Version
40
42
  version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: pry
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: webmock
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: vcr
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: mechanize
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
41
113
  description: Includes often used scripts to help Flatiron School instructors
42
114
  email:
115
+ - uzo@flatironschool.com
43
116
  - ben@flatironschool.com
44
- executables: []
117
+ - sophie.debenedetto@gmail.com
118
+ executables:
119
+ - common-tools
45
120
  extensions: []
46
121
  extra_rdoc_files: []
47
122
  files:
@@ -54,10 +129,13 @@ files:
54
129
  - bin/console
55
130
  - bin/setup
56
131
  - common_tools.gemspec
132
+ - exe/common-tools
57
133
  - lib/common_tools.rb
134
+ - lib/common_tools/batch_generator.rb
135
+ - lib/common_tools/credentials.yml
136
+ - lib/common_tools/data_fetcher.rb
137
+ - lib/common_tools/learn_proxy.rb
58
138
  - lib/common_tools/parser.rb
59
- - lib/common_tools/say_hello.rb
60
- - lib/common_tools/student.rb
61
139
  - lib/common_tools/version.rb
62
140
  homepage: https://github.com/flatiron-labs/instructor-tools-common-tools
63
141
  licenses: []
@@ -78,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
156
  version: '0'
79
157
  requirements: []
80
158
  rubyforge_project:
81
- rubygems_version: 2.4.6
159
+ rubygems_version: 2.4.8
82
160
  signing_key:
83
161
  specification_version: 4
84
162
  summary: Common Tools and scripts for Flatiron School Instructors
@@ -1,7 +0,0 @@
1
- module SayHello
2
-
3
- def say_hello(name)
4
- "Hello #{name}"
5
- end
6
-
7
- end
@@ -1,22 +0,0 @@
1
- require 'json'
2
- class Student
3
-
4
- def initialize(args)
5
- args.each do |key, value|
6
- self.public_send("#{key}=", value )
7
- end
8
- end
9
-
10
- def self.build_attributes(headers)
11
- headers.each do |header|
12
- attr_accessor header.to_sym
13
- end
14
- end
15
-
16
- def to_json(args)
17
- hash = {}
18
- self.instance_variables.each{ |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
19
- hash.to_json
20
- end
21
-
22
- end