comet 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/comet +44 -17
  3. data/lib/comet/version.rb +1 -1
  4. data/lib/helpers.rb +13 -0
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7891c00e84fa9da8333fa05249a587dab2a737a
4
- data.tar.gz: ab3c3d48574ff2cdfc4c33ea4eaca39e53e20100
3
+ metadata.gz: 26089d2f3a83ac8aa43a80a85d8be0b61f731b4e
4
+ data.tar.gz: dfa7564ca9f58ac5dc9550443178d889c705ee4b
5
5
  SHA512:
6
- metadata.gz: 581330f97cbc0aae71682861aa0ae79feaafeea32c186c101eecc9db6551917c9bc96bb04a230530d0c3b60552f0f0822ec845693c79b14470d26b1c6533de4e
7
- data.tar.gz: b1538d7dfdecda2facdb8791a1b8082edfd05310661e23533faef0a95110b4c66c7a71ce1fc70bee6ea34778394959ec9de64fd54a3ae93307d377bc594906e3
6
+ metadata.gz: e58c8ce43ac20e2d7ef34c7381e8f0e4b36dc9ee5db18604273ea76047dc19ec9074b47202a3e05d8e2b494c88f11475ef1ba19f003a39197f8592fba69a105a
7
+ data.tar.gz: 659f2e219fd4bd5b3c1022e6fbb3fcf9094dfedfab2e39ab92abcc48e829c137cac63abdbf1b61475e14edb1240118abe5c41ffd566516245f12a85bf1cae856
data/bin/comet CHANGED
@@ -32,9 +32,16 @@ command :list do |c|
32
32
  if challenges.empty?
33
33
  puts "No challenges available."
34
34
  else
35
- challenges.each do |challenge|
36
- printf("\e[33m%4d\e[0m) \e[32m%s\e[0m: %s\n",
37
- challenge[:id], challenge[:topic], challenge[:name])
35
+ sorted_challenges = challenges.sort_by do |challenge|
36
+ [challenge[:topic_name], challenge[:difficulty]]
37
+ end
38
+
39
+ sorted_challenges.each do |challenge|
40
+ printf("(%4d) \e[34m%s\e[0m: %s (%s)\n",
41
+ challenge[:id],
42
+ challenge[:topic_name],
43
+ challenge[:name],
44
+ difficulty_to_string(challenge[:difficulty]))
38
45
  end
39
46
  end
40
47
  end
@@ -50,28 +57,48 @@ command :fetch do |c|
50
57
  info = { 'id' => challenge_id.to_i, 'file_name' => "#{challenge.slug}.rb" }
51
58
  info_file = File.join(directory, '.challenge')
52
59
  File.write(info_file, info.to_yaml)
60
+
61
+ puts "Downloaded challenge to #{directory}."
53
62
  end
54
63
  end
55
64
 
56
65
  desc 'Submit challenge'
57
66
  command :submit do |c|
58
67
  c.action do |global_options, options, args|
59
- info_file = File.join(Dir.pwd, '.challenge')
60
-
61
- if File.exists?(info_file)
62
- info = YAML.load(File.read(info_file))
63
-
64
- challenge_id = info['id']
65
- solution_file = File.join(Dir.pwd, info['file_name'])
66
-
67
- if File.exists?(solution_file)
68
- Comet::API.submit(@config, challenge_id, solution_file)
69
- else
70
- puts "Missing solution file (#{solution_file})."
71
- exit 1
68
+ require 'rest_client'
69
+ require 'tmpdir'
70
+
71
+ current_dir = Dir.pwd
72
+ challenge_file = File.join(current_dir, '.challenge')
73
+
74
+ if File.exists?(challenge_file)
75
+ challenge_info = YAML.load(File.read(challenge_file))
76
+ lib_dir = File.join(current_dir, 'lib')
77
+ slug = File.basename(current_dir)
78
+
79
+ Dir.mktmpdir do |tmpdir|
80
+ submission_file = File.join(tmpdir, 'submission.tar.gz')
81
+ if system("tar zcf #{submission_file} -C #{lib_dir} .")
82
+ payload = {
83
+ submission: {
84
+ challenge_id: challenge_info['id'],
85
+ archive: File.new(submission_file)
86
+ }
87
+ }
88
+
89
+ headers = { 'Authorization' => "Token #{@config['token']}" }
90
+
91
+ RestClient.post("#{@config['server']}/api/v1/submissions.json", payload, headers)
92
+
93
+ puts "Submitted solution for #{slug}."
94
+ else
95
+ puts "Unable to create submission archive."
96
+ exit 1
97
+ end
72
98
  end
99
+
73
100
  else
74
- puts "This is not a challenge directory."
101
+ puts "Not a challenge directory."
75
102
  exit 1
76
103
  end
77
104
  end
data/lib/comet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Comet
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/helpers.rb CHANGED
@@ -13,3 +13,16 @@ def prompt_for_setting(name, existing_settings)
13
13
  existing_settings[name]
14
14
  end
15
15
  end
16
+
17
+ def difficulty_to_string(difficult_rating)
18
+ case difficult_rating
19
+ when 1
20
+ "\e[32measy\e[0m"
21
+ when 2
22
+ "\e[33mintermediate\e[0m"
23
+ when 3
24
+ "\e[31mhard\e[0m"
25
+ else
26
+ ""
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Sheehan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
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'
69
83
  description:
70
84
  email: adam.sheehan@launchacademy.com
71
85
  executables: