hexlet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35f9300008b67722d0c2c50a6c3de958afdb90e6
4
+ data.tar.gz: dbbdf2bde4cc1af0e81cee92ed9be98e094e4258
5
+ SHA512:
6
+ metadata.gz: 0676c89c279310423c087f8f91c9bc449e7f6a2c7f9f275f82b6b89c9fc43794a4a3089eb29052bf093b012d3632939d3e02b39dfba5673648a9372d6fe5c388
7
+ data.tar.gz: 59039612d7a7299e508f21b244c318a1398489a72818f92786371498b2d2633193582d4eaae6f32fec0e746ff8b043085eef55e8732c09c178636467a712f007
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.swo
16
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hexlet.gemspec
4
+ gemspec
5
+
6
+ gem 'minitest'
7
+ gem 'wrong'
8
+ gem 'webmock'
9
+ gem 'mocha'
10
+
11
+ gem 'fakefs', require: "fakefs/safe"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kirill Mokevnin
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,33 @@
1
+ [![Build Status](https://travis-ci.org/Hexlet/hexlet.svg?branch=master)](https://travis-ci.org/Hexlet/hexlet)
2
+
3
+ # Hexlet
4
+
5
+ TODO: Write a gem description
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hexlet'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hexlet
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/hexlet/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/hexlet/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
12
+
data/bin/hexlet ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'hexlet'
5
+
6
+ # raise ARGV.inspect
7
+ Hexlet::MemberCLI.start
data/bin/hexlet-lesson ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'hexlet'
5
+
6
+ # raise ARGV.inspect
7
+ Hexlet::TeacherCLI.start
data/hexlet.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hexlet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hexlet"
8
+ spec.version = Hexlet::VERSION
9
+ spec.authors = ["Kirill Mokevnin"]
10
+ spec.email = ["mokevnin@gmail.com"]
11
+ spec.summary = %q{hexlet cli}
12
+ spec.description = %q{hexlet cli}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "thor"
25
+ spec.add_dependency "rest_client"
26
+ spec.add_dependency "i18n"
27
+ spec.add_dependency "minitar"
28
+ end
data/lib/hexlet.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "hexlet/version"
2
+
3
+ require 'logger'
4
+ require 'yaml'
5
+ require 'fileutils'
6
+ require 'uri'
7
+ require 'zlib'
8
+
9
+ require 'archive/tar/minitar'
10
+ require 'rake'
11
+ require 'thor'
12
+ require 'rest-client'
13
+ require 'i18n'
14
+
15
+ I18n.available_locales = [:en]
16
+ I18n.enforce_available_locales = true
17
+ I18n.locale = :en
18
+
19
+ I18n.load_path = Dir['locales/*.yml']
20
+ I18n.backend.load_translations
21
+ I18n.t "key" # FIXME this is hack
22
+
23
+ module Hexlet
24
+ autoload "Router", "hexlet/router"
25
+
26
+ autoload "BaseClient", "hexlet/base_client"
27
+ autoload "TeacherClient", "hexlet/teacher_client"
28
+ autoload "MemberClient", "hexlet/member_client"
29
+
30
+ autoload "BaseCLI", "hexlet/base_cli"
31
+ autoload "MemberCLI", "hexlet/member_cli"
32
+ autoload "TeacherCLI", "hexlet/teacher_cli"
33
+
34
+ # Your code goes here...
35
+ end
@@ -0,0 +1,52 @@
1
+ module Hexlet
2
+ class BaseCLI < Thor
3
+ include Thor::Actions
4
+
5
+ CONFIG_DIR = File.join(Dir.home, ".hexlet")
6
+ CREDENTIALS_FILE = File.join(Dir.home, ".hexlet", "credentials")
7
+
8
+ class_option :verbose, type: :boolean
9
+ class_option :host, type: :string, default: "http://hexlet.io"
10
+
11
+ desc "login HEXLET_API_KEY", "login on hexlet.io"
12
+ def login(key)
13
+ client = BaseClient.new key, logger: logger
14
+ if client.login
15
+ puts (t :ok)
16
+ write_config("hexlet_api_key" => key)
17
+ else
18
+ puts (t :not_found)
19
+ end
20
+ end
21
+
22
+ no_commands do
23
+ def logger
24
+ logger = Logger.new(STDOUT)
25
+ logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
26
+ logger
27
+ end
28
+
29
+ def t key
30
+ command_name = @_invocations.values.last.last
31
+ ns = self.class.to_s.downcase.split("::").last
32
+ I18n.t key, scope: [ns, command_name]
33
+ end
34
+
35
+ def config
36
+ if File.file?(CREDENTIALS_FILE)
37
+ YAML.load_file(CREDENTIALS_FILE)
38
+ else
39
+ {}
40
+ end
41
+ end
42
+
43
+ def write_config(data)
44
+ FileUtils.mkdir_p(CONFIG_DIR)
45
+ File.open(CREDENTIALS_FILE, 'w') do |f|
46
+ f.write data.to_yaml
47
+ end
48
+ # TODO puts (I18n.t "update_config")
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ module Hexlet
2
+ class BaseClient
3
+ def initialize(key, options={})
4
+ @key = key
5
+ @host = options[:host] || "http://hexlet.io"
6
+ @logger = options[:logger]
7
+ @router = Router.new @host
8
+ end
9
+
10
+ def login
11
+ url = @router.api_member_user_check_url
12
+ @logger.debug url
13
+
14
+ RestClient.get url, headers do |response, request, result, &block|
15
+ @logger.debug response
16
+ 200 == response.code
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def headers(other = {})
23
+ {"X-Hexlet-Api-Key" => @key}.merge other
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module Hexlet
2
+ class MemberCLI < BaseCLI
3
+ # fetch
4
+ # submit
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Hexlet
2
+ class MemberClient < BaseClient
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module Hexlet
2
+ # FIXME add uri parser
3
+ class Router
4
+ def initialize(host = "http://hexlet.io")
5
+ @host = host
6
+ end
7
+
8
+ def api_teacher_lessons_url
9
+ generate("api_teacher/lessons")
10
+ end
11
+
12
+ def api_member_user_check_url
13
+ generate("api_member/user/check_auth")
14
+ end
15
+
16
+ private
17
+
18
+ def generate(url)
19
+ URI("#{@host}/#{url}.json").to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,65 @@
1
+ module Hexlet
2
+ class TeacherCLI < BaseCLI
3
+ desc "submit PATH_TO_LESSON", "login on hexlet.io"
4
+ def submit(path)
5
+ lesson_folder = File.split(path)[1]
6
+ parts = lesson_folder.split("_")
7
+
8
+ if parts.last != "lesson"
9
+ puts (t "wrong_lesson_folder")
10
+ return false
11
+ end
12
+
13
+ slug = parts[0, parts.size - 2].join("_")
14
+ locale = parts[-2]
15
+
16
+ filepath = generate_lesson_tarball(path)
17
+
18
+ result = client.submit slug, locale, filepath
19
+
20
+ if result
21
+ puts (t :created)
22
+ true
23
+ else
24
+ puts (t :error)
25
+ false
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def generate_lesson_tarball(path)
32
+ dist_path = File.join(path, "dist")
33
+ exercise_tarball_path = File.join(dist_path, "exercise.tar.gz")
34
+
35
+ FileUtils.mkdir_p(dist_path)
36
+
37
+ File.open(exercise_tarball_path, 'wb') do |fd|
38
+ sgz = Zlib::GzipWriter.new(fd)
39
+
40
+ Archive::Tar::Minitar::Output.open(sgz) do |stream|
41
+ FileUtils.cd path do
42
+ files = Rake::FileList.new("**/*") do |f|
43
+ f.exclude /node_modules/
44
+ f.exclude /bower_components/
45
+ f.exclude /dist/
46
+ f.exclude ".git"
47
+ end
48
+
49
+ # raise files.inspect
50
+ files.each do |entry|
51
+ Archive::Tar::Minitar.pack_file(entry, stream)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ exercise_tarball_path
58
+ end
59
+
60
+ def client
61
+ @client ||= Hexlet::TeacherClient.new config["hexlet_api_key"], logger: logger, host: options["host"]
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,25 @@
1
+ module Hexlet
2
+ class TeacherClient < BaseClient
3
+ def submit(slug, locale, file)
4
+ url = @router.api_teacher_lessons_url
5
+ @logger.debug url
6
+
7
+ fd = ENV["TEST"] ? "a" : File.new(file, "rb") # FIXME
8
+
9
+ attrs = {
10
+ lesson: {
11
+ slug: slug,
12
+ locale: locale,
13
+ "packs_attributes[]" => [
14
+ {tarball: fd}
15
+ ]
16
+ }
17
+ }
18
+
19
+ RestClient.post url, attrs, headers do |response, request, result, &block|
20
+ @logger.debug response
21
+ 201 == response.code
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Hexlet
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ en:
2
+ membercli:
3
+ login:
4
+ ok: login has been succesfull
5
+ not_found: User has not been found
@@ -0,0 +1,5 @@
1
+ en:
2
+ teachercli:
3
+ submit:
4
+ created: lesson has been uploaded
5
+ wrong_lesson_folder: Wrong lesson folder
data/locales/en.yml ADDED
@@ -0,0 +1,2 @@
1
+ en:
2
+ update_config: Config has been updated
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class Hexlet::MemberCLITest < MiniTest::Test
4
+ def setup
5
+ @router = Hexlet::Router.new
6
+ end
7
+
8
+ def test_login
9
+ api_key = "api_key"
10
+ config_file = File.join(Dir.home, ".hexlet", "credentials")
11
+
12
+ stub = stub_request(:get, @router.api_member_user_check_url).
13
+ to_return(:status => 200)
14
+
15
+ FakeFS do
16
+ result = Hexlet::MemberCLI.start ["login", api_key, "--verbose"]
17
+ assert { result }
18
+ assert { File.file?(config_file) }
19
+ end
20
+
21
+ assert_requested stub
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class Hexlet::TeacherCLITest < MiniTest::Test
4
+ def setup
5
+ @router = Hexlet::Router.new
6
+ end
7
+
8
+ def test_submit
9
+ stub = stub_request(:post, @router.api_teacher_lessons_url).
10
+ to_return(:status => 201)
11
+
12
+ FakeFS do
13
+ folder = "my_super_ru_lesson"
14
+ FileUtils.mkdir(folder)
15
+ result = Hexlet::TeacherCLI.start ["submit", folder, "--verbose"]
16
+ assert { result }
17
+ end
18
+
19
+ assert_requested stub
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ ENV["TEST"] = "true"
2
+
3
+ require 'bundler/setup'
4
+ Bundler.require
5
+
6
+ require 'minitest/unit'
7
+ require 'mocha/mini_test'
8
+
9
+ require 'webmock/minitest'
10
+
11
+ Wrong.config.color
12
+
13
+ class Minitest::Test
14
+ include Wrong
15
+ end
16
+
17
+ Minitest.autorun
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hexlet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Mokevnin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
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: rest_client
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
+ - !ruby/object:Gem::Dependency
70
+ name: i18n
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitar
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: hexlet cli
98
+ email:
99
+ - mokevnin@gmail.com
100
+ executables:
101
+ - hexlet
102
+ - hexlet-lesson
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/hexlet
113
+ - bin/hexlet-lesson
114
+ - hexlet.gemspec
115
+ - lib/hexlet.rb
116
+ - lib/hexlet/base_cli.rb
117
+ - lib/hexlet/base_client.rb
118
+ - lib/hexlet/member_cli.rb
119
+ - lib/hexlet/member_client.rb
120
+ - lib/hexlet/router.rb
121
+ - lib/hexlet/teacher_cli.rb
122
+ - lib/hexlet/teacher_client.rb
123
+ - lib/hexlet/version.rb
124
+ - locales/en.membercli.yml
125
+ - locales/en.teachercli.yml
126
+ - locales/en.yml
127
+ - test/hexlet/member_cli_test.rb
128
+ - test/hexlet/teacher_cli_test.rb
129
+ - test/test_helper.rb
130
+ homepage: ''
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.2.2
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: hexlet cli
154
+ test_files:
155
+ - test/hexlet/member_cli_test.rb
156
+ - test/hexlet/teacher_cli_test.rb
157
+ - test/test_helper.rb