comet 0.0.2 → 0.0.3

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: 311404210d27d916830617aa2b22cec4ffc8b4d5
4
- data.tar.gz: f4e135e0cde0a242b802a088e643eaa50a4f4ca7
3
+ metadata.gz: a7891c00e84fa9da8333fa05249a587dab2a737a
4
+ data.tar.gz: ab3c3d48574ff2cdfc4c33ea4eaca39e53e20100
5
5
  SHA512:
6
- metadata.gz: 554afd290442793b4525442a4e2a621d2b52bc20e59c1f65751e3beff5a6911b8352e2f35df917e488786cfc21f28d5636f46f02d19c313bac1b0c39658d7bbe
7
- data.tar.gz: 878b45b3e72b9b2f4cb0f7b271ab3df86c9aaa6e34a997e243f00184ed880aa00f285aa3c615530c6c4521156f8d50968326d54aedf40ed25a788dd2001f20c3
6
+ metadata.gz: 581330f97cbc0aae71682861aa0ae79feaafeea32c186c101eecc9db6551917c9bc96bb04a230530d0c3b60552f0f0822ec845693c79b14470d26b1c6533de4e
7
+ data.tar.gz: b1538d7dfdecda2facdb8791a1b8082edfd05310661e23533faef0a95110b4c66c7a71ce1fc70bee6ea34778394959ec9de64fd54a3ae93307d377bc594906e3
data/bin/comet CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'gli'
3
3
  require 'yaml'
4
4
  require 'comet'
5
+ require 'helpers'
5
6
 
6
7
  include GLI::App
7
8
 
@@ -13,16 +14,11 @@ desc 'Initialize the current directory as a comet project directory'
13
14
  skips_pre
14
15
  command :init do |c|
15
16
  c.action do |global_options, options, args|
16
- answers = {}
17
+ answers = Comet::Init.find_config(Dir.pwd) || {}
17
18
 
18
- print 'E-mail: '
19
- answers['email'] = gets.chomp
20
-
21
- print 'Token: '
22
- answers['token'] = gets.chomp
23
-
24
- print 'Server: '
25
- answers['server'] = gets.chomp
19
+ ['email', 'token', 'server'].each do |setting|
20
+ answers[setting] = prompt_for_setting(setting, answers)
21
+ end
26
22
 
27
23
  Comet::Init.init_project_dir(Dir.pwd, answers)
28
24
  end
@@ -37,7 +33,8 @@ command :list do |c|
37
33
  puts "No challenges available."
38
34
  else
39
35
  challenges.each do |challenge|
40
- puts "#{challenge[:id]}: #{challenge[:name]}"
36
+ printf("\e[33m%4d\e[0m) \e[32m%s\e[0m: %s\n",
37
+ challenge[:id], challenge[:topic], challenge[:name])
41
38
  end
42
39
  end
43
40
  end
@@ -94,7 +91,7 @@ end
94
91
  on_error do |exception|
95
92
  # Error logic here
96
93
  # return false to skip default error handling
97
- true
94
+ raise exception
98
95
  end
99
96
 
100
97
  exit run(ARGV)
data/lib/comet/api.rb CHANGED
@@ -4,7 +4,7 @@ require 'json'
4
4
  module Comet
5
5
  class API
6
6
  def self.get_challenges(config)
7
- response = request_with_token("http://#{config['server']}/api/v1/challenges.json",
7
+ response = request_with_token("#{config['server']}/api/v1/challenges.json",
8
8
  config['token'])
9
9
 
10
10
  results = JSON.parse(response.body, symbolize_names: true)
@@ -12,7 +12,7 @@ module Comet
12
12
  end
13
13
 
14
14
  def self.get_challenge(config, id)
15
- response = request_with_token("http://#{config['server']}/api/v1/challenges/#{id}.json",
15
+ response = request_with_token("#{config['server']}/api/v1/challenges/#{id}.json",
16
16
  config['token'])
17
17
 
18
18
  if response.code == '200'
@@ -40,7 +40,7 @@ module Comet
40
40
  end
41
41
 
42
42
  def self.submit(config, challenge_id, file_path)
43
- uri = URI("http://#{config['server']}/api/v1/submissions.json")
43
+ uri = URI("#{config['server']}/api/v1/submissions.json")
44
44
  req = Net::HTTP::Post.new(uri)
45
45
 
46
46
  file_name = File.basename(file_path)
@@ -64,7 +64,7 @@ module Comet
64
64
  def self.request_with_token(url, token)
65
65
  uri = URI(url)
66
66
 
67
- request = Net::HTTP::Get.new(uri)
67
+ request = Net::HTTP::Get.new(uri.request_uri)
68
68
  request['Authorization'] = "Token #{token}"
69
69
  response = Net::HTTP.start(uri.hostname, uri.port) do |http|
70
70
  http.request(request)
data/lib/comet/init.rb CHANGED
@@ -23,20 +23,27 @@ module Comet
23
23
  def init_project_dir(dirname, user_answers)
24
24
  config_file = File.join(dirname, '.comet')
25
25
 
26
- unless File.exists?(config_file)
27
- config = {
28
- 'email' => user_answers['email'],
29
- 'token' => user_answers['token'],
30
- 'server' => user_answers['server']
31
- }
32
-
33
- File.write(config_file, config.to_yaml)
26
+ if File.exists?(config_file)
27
+ existing_settings = YAML.load(File.read(config_file))
28
+ else
29
+ existing_settings = {}
34
30
  end
31
+
32
+ settings = existing_settings.merge(user_answers)
33
+ settings['server'] = normalize_url(settings['server']) if settings['server']
34
+
35
+ File.write(config_file, settings.to_yaml)
35
36
  end
36
37
 
37
38
  private
38
39
 
39
-
40
+ def normalize_url(input)
41
+ unless input.include?('://')
42
+ 'http://' + input
43
+ else
44
+ input
45
+ end
46
+ end
40
47
  end
41
48
  end
42
49
  end
data/lib/comet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Comet
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/helpers.rb ADDED
@@ -0,0 +1,15 @@
1
+ def prompt_for_setting(name, existing_settings)
2
+ if existing_settings.has_key?(name)
3
+ print "#{name.capitalize} (#{existing_settings[name]}): "
4
+ else
5
+ print "#{name.capitalize}: "
6
+ end
7
+
8
+ input = gets.chomp.strip
9
+
10
+ if !input.empty?
11
+ input
12
+ else
13
+ existing_settings[name]
14
+ end
15
+ 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.2
4
+ version: 0.0.3
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-11 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -81,6 +81,7 @@ files:
81
81
  - lib/comet/challenge.rb
82
82
  - lib/comet/init.rb
83
83
  - lib/comet/version.rb
84
+ - lib/helpers.rb
84
85
  - README.rdoc
85
86
  - comet.rdoc
86
87
  homepage: http://www.launchacademy.com