rubysteps 0.0.1 → 0.0.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: 2fd7c82511f0cd8b372bcc42ec36930c7f723255
4
- data.tar.gz: 56b0ed9d20e3413ee81cd65eddf07adc382ac960
3
+ metadata.gz: ef0c442b1b016da89b99cc194a1bee2783c47fa3
4
+ data.tar.gz: 4cd7da4daee30c65165bec4aee14c735a70577dc
5
5
  SHA512:
6
- metadata.gz: d7d0e3d6c7ede71dcdc8edbdaacd1b15978a215d53c84cceee049d7be252d75432a9362fde3b16c07dd7d3d52d4d1ff37d369f24e266fdf3d8485dc857b571b6
7
- data.tar.gz: 41f4dce36cdb3a843530b07bcda3b25cac7c441ac3c89edcc8bc95466714bd9c1e76477a1e9174a2d13a041f0dce4f46dca095b35163d86af2150ca3114df159
6
+ metadata.gz: af1987ff386ff27e6154119759ab8fae99a20549267de09c160503198b7757615d5ce295c053b86e64740b3571652fdede2fb29c47313c171b5846649d5529fd
7
+ data.tar.gz: 2b8f74fd7a13f330742765f9a202e1b582642cb8fa7e755b2c4acddd7b8c7983dd5282f308ceda71c1262a51903e1f0530b7a03b8e740806e5920d22312bc229
data/bin/rubysteps CHANGED
@@ -2,21 +2,24 @@
2
2
  require 'thor'
3
3
  require 'active_rest_client'
4
4
 
5
- filename = File.expand_path('~/.rubysteps-login')
6
- unless File.exist?(filename)
7
- $stderr.puts "Missing ~/.rubysteps-login - please contact pat for your credentials"
8
- exit 1
5
+ RUBYSTEPS_FILENAME = File.expand_path('~/.rubysteps-login')
6
+ RUBYSTEPS_FILENAME << "-dev" if ENV['dev']
7
+ if File.exist?(RUBYSTEPS_FILENAME)
8
+ USERNAME, TOKEN = File.read(RUBYSTEPS_FILENAME).strip.split(":")
9
+ else
10
+ USERNAME, TOKEN = 'ignore', 'for_real'
11
+ $stderr.puts "Missing ~/.rubysteps-login"
12
+ $stderr.puts "`rubysteps register` is the only command which will work"
13
+ $stderr.puts "Please contact pat for your credentials"
9
14
  end
10
15
 
11
- USERNAME, TOKEN = File.read(filename).strip.split(":")
16
+ ActiveRestClient::Base.base_url = if ENV['dev']
17
+ "http://#{USERNAME}:#{TOKEN}@localhost:3000/"
18
+ else
19
+ "https://#{USERNAME}:#{TOKEN}@mob-lobby.herokuapp.com/"
20
+ end
12
21
 
13
22
  class MobResource < ActiveRestClient::Base
14
- if ENV['dev']
15
- base_url "http://#{USERNAME}:#{TOKEN}@localhost:3000/"
16
- else
17
- base_url "https://#{USERNAME}:#{TOKEN}@mob-lobby.herokuapp.com/"
18
- end
19
-
20
23
  get :all, "/mobs"
21
24
  get :find, "/mobs/:id"
22
25
  put :join, "/mobs/:id/join"
@@ -38,9 +41,25 @@ class MobResource < ActiveRestClient::Base
38
41
  end
39
42
  end
40
43
 
44
+ class InvitationResource < ActiveRestClient::Base
45
+ put :accept, "/invitations/:id/accept"
46
+
47
+ def credentials
48
+ [username, token].join ':'
49
+ end
50
+ end
51
+
52
+ class PublicKeyResource < ActiveRestClient::Base
53
+ post :upload, "/public_keys"
54
+ end
55
+
41
56
  class RubyStepsClient
42
57
  def self.mobs
43
- MobResource.all[:mobs]
58
+ begin
59
+ MobResource.all[:mobs]
60
+ rescue ActiveRestClient::HTTPUnauthorisedClientException => e
61
+ $stderr.puts "Unauthorized. #{e.result}"
62
+ end
44
63
  end
45
64
 
46
65
  def self.join_mob(slug)
@@ -54,12 +73,46 @@ class RubyStepsClient
54
73
  $stderr.puts "Unauthorized. #{e.result}"
55
74
  end
56
75
  end
76
+
77
+ def self.register(token)
78
+ begin
79
+ invitation = InvitationResource.accept token
80
+ File.open(RUBYSTEPS_FILENAME, 'w') {|f| f.write invitation.credentials }
81
+ puts "You are registered as #{invitation.username}. You may now run rubysteps commands"
82
+ puts "Please upload your SSH key with `rubysteps upload_public_key PATH_TO_KEY`"
83
+ rescue ActiveRestClient::HTTPNotFoundClientException
84
+ $stderr.puts "Unable to find an invitation with token #{token}"
85
+ rescue ActiveRestClient::HTTPUnauthorisedClientException => e
86
+ $stderr.puts "Unauthorized. #{e.result}"
87
+ end
88
+ end
89
+
90
+ def self.upload_public_key(path)
91
+ full_path = File.expand_path path
92
+
93
+ if File.file?(full_path)
94
+ puts "Uploading public key: #{full_path}"
95
+
96
+ key_text = File.read(full_path).strip
97
+
98
+ begin
99
+ key = PublicKeyResource.new key: key_text
100
+ key.upload
101
+ puts "Public key successfully uploaded"
102
+ rescue ActiveRestClient::HTTPUnauthorisedClientException => e
103
+ $stderr.puts "Unauthorized. #{e.result}"
104
+ end
105
+ else
106
+ $stderr.puts "Unable to find public key: #{full_path}"
107
+ end
108
+ end
57
109
  end
58
110
 
59
111
  class RubySteps < Thor
60
112
  desc "list", "List mobs waiting to start"
61
113
  def list
62
114
  mobs = RubyStepsClient.mobs
115
+ return if mobs.nil?
63
116
  if mobs.any?
64
117
  mobs.each do |m|
65
118
  puts m
@@ -92,6 +145,16 @@ class RubySteps < Thor
92
145
  def chicken
93
146
  puts "cluck cluck!"
94
147
  end
148
+
149
+ desc "register TOKEN", "Register an invitation using TOKEN and download credentials"
150
+ def register(token)
151
+ RubyStepsClient.register token
152
+ end
153
+
154
+ desc "upload_public_key PATH", "Upload the public key located at PATH (e.g. ~/.ssh/id_rsa.pub)"
155
+ def upload_public_key(path)
156
+ RubyStepsClient.upload_public_key path
157
+ end
95
158
  end
96
159
 
97
160
  RubySteps.start
@@ -1,3 +1,3 @@
1
1
  module Rubysteps
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysteps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Maddox