learn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/bin/learn +4 -0
- data/learn.gemspec +22 -0
- data/lib/learn.rb +20 -0
- data/lib/learn/cli.rb +32 -0
- data/lib/learn/exercise.rb +25 -0
- data/lib/learn/student.rb +18 -0
- data/lib/learn/version.rb +3 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 lfborjas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Learn
|
2
|
+
|
3
|
+
A gem to take an interactive (CLI) course based on challenges
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'learn'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install learn
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
1. Subscribe to the course you're gonna take by writing `learn <course>`
|
22
|
+
2. You will receive your first task in the output
|
23
|
+
3. When you complete your task, submit it by writing `learn <course> <response>`
|
24
|
+
4. If the task is accepted, you'll get the next task
|
25
|
+
5. If there are no more tasks, you'll get a "CHALLENGE COMPLETED!" output
|
26
|
+
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/learn
ADDED
data/learn.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/learn/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["lfborjas"]
|
6
|
+
gem.email = ["luisfborjas@gmail.com"]
|
7
|
+
gem.description = %q{A gem for learning ruby and http}
|
8
|
+
gem.summary = %q{Companion gem for the progra4/teach site}
|
9
|
+
gem.homepage = "http://aprenderuby.heroku.com"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "learn"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Learn::VERSION
|
17
|
+
gem.add_dependency("rest-client", "~> 1.6.7")
|
18
|
+
gem.add_dependency("thor", "~> 0.14.6")
|
19
|
+
gem.add_dependency("json", "~> 1.6.5")
|
20
|
+
gem.add_dependency("term-ansicolor", "~> 1.0.7")
|
21
|
+
gem.required_ruby_version = ">= 1.9.2"
|
22
|
+
end
|
data/lib/learn.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "learn/version"
|
2
|
+
require 'learn/student'
|
3
|
+
require 'learn/exercise'
|
4
|
+
require 'learn/cli'
|
5
|
+
|
6
|
+
module Learn
|
7
|
+
HOST = "http://aprenderuby.herokuapp.com"
|
8
|
+
SETTINGS_PATH = "#{Dir.home}/.learn"
|
9
|
+
|
10
|
+
def self.write_settings(settings_hash)
|
11
|
+
File.open(Learn::SETTINGS_PATH, 'w') do |f|
|
12
|
+
f.write(settings_hash)
|
13
|
+
end
|
14
|
+
settings_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.read_settings
|
18
|
+
settings = JSON.parse File.read(Learn::SETTINGS_PATH)
|
19
|
+
end
|
20
|
+
end
|
data/lib/learn/cli.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'term/ansicolor'
|
3
|
+
|
4
|
+
module Learn
|
5
|
+
class CLI
|
6
|
+
extend Term::ANSIColor
|
7
|
+
def self.start
|
8
|
+
filename = ARGV.pop
|
9
|
+
|
10
|
+
#if the file doesn't exist, create it
|
11
|
+
unless File.exists?(Learn::SETTINGS_PATH)
|
12
|
+
print green, "Hi! It's time to register, this should only happen once!",reset
|
13
|
+
print "\nAccount Number: "
|
14
|
+
|
15
|
+
|
16
|
+
account_number= gets.chomp
|
17
|
+
if Learn::Student.register(account_number)
|
18
|
+
print green, "Done, you're registered as a student", reset, "\n"
|
19
|
+
else
|
20
|
+
print red, "Couldn't register, check your internet collection and try again", reset, "\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if filename and File.exists?("./#{filename}")
|
25
|
+
contents = File.read("./#{filename}")
|
26
|
+
Learn::Exercise.submit(filename, contents)
|
27
|
+
else
|
28
|
+
print red, "Usage: learn ex<exercise_number>.rb", reset, "\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'term/ansicolor'
|
4
|
+
|
5
|
+
module Learn
|
6
|
+
class Exercise
|
7
|
+
extend Term::ANSIColor
|
8
|
+
|
9
|
+
def self.submit(name, contents)
|
10
|
+
settings = Learn.read_settings
|
11
|
+
begin
|
12
|
+
legal_name = name.match(/ex(?<order>\d+)/)
|
13
|
+
if legal_name
|
14
|
+
response = RestClient.post(
|
15
|
+
"#{Learn::HOST}/students/#{settings["account_number"].chomp}/exercises.json",
|
16
|
+
{exercise: {name: name, contents: contents, ordering: legal_name[:order]}})
|
17
|
+
print green, "Exercise #{legal_name[:order]} submitted successfully", reset, "\n"
|
18
|
+
end
|
19
|
+
rescue Exception => e
|
20
|
+
puts e
|
21
|
+
print red, "Exercise could not be submitted :(", reset, "\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
module Learn
|
4
|
+
class Student
|
5
|
+
def self.register(account_number)
|
6
|
+
begin
|
7
|
+
response = RestClient.post(
|
8
|
+
"#{Learn::HOST}/students",
|
9
|
+
JSON.dump(student: {account_number: account_number}),
|
10
|
+
content_type: :json
|
11
|
+
)
|
12
|
+
Learn.write_settings(response)
|
13
|
+
rescue Exception => e
|
14
|
+
puts "Couldn't register because of #{e}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: learn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- lfborjas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: thor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.14.6
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.14.6
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.6.5
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.5
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: term-ansicolor
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.7
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.7
|
78
|
+
description: A gem for learning ruby and http
|
79
|
+
email:
|
80
|
+
- luisfborjas@gmail.com
|
81
|
+
executables:
|
82
|
+
- learn
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/learn
|
92
|
+
- learn.gemspec
|
93
|
+
- lib/learn.rb
|
94
|
+
- lib/learn/cli.rb
|
95
|
+
- lib/learn/exercise.rb
|
96
|
+
- lib/learn/student.rb
|
97
|
+
- lib/learn/version.rb
|
98
|
+
homepage: http://aprenderuby.heroku.com
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.9.2
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.21
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Companion gem for the progra4/teach site
|
122
|
+
test_files: []
|